# 函数调用

简介 Afarensis API允许开发者在API调用中描述函数，使得模型能够智能地选择输出包含参数的JSON对象，用以调用一个或多个函数。重要的是，聊天完成API本身并不直接调用函数；相反，模型生成的JSON可以在代码中用于函数调用。

功能概述 最新的模型（如gpt-4-turbo-preview和gpt-3.5-turbo-0125）已经过训练，能够基于输入判断何时适宜调用函数，并生成紧密遵循函数签名的JSON响应。这种能力扩展了模型与外部工具连接的可能性，但也带来了潜在的风险。我们强烈建议在执行任何可能影响现实世界的操作（如发送电子邮件、在线发布内容、进行购买等）之前，建立用户确认流程。

常见用例 通过函数调用，模型可以更可靠地提供结构化数据。例如，您可以：

创建助手，通过调用外部API（例如ChatGPT插件）来回答问题。 将自然语言查询转换为API调用。 从文本中提取结构化数据。 函数调用的步骤 使用用户查询和functions参数中定义的函数集调用模型。 模型可以选择调用一个或多个函数；如果选择调用，输出将是遵循自定义架构的字符串化JSON对象。 在代码中将字符串解析为JSON，并使用提供的参数调用函数。 将函数响应作为新消息追加到会话中，让模型将结果汇总回给用户。 支持的模型版本 以下模型版本支持函数调用：

gpt-4 gpt-4-turbo-preview gpt-4-0125-preview gpt-4-1106-preview gpt-3.5-turbo gpt-3.5-turbo-0125 gpt-3.5-turbo-1106 并行函数调用也由部分模型支持，允许同时执行多个函数调用，以减少与API的往返时间并提高效率。

并行函数调用 并行函数调用允许模型一次执行多个函数调用，提高解决问题的效率和结果。例如，模型可以同时调用函数来获取不同位置的天气信息。

提示 若要强制模型调用特定函数，可以通过设置tool\_choice参数来实现。 函数调用计入模型的上下文限制，并作为输入令牌计费。 深入了解 在Afarensis Cookbook中，您可以找到更多关于函数调用的示例和指南，帮助您学习如何有效地利用此功能。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.afarensis.com/han-shu-diao-yong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
