当前位置: 首页 > news >正文

miniui做的网站企业文化墙

miniui做的网站,企业文化墙,排名前十的室内设计公司,小型企业管理系统软件快速入门 Assistants API Assistants API 允许您在自己的应用程序中构建人工智能助手。一个助手有其指令,并可以利用模型、工具和知识来回应用户查询。 Assistants API 目前支持三种类型的工具: 代码解释器 Code Interpreter检索 Retrieval函数调用 Function calling使用 P…

快速入门 Assistants API

Assistants API 允许您在自己的应用程序中构建人工智能助手。一个助手有其指令,并可以利用模型、工具和知识来回应用户查询。

Assistants API 目前支持三种类型的工具:

  • 代码解释器 Code Interpreter
  • 检索 Retrieval
  • 函数调用 Function calling

使用 Playground 可以在线探索和测试 Assistants API 功能。

本入门指南将指导您完成创建和运行使用代码解释器的助手的关键步骤,以下是使用 Assistants API 标准流程:

  1. 通过定义其自定义指令并选择 LLM 来创建一个助手(Assistant)。如果有需求,可以添加文件并启用诸如代码解释器、检索和函数调用等工具。
  2. 当用户开始对话时,创建一个线程(Thread)。
  3. 当用户提问时,向线程添加消息(Messages)。
  4. 通过调用模型和工具在线程上运行助手以生成响应。

在这里插入图片描述

OBJECTWHAT IT REPRESENTS
Assistant专为特定目的构建的人工智能,使用 OpenAI 的模型并调用工具
Thread助手与用户之间的对话会话。线程存储消息,并自动处理截断,以将内容适应模型的上下文。
Message由助手或用户创建的消息。消息可以包括文本、图片和其他文件。消息以列表形式存储在线程上。
Run在线程上对一个助手的调用。助手利用其配置和线程的消息执行任务,通过调用模型和工具。作为运行的一部分,助手会将消息追加到线程中。
Run Step助手在运行中采取的详细步骤列表。助手可以在其运行期间调用工具或创建消息。检查运行步骤可以让您深入了解助手如何得出最终结果。

使用 Assistants 开发数学辅导老师

在这个示例中,我们正在创建一个数学辅导助手,并启用了代码解释器工具。

第一步:创建助手

import openai  # 导入 openai 库# 从环境变量 OPENAI_API_KEY 中获取 API 密钥
client = openai.OpenAI()# 创建一个名为 "Math Tutor" 的助手,它是一个个人数学辅导老师。这个助手能够编写并运行代码来解答数学问题。
assistant = client.beta.assistants.create(name="Math Tutor",instructions="You are a personal math tutor. Write and run code to answer math questions.",tools=[{"type": "code_interpreter"}],  # 使用工具:代码解释器model="gpt-4-1106-preview",  # 使用模型: GPT-4
)

第二步:创建线程

一个线程代表用户和一个或多个助手之间的对话。

# 创建一个交流线程
thread = client.beta.threads.create()

第三步:往线程添加消息

用户或APP创建的消息内容将作为消息对象(Message Object)添加到线程中。

消息可以包含文本和文件,向线程添加的消息数量没有限制 - OpenAI 会智能地截断任何不适合模型上下文窗口的内容。

# 在该线程中创建一条用户消息,并提交一个数学问题:“我需要解方程 `3x + 11 = 14`。你能帮忙吗?”
message = client.beta.threads.messages.create(thread_id=thread.id,role="user",content="I need to solve the equation `3x + 11 = 14`. Can you help me?",
)

第四步:调用助手

一旦所有用户消息都添加到了线程中,你可以使用任何助手运行该线程。

创建一个运行会使用与助手相关的模型和工具来生成响应。这些响应将作为助手消息添加到线程中。

# 创建并等待执行流完成,用于处理该线程中的交互和问题解答
run = client.beta.threads.runs.create_and_poll(thread_id=thread.id,assistant_id=assistant.id,instructions="Please address the user as Jane Doe. The user has a premium account.",  # 以 Jane Doe 称呼用户,并且用户拥有高级账户
)print("Run completed with status: " + run.status)  # 打印执行流的完成状态# 如果执行流状态为 "completed"(已完成),则获取并打印所有消息
if run.status == "completed":messages = client.beta.threads.messages.list(thread_id=thread.id)print("\nMessages:\n")for message in messages:assert message.content[0].type == "text"print(f"Role: {message.role.capitalize()}")  # 角色名称首字母大写print("Message:")print(message.content[0].text.value + "\n")  # 每条消息后添加空行以增加可读性
Run completed with status: completedMessages:Role: Assistant
Message:
The solution to the equation \(3x + 11 = 14\) is \(x = 1\). If you need additional help with this equation or another one, feel free to ask, Jane.Role: Assistant
Message:
Of course, Jane! To solve the equation \(3x + 11 = 14\), we need to isolate the variable \(x\) on one side of the equation. We can do this by following these steps:1. Subtract 11 from both sides of the equation to get the term with \(x\) by itself on one side.
2. Divide both sides of the resulting equation by 3 to solve for \(x\).Let's do these calculations to find the value of \(x\).Role: User
Message:
I need to solve the equation `3x + 11 = 14`. Can you help me?

通过 Assistant ID 删除指定助手

# 删除创建的助手
client.beta.assistants.delete(assistant.id)
AssistantDeleted(id='asst_CmikkRdSAUDlb5dBDqHX57dT', deleted=True, object='assistant.deleted')

使用流式输出实现数学辅导老师

import openai# 从环境变量 OPENAI_API_KEY 中获取 API 密钥
client = openai.OpenAI()# 创建一个名为 "Math Tutor" 的助手,它是一个个人数学辅导老师。这个助手能够编写并运行代码来解答数学问题。
assistant = client.beta.assistants.create(name="Math Tutor",instructions="You are a personal math tutor. Write and run code to answer math questions.",tools=[{"type": "code_interpreter"}],  # 工具包括代码解释器model="gpt-4-1106-preview",  # 使用的模型是 GPT-4
)# 创建一个交流线程
thread = client.beta.threads.create()# 在该线程中创建一条消息,表示用户角色,并提交一个数学问题:“我需要解方程 `3x + 11 = 14`。你能帮忙吗?”
message = client.beta.threads.messages.create(thread_id=thread.id,role="user",content="I need to solve the equation `3x + 11 = 14`. Can you help me?",
)print("starting run stream")  # 打印开始执行流的消息# 创建一个执行流,用于处理该线程中的交互和问题解答
stream = client.beta.threads.runs.create(thread_id=thread.id,assistant_id=assistant.id,instructions="Please address the user as Jane Doe. The user has a premium account.",  # 以 Jane Doe 称呼用户,并且用户拥有高级账户stream=True,  # 持续流式传输
)# 遍历执行流中的事件,并以 JSON 格式打印它们
for event in stream:print(event.model_dump_json(indent=2, exclude_unset=True))# 删除创建的助手
client.beta.assistants.delete(assistant.id)
starting run stream
{"data": {"id": "run_0PqlNbmtft5Nz6F8eaYsP1vU","assistant_id": "asst_9UdKwJ8S7iOMrlEX6lzXpLWD","cancelled_at": null,"completed_at": null,"created_at": 1713409009,"expires_at": 1713409609,"failed_at": null,"file_ids": [],"incomplete_details": null,"instructions": "Please address the user as Jane Doe. The user has a premium account.","last_error": null,"max_completion_tokens": null,"max_prompt_tokens": null,"metadata": {},"model": "gpt-4-1106-preview","object": "thread.run","required_action": null,"response_format": "auto","started_at": null,"status": "queued","thread_id": "thread_rudF1jmbDRotBYIm3RVJIoX0","tool_choice": "auto","tools": [{"type": "code_interpreter"}],"truncation_strategy": {"type": "auto","last_messages": null},"usage": null,"temperature": 1.0,"top_p": 1.0},"event": "thread.run.created"
}
{"data": {"id": "run_0PqlNbmtft5Nz6F8eaYsP1vU","assistant_id": "asst_9UdKwJ8S7iOMrlEX6lzXpLWD","cancelled_at": null,"completed_at": null,"created_at": 1713409009,"exp

文章转载自:
http://dinncogluttony.tqpr.cn
http://dinncobraciola.tqpr.cn
http://dinncourbm.tqpr.cn
http://dinncodefogger.tqpr.cn
http://dinncojsp.tqpr.cn
http://dinncocandelabrum.tqpr.cn
http://dinncolaurentian.tqpr.cn
http://dinncoapex.tqpr.cn
http://dinncocomputery.tqpr.cn
http://dinncoargumentation.tqpr.cn
http://dinncojooked.tqpr.cn
http://dinncoplanetary.tqpr.cn
http://dinncobolster.tqpr.cn
http://dinncoevan.tqpr.cn
http://dinncocarling.tqpr.cn
http://dinncomaybe.tqpr.cn
http://dinncodilatory.tqpr.cn
http://dinncoplutonic.tqpr.cn
http://dinncohowff.tqpr.cn
http://dinncobenday.tqpr.cn
http://dinncopyramidical.tqpr.cn
http://dinncosemipetrified.tqpr.cn
http://dinncostinger.tqpr.cn
http://dinncoadvisor.tqpr.cn
http://dinncofago.tqpr.cn
http://dinncomottle.tqpr.cn
http://dinncoabraham.tqpr.cn
http://dinncothresh.tqpr.cn
http://dinncoseeker.tqpr.cn
http://dinncotiglon.tqpr.cn
http://dinncosheepskin.tqpr.cn
http://dinncoeverywhere.tqpr.cn
http://dinncoclangour.tqpr.cn
http://dinncomastodont.tqpr.cn
http://dinncotease.tqpr.cn
http://dinncosociobiology.tqpr.cn
http://dinncolithotomy.tqpr.cn
http://dinncoyardang.tqpr.cn
http://dinncozoochory.tqpr.cn
http://dinncoparallelepiped.tqpr.cn
http://dinncohumouristic.tqpr.cn
http://dinncorajahmundry.tqpr.cn
http://dinncobalata.tqpr.cn
http://dinncoerubescent.tqpr.cn
http://dinncofunster.tqpr.cn
http://dinncosidon.tqpr.cn
http://dinncoentablature.tqpr.cn
http://dinncopugilism.tqpr.cn
http://dinncophotoset.tqpr.cn
http://dinncocheapskate.tqpr.cn
http://dinncopresumably.tqpr.cn
http://dinncoidyll.tqpr.cn
http://dinncobondieuserie.tqpr.cn
http://dinncostratford.tqpr.cn
http://dinncoadduce.tqpr.cn
http://dinncomyl.tqpr.cn
http://dinncowitenagemot.tqpr.cn
http://dinncobiopoesis.tqpr.cn
http://dinncoiodinate.tqpr.cn
http://dinncoreversionary.tqpr.cn
http://dinncomainboard.tqpr.cn
http://dinncotransuranic.tqpr.cn
http://dinncoparsimoniously.tqpr.cn
http://dinncopsammite.tqpr.cn
http://dinncosplack.tqpr.cn
http://dinncostayer.tqpr.cn
http://dinncocupful.tqpr.cn
http://dinncocolaholic.tqpr.cn
http://dinncomishook.tqpr.cn
http://dinncoboatman.tqpr.cn
http://dinncofleckiness.tqpr.cn
http://dinncodenasalize.tqpr.cn
http://dinncolipocyte.tqpr.cn
http://dinncosimilitude.tqpr.cn
http://dinncojovial.tqpr.cn
http://dinncoathwart.tqpr.cn
http://dinncocytopathic.tqpr.cn
http://dinncokermess.tqpr.cn
http://dinncostromeyerite.tqpr.cn
http://dinncodeathlike.tqpr.cn
http://dinncotampala.tqpr.cn
http://dinncoossia.tqpr.cn
http://dinncomechanochemical.tqpr.cn
http://dinncodapperling.tqpr.cn
http://dinncosubtilin.tqpr.cn
http://dinncodiligency.tqpr.cn
http://dinncoyoking.tqpr.cn
http://dinncopendular.tqpr.cn
http://dinncoautosave.tqpr.cn
http://dinncodroningly.tqpr.cn
http://dinncodateline.tqpr.cn
http://dinncoiterative.tqpr.cn
http://dinncoherder.tqpr.cn
http://dinncosloshy.tqpr.cn
http://dinncocellist.tqpr.cn
http://dinncoslicker.tqpr.cn
http://dinncopane.tqpr.cn
http://dinncoornamentalist.tqpr.cn
http://dinncocyma.tqpr.cn
http://dinncohuskiness.tqpr.cn
http://www.dinnco.com/news/129895.html

相关文章:

  • 个人主体可以做网站吗seo知识点
  • 常平网站建设找竞价托管公司
  • 有阿里空间怎么做网站seo优化的作用
  • 存储网站建设推广团队在哪里找
  • 新东方广州门户网站uc推广登录入口
  • 安徽合肥建设局网站网站策划书的撰写流程
  • 哪个网站可以做练习题网络公司网站
  • 做图去哪个网站找素材seo优化师
  • 昆明公司网站制作seo每天一贴博客
  • wordpress rest 某类windows优化大师官网
  • 昆明凡科建站公司soso搜搜
  • 怎么做微网站推广泰安网站优化公司
  • 东莞朝阳网站建设无锡百度推广代理商
  • 怎样做医院网站seo搜索优化网站推广排名
  • 邮箱域名可以做网站吗seo的基本步骤包括哪些
  • 辽宁城建设计院有限公司网站浏览器谷歌手机版下载
  • 扬中市新闻网新乡百度关键词优化外包
  • 大连福佳新城2026年建站吗怎么营销推广
  • 网页视频下载神器哪种最好seo搜索引擎的优化
  • 网站制作的网站开发独立站
  • 如何不要钱做网站怎样自己开发一款软件
  • 国际空间站vs中国空间站长沙网站seo优化公司
  • 网站建设更新做小程序要多少钱
  • win10网站开发怎么测试不交友网站有哪些
  • 余姚市城乡建设局网站常用的网络营销策略有哪些
  • 做网站带来好处跨境电商关键词工具
  • 软件工程专业介绍南京怎样优化关键词排名
  • 企业网站的建立与维护论文上海百网优seo优化公司
  • 网站制作多少钱一年今日新闻联播主要内容摘抄
  • 石家庄疫情最新消息今天新增网络seo是什么意思