Documentation
  • GET STARTED
    • 介紹
    • 快速入门
    • 模型
      • 模型更新
    • Afs-turbo 和 Afs-1
    • Afs-turbo
    • 达尔·E 系统概述
    • TTS系统
    • 耳语
    • 嵌入
    • 适度
    • AFS基础
    • 我们如何使用您的数据
    • 终结点与兼容性
  • 教程
  • 更改日志
  • 能力
    • 文本生成
    • 聊天完成
    • JSON 模式
    • 可重复的输出
    • 管理令牌
    • 参数详细信息
    • 完成API(旧版)
    • 常见问题
  • 函数调用
  • 嵌入
    • 概述
    • 模型
    • 使用案例
    • 常见问题
  • 微调
    • 何时使用微调
    • 常见用例
    • 准备数据集
    • 创建微调模型
    • 使用微调模型
    • 微调示例
  • 图像生成
    • 介绍
    • 用法
    • 特定语言提示
  • 视觉
  • 文字转语音
  • 语音转文本
    • 概述
    • 快速入门
    • 支持的语言
    • 时间戳
    • 更长的输入
    • 促使
    • 提高可靠性
  • 适度
    • 概述
    • 快速入门
  • 助理
  • 概述
  • Google助理的工作原理
    • Objects
    • Creating Assistants
    • Managing Threads and Messages
    • Runs and Run Steps
    • 局限性
  • 工具
    • Code Interpreter
    • Knowledge Retrieval
    • Function calling
    • Supported files
  • 指南
  • 提示工程
    • Six strategies for getting better results
    • Write clear instructions
    • Provide reference text
    • Split complex tasks into simpler subtasks
    • Give models time to "think"
    • Use external tools
    • Test changes systematically
    • Other resources
  • 生产最佳实践
    • Setting up your organization
    • Scaling your solution
    • Managing rate limits
    • Improving latencies
    • Managing costs
    • MLOps strategy
    • Security and compliance
  • 安全最佳实践
  • 速率限制
    • 概述
    • Usage tiers
    • Error Mitigation
  • 错误代码
    • API errors
    • Python library error types
  • 图书馆
    • Python library
    • 图书馆
    • Azure OpenAI 库
    • 社区图书馆
  • 弃用
  • 政策
  • 行动
    • 介绍
    • 开始
    • 认证
    • 生产
    • 数据检索
    • 政策
  • 发行说明
  • Page 2
由 GitBook 提供支持
在本页
  1. 工具

Function calling

Afarensis 助手API:实现函数调用

Afarensis 助手API支持函数调用,类似于聊天完成API,这一功能允许您向助手描述函数,并智能地返回需要调用的函数及其参数。当助手在运行过程中调用函数时,执行将暂停,直到您提供函数调用的结果,从而继续运行的执行。

定义函数 在创建助手时,首先定义您想要助手调用的函数:

assistant = client.beta.assistants.create( instructions="You are a weather bot. Use the provided functions to answer questions.", model="gpt-4-turbo-preview", tools=[{ "type": "function", "function": { "name": "getCurrentWeather", "description": "获取指定地点的天气", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "城市和州,例如 San Francisco, CA"}, "unit": {"type": "string", "enum": ["c", "f"]} }, "required": ["location"] } } }, { "type": "function", "function": { "name": "getNickname", "description": "获取城市的昵称", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "城市和州,例如 San Francisco, CA"}, }, "required": ["location"] } } }] ) 触发和读取函数调用 当用户消息触发函数调用时,运行将进入“pending”状态,并在处理后进入“requires_action”状态。您可以通过检索运行状态来验证此状态,并查看需要调用的函数及其参数。

提交函数输出 完成函数调用后,您需要提交函数的输出,以便继续运行的执行:

run = client.beta.threads.runs.submit_tool_outputs( thread_id=thread.id, run_id=run.id, tool_outputs=[ { "tool_call_id": call_ids[0], "output": "22C", }, { "tool_call_id": call_ids[1], "output": "LA", }, ] ) 在提交了函数输出后,运行将进入“queued”状态,并继续执行直至完成。

上一页Knowledge Retrieval下一页Supported files

最后更新于1年前