Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 297ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
o

openai

Recently created Least recently created Recently updated Least recently updated

timmy / 使用 litellm 呼叫 LLM API 生成回應

Last active 5 hours ago ai api chatbot litellm llm openai python

litellm 提供一個統一的介面來呼叫不同的 LLM(如 OpenAI、Anthropic、Azure OpenAI 等),簡化 API 介接,適用於聊天機器人、AI 助理或內容生成應用。

0 0 0 1
1 import os
2 from litellm import completion
3
4 # 設定 API 金鑰(建議使用環境變數)
5 os.environ["OPENAI_API_KEY"] = "your-api-key"
6
7 # 發送請求至 LLM
8 response = completion(
9 model="gpt-3.5-turbo",
10 messages=[{"role": "user", "content": "Hello, how are you?"}]