Not Diamond Python SDK
项目描述
开始使用Not Diamond
Not Diamond是一个AI模型路由器,它会自动确定哪个LLM最适合回答任何查询,通过将多个LLM组合成一个学习何时调用每个LLM的元模型
,从而提高LLM输出质量。
主要功能
- 最大化输出质量:Not Diamond始终调用最佳模型,在主要评估基准测试中优于所有基础模型。
- 降低成本和延迟:Not Diamond 允许您定义智能的成本和延迟权衡,以高效利用更小、更便宜的模型,而不会降低质量。
- 训练自己的路由器:Not Diamond 允许您训练适合您数据和用例的定制路由器。
- Python、TypeScript 和 REST API 支持:Not Diamond 可在多种堆栈上运行。
安装
Python:需要 Python 3.10+。建议您在安装软件包之前创建并激活一个 虚拟环境。在此示例中,我们将安装可选的附加 create
依赖项,您可以在 这里 了解更多信息。
pip install notdiamond[create]
设置
创建一个包含您的 Not Diamond API密钥 以及您想要在之间路由的模型的 API密钥 的 .env
文件
NOTDIAMOND_API_KEY = "YOUR_NOTDIAMOND_API_KEY"
OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"
ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY"
发送第一个 Not Diamond API 请求
在您的 .env
文件所在目录中创建一个新文件,并将以下代码复制并运行(您可以在代码块的左上角在 Python 和 TypeScript 之间切换)
from notdiamond import NotDiamond
# Define the Not Diamond routing client
client = NotDiamond()
# The best LLM is determined by Not Diamond based on the messages and specified models
result, session_id, provider = client.chat.completions.create(
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Concisely explain merge sort."} # Adjust as desired
],
model=['openai/gpt-3.5-turbo', 'openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620']
)
print("ND session ID: ", session_id) # A unique ID of Not Diamond's recommendation
print("LLM called: ", provider.model) # The LLM routed to
print("LLM output: ", result.content) # The LLM response
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源分布
notdiamond-0.3.19.tar.gz (49.5 kB 查看哈希)
构建分布
notdiamond-0.3.19-py3-none-any.whl (56.5 kB 查看哈希)
关闭
notdiamond-0.3.19.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | db1a432a9b6cd9352a2cfd27e36b316113442138f567ebe58abe845e19e2096b |
|
MD5 | c4e17b07f8fde00864f2b6b9f0de83a1 |
|
BLAKE2b-256 | 257bd0bd5b7b8b3654dc11cba815952bef4eef69977d206c46668bc7b402f0b3 |
关闭
notdiamond-0.3.19-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fa445597a9dc83c4139c09574fc0513a866049c26dd8ed071b10b6fea14a5690 |
|
MD5 | e5f34eb4eff0888d43327033a66d5fc2 |
|
BLAKE2b-256 | c252f7c3cef3584c3f316b9a4f1ae8a2f36a1e8e73e7a2290142f02e7604831b |