跳转到主要内容

Not Diamond Python SDK

项目描述

开始使用Not Diamond

Not Diamond是一个AI模型路由器,它会自动确定哪个LLM最适合回答任何查询,通过将多个LLM组合成一个学习何时调用每个LLM的元模型,从而提高LLM输出质量。

主要功能

安装

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 查看哈希)

上传时间 Python 3

支持者