Common interface for llm apis
Project description
Genlink
Genlink is a Python package that provides a unified interface for interacting with various Language Model (LLM) APIs. It simplifies the process of integrating and switching between different LLM providers in your applications.
Features
- Unified interface for multiple LLM providers (OpenAI, Anthropic, Google's Gemini supported for now)
- Asynchronous support for efficient handling of multiple queries
- Built-in performance metrics and logging
- Support for function calling / tool use in compatible LLMs
- Configurable via YAML files or dictionaries
- Easy-to-use Agent system for managing LLM interactions
The package is still in development and more features will be added as soon as possible.
Installation
You can install Genlink using pip:
pip install genlink
Quick Start
Here's a basic example of how to use Genlink with OpenAI's GPT model:
from genlink import GPTConnector, StandardAgent
from genlink.typedicts import LLMParameters, PromptParameters
# Initialize the connector
connector = GPTConnector.from_config(
api_key="your-api-key-here",
config_dict={
"id": "gpt-connector",
"type": "openai",
"model": "gpt-3.5-turbo"
}
)
# Connect to the API
connector.connect()
# Create an agent
agent = StandardAgent(
id="my-agent",
name="GPT Agent",
description="A simple GPT agent",
generation_parameters=LLMParameters(
temperature=0.7,
max_tokens=150
),
prompt_parameters=PromptParameters(
system_prompt="You are a helpful assistant."
),
connector_list=[connector]
)
# Use the agent
messages = [
{"role": "user", "content": "What is the capital of France?"}
]
response = agent.workflow(messages)
print(response[0]['content'])
Asynchronous Usage
Genlink supports asynchronous operations for improved performance when handling multiple queries:
import asyncio
from genlink import GPTConnector, StandardAgent
async def main():
connector = GPTConnector.from_config(...)
connector.connect()
agent = StandardAgent(...)
messages1 = [Message(role="user", content="Query 1")]
messages2 = [Message(role="user", content="Query 2")]
results = await asyncio.gather(
agent.async_workflow(messages1),
agent.async_workflow(messages2)
)
for result in results:
print(result[0]['content'])
asyncio.run(main())
Configuration
Genlink supports configuration via YAML files or dictionaries. Here's an example YAML configuration:
id: my-agent
name: GPT Agent
description: A simple GPT agent
generation_parameters:
temperature: 0.7
max_tokens: 150
prompt_parameters:
system_prompt: You are a helpful assistant.
connector_ids:
- gpt-connector
from genlink import StandardAgent
agent = StandardAgent.from_config(
handler_dict={"gpt-connector": gpt_connector},
yaml_path="path/to/config.yaml"
)
Available Connectors
# GPT Connector
gpt_connector = GPTConnector.from_config(
api_key="your-api-key-here",
config_dict={
"id": "gpt-connector",
"type": "openai",
"model": "gpt-3.5-turbo"
}
)
# Anthropic Connector
anthropic_connector = AnthropicConnector.from_config(
api_key="your-anthropic-api-key-here",
config_dict={
"id": "anthropic-connector",
"type": "anthropic",
"model": "claude-2"
}
)
# Gemini Connector
gemini_connector = GeminiConnector.from_config(
api_key="your-gemini-api-key-here",
config_dict={
"id": "gemini-connector",
"type": "gemini",
"model": "gemini-pro"
}
)
Adding Custom Connectors
Genlink is designed to be extensible. You can create custom connectors for new LLM providers by subclassing the Connector class and implementing the required methods.
License
Genlink is released under the MIT License. See the LICENSE file for more details.
Support
If you encounter any issues or have questions, please file an issue on our GitHub issue tracker.
Acknowledgements
Genlink was inspired by the need for a unified interface in the rapidly evolving landscape of large language models. We thank all the contributors and the open-source community for their valuable input and support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genlink-0.1.2a0.tar.gz.
File metadata
- Download URL: genlink-0.1.2a0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dab8a4f840ac3d218d3376a0c4bfbfca5fdade1c7ea17c5f5425dbad616a0956
|
|
| MD5 |
0910556d66d940642a6d9b34e0e083fc
|
|
| BLAKE2b-256 |
eeb6a143e21888e6e9119dfbd9d1e4423ca6e193bef639421d4707324df0cadd
|
File details
Details for the file genlink-0.1.2a0-py3-none-any.whl.
File metadata
- Download URL: genlink-0.1.2a0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e59e8367e982e0c3c26e35dbc955ef95bf077832c00a54e3f5a1cbbb59cde31
|
|
| MD5 |
3b77b651f57d347e801644838d904d64
|
|
| BLAKE2b-256 |
fa6100075d04cabdce06b9c109aa1d5f86f9c77e0df9e129749bfa1068e53dde
|