<div class="alert alert-success">
用
<a href="https://platform.openai.com/docs/guides/text-generation/json-mode">JSON Mode</a>,
也可以不用 function calling 而获得稳定的 JSON 输出。
</div>
## 示例 3:用 Function Calling 获取 JSON 结构
Function calling 生成 JSON 的稳定性比较高,因为默认启动了 [JSON mode](https://platform.openai.com/docs/guides/text-generation/json-mode)。
需求:从一段文字中抽取联系人姓名、地址和电话
def get_completion(messages, model="gpt-3.5-turbo"):
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=0,
tools=[{
"type": "function",
"function": {
"name": "add_contact",
"description": "添加联系人",