response = client.chat.completions.create(model="gpt-3.5-turbo", # 必需參數messages=[], # 必需參數temperature=1.0, # 可選參數max_tokens=None, # 可選參數top_p=1.0, # 可選參數frequency_penalty=0.0, # 可選參數presence_penalty=0.0, # 可選參數stop=None, # 可選參數stream=False, # 可選參數response_format=None, # 可選參數(部分實現支持)seed=None, # 可選參數(部分實現支持)tools=None, # 可選參數(GPT-4o 等支持工具調用)tool_choice=None, # 可選參數(GPT-4o 等支持工具選擇)**kwargs # 其他擴展參數
)
必要參數
可選參數
示例
response = client.chat.completions.create(model="gpt-4o",messages=[{"role": "user", "content": "計算 1+1 的結果"}],tools=[{"type": "function","function": {"name": "calculator","description": "執行數學計算","parameters": {"type": "object","properties": {"expression": {"type": "string"}},"required": ["expression"]}}}],tool_choice={"type": "function", "function": {"name": "calculator"}}
)