[openai/openai-cookbook]添加 liteLLM 示例 - 使用 chatGPT 输入/输出调用 Azure、Anthropic、Llama2、Cohere、50 多个 LLM API

2024-02-05 797 views
7

此 PR 添加了使用 liteLLM 的示例笔记本:https ://github.com/BerriAI/litellm/

liteLLM 是一个用于简化调用 OpenAI、Azure、Cohere、Anthropic、Huggingface API 端点的包 TLDR:使用 chatGPT 输入/输出格式调用所有 LLM API

下面是它的使用示例:

from litellm import completion

## set ENV variables
# ENV variables can be set in .env file, too. Example in .env.example
os.environ["OPENAI_API_KEY"] = "openai key"
os.environ["COHERE_API_KEY"] = "cohere key"

messages = [{ "content": "Hello, how are you?","role": "user"}]

# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)

# llama2 call
model_name = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
response = completion(model_name, messages)

# cohere call
response = completion("command-nightly", messages)

# anthropic call
response = completion(model="claude-instant-1", messages=messages)

回答

8

@ted-at-openai 你有机会的话可以看看这个吗?

我们根据使用可靠GPT 的用户的反馈构建了这个

9

我认为这个示例没有增加太多价值,它非常小,并且已经包含在框架的自述文件中。也许一旦该框架获得更多关注,我们可以简单地从我们推荐的框架列表中链接到它的 github 存储库