pythonic生物人

Andrew Ng发布Python aisuite包,轻松统一调用GPT、Claude、Llama等顶级LLM!

Andrew Ng官宣正式发布了一款用于操作大型语言模型的Python包— aisuite 。
aisuite通过统一接口,使开发者能够以一致的方式调用不同的LLM,无论底层模型的原始API形式如何,均可轻松实现调用。

通过一个类似于OpenAI接口的设计,aisuite不仅方便用户与主流LLM进行交互,还能轻松对比不同模型的输出效果。

aisuite 目前支持 以下平台的LLM大语言模型:
  • OpenAI
  • Anthropic
  • Azure
  • Google
  • AWS
  • Groq
  • Mistral
  • HuggingFace
  • Ollama

aisuite使用

# 安装 aisuite
pip install aisuite

# 设置API密钥
export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"

# 使用 Python client
import aisuite as ai
client = ai.Client()

models = ["openai:gpt-4o", "anthropic:claude-3-5-sonnet-20240620"]

messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."},
]

for model in models:
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0.75
    )
    print(response.choices[0].message.content)

参考:https://github.com/andrewyng/aisuite



推荐阅读:
👉《Python可视化教程》,优惠中!