
API開發中的日志記錄價值
import openai
openai.api_key = "your-api-key"
openai.api_base = "https://<your-resource-name>.cognitiveservices.azure.com"
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
response = openai.ChatCompletion.create(
engine="gpt-35-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
)
print(response)
import requests
url = "http://localhost:5000/v1/chat/completions"
headers = {
"Content-Type": "application/json"
}
data = {
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
在填寫 api_base_url
時,用戶需要注意以下幾點:
api_base_url
正確無誤:填寫錯誤的 api_base_url
可能會導致無法連接到 GPT 模型的服務,進而影響模型的調用效果。api_base_url
:不同的平臺有不同的 api_base_url
,用戶需要根據自己的使用場景選擇合適的 api_base_url
。api_base_url
是調用 GPT 模型時非常重要的一個參數,用戶需要根據自己的使用場景選擇合適的 api_base_url
。在使用 OpenAI 平臺時,api_base_url
通常為 https://api.openai.com/v1
;在使用 Azure 平臺時,api_base_url
通常為 https://<your-resource-name>.cognitiveservices.azure.com
;在本地部署時,api_base_url
通常為 http://localhost:5000
或其他自定義端口號。通過本文的介紹,希望用戶能夠更好地理解 api_base_url
的填寫方法,并在實際應用中正確使用 GPT 模型。