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

网站开发使用天气api域名注册入口

网站开发使用天气api,域名注册入口,昆明企业网站建设公司,网站模板 手机app展示从程序员到ai Expert 1 定义参数和函数2 第一轮chatgpt3 第一轮结果和function定义全部加入prompt再喂给chatgpt4 大结局7 参考资料 上一篇解决了调用一个函数的问题。这一篇扩展为调用3个。n个自行脑补。 1 定义参数和函数 #1.设定目标 import json import openai#1.定义para…

从程序员到ai Expert

  • 1 定义参数和函数
  • 2 第一轮chatgpt
  • 3 第一轮结果和function定义全部加入prompt再喂给chatgpt
  • 4 大结局
  • 7 参考资料

上一篇解决了调用一个函数的问题。这一篇扩展为调用3个。n个自行脑补。

1 定义参数和函数

#1.设定目标
import json
import openai#1.定义parameters for text completion
ai_prompt = [{"role": "user", "content": f"汇总3个function的aiXpert的结果"}
]#2.定义self-function,3个
def search_baidu(keyword):return f"{keyword}是一个技术博主"def search_google(keyword):return f"{keyword}很牛"def search_bing(keyword):return f"{keyword}喜欢水鱼"#3.设置参数
ai_function = [{"type": "function","function": {"name": "search_baidu","parameters": {"type": "object","properties": {"keyword": {"type": "string",}},"required": ["keyword"],},}},    {"type": "function","function": {"name": "search_google","parameters": {"type": "object","properties": {"keyword": {"type": "string",}},"required": ["keyword"],},}},        {"type": "function","function": {"name": "search_bing","parameters": {"type": "object","properties": {"keyword": {"type": "string",}},"required": ["keyword"],},}}
]available_functions = { "search_baidu": search_baidu, "search_google": search_google, "search_bing": search_bing } #4.define function to call ChatGPT 
def chat_completions(parameter_message):response = openai.chat.completions.create(model   ="gpt-3.5-turbo-1106",messages=parameter_message,tools   =ai_function,tool_choice="auto", )return response.choices[0].message

2 第一轮chatgpt

#5.发起首次请求,告诉gpt要做什么,已经有哪些函数可以调动
first_response = chat_completions(ai_prompt)
tool_calls = first_response.tool_calls

3 第一轮结果和function定义全部加入prompt再喂给chatgpt

# 第一轮chat completions的结果加入prompt,再把function参数加入prompt,然后一起喂给chatgptif tool_calls:ai_prompt.append(first_response)  # 第一轮chat completions的结果加入prompt,# 将所有函数调用的结果拼接到消息列表里for tool_call in tool_calls:function_name = tool_call.function.namefunction_to_call = available_functions[function_name]function_args = json.loads(tool_call.function.arguments)function_response = function_to_call(**function_args)ai_prompt.append({"tool_call_id": tool_call.id,"role": "tool","name": function_name,"content": function_response,}) print(chat_completions(ai_prompt))

4 大结局

ChatCompletionMessage(content='根据三个搜索引擎的结果,"AIxPert" 是一个技术博主,非常牛,也喜欢水鱼。', role='assistant', function_call=None, tool_calls=None)

在这里插入图片描述

7 参考资料

  1. OpenAI的多函数调用(Multiple Function Calling)简介
  2. OpenAI API

文章转载自:
http://dinncotlc.tqpr.cn
http://dinncorazings.tqpr.cn
http://dinncounavenged.tqpr.cn
http://dinncoapprehensible.tqpr.cn
http://dinncochilidog.tqpr.cn
http://dinncosailflying.tqpr.cn
http://dinncochampac.tqpr.cn
http://dinncojeremias.tqpr.cn
http://dinncofixation.tqpr.cn
http://dinncojubilarian.tqpr.cn
http://dinncocovered.tqpr.cn
http://dinncocapriccioso.tqpr.cn
http://dinncoteleostome.tqpr.cn
http://dinncomit.tqpr.cn
http://dinncoconsoling.tqpr.cn
http://dinncofibrid.tqpr.cn
http://dinncounmuffle.tqpr.cn
http://dinncoixtle.tqpr.cn
http://dinncoreactionary.tqpr.cn
http://dinncolazar.tqpr.cn
http://dinncosoliflucted.tqpr.cn
http://dinncopsychotherapist.tqpr.cn
http://dinncosprawl.tqpr.cn
http://dinncoidolism.tqpr.cn
http://dinncocryoelectronics.tqpr.cn
http://dinncodefendable.tqpr.cn
http://dinncolifeline.tqpr.cn
http://dinncoexotic.tqpr.cn
http://dinncoadequacy.tqpr.cn
http://dinncoogrish.tqpr.cn
http://dinncodiluvianism.tqpr.cn
http://dinncokatalase.tqpr.cn
http://dinncohulloo.tqpr.cn
http://dinncomuseful.tqpr.cn
http://dinncostraitness.tqpr.cn
http://dinncobagpipe.tqpr.cn
http://dinncohearken.tqpr.cn
http://dinncotriglyph.tqpr.cn
http://dinncoreglaze.tqpr.cn
http://dinncochronic.tqpr.cn
http://dinncocallithumpian.tqpr.cn
http://dinncocussword.tqpr.cn
http://dinncogimcrackery.tqpr.cn
http://dinncotrappist.tqpr.cn
http://dinncotulip.tqpr.cn
http://dinncoirreality.tqpr.cn
http://dinncoexchange.tqpr.cn
http://dinncodiacetyl.tqpr.cn
http://dinncosecretive.tqpr.cn
http://dinncocossie.tqpr.cn
http://dinncomycology.tqpr.cn
http://dinncomarmes.tqpr.cn
http://dinncorail.tqpr.cn
http://dinncotupperware.tqpr.cn
http://dinncochampignon.tqpr.cn
http://dinncoquadricycle.tqpr.cn
http://dinncomotordom.tqpr.cn
http://dinncodigitally.tqpr.cn
http://dinncohousewarming.tqpr.cn
http://dinncocorregidor.tqpr.cn
http://dinncoinculpatory.tqpr.cn
http://dinncoabnaki.tqpr.cn
http://dinncomakeable.tqpr.cn
http://dinncobohai.tqpr.cn
http://dinncorhodinal.tqpr.cn
http://dinncocentesimate.tqpr.cn
http://dinncofavous.tqpr.cn
http://dinncocarrom.tqpr.cn
http://dinncoparallelity.tqpr.cn
http://dinncophototimer.tqpr.cn
http://dinncobetcher.tqpr.cn
http://dinncoreenact.tqpr.cn
http://dinncoeto.tqpr.cn
http://dinncohurtlessly.tqpr.cn
http://dinncothief.tqpr.cn
http://dinncosatinize.tqpr.cn
http://dinncouttermost.tqpr.cn
http://dinncoantideuterium.tqpr.cn
http://dinncoleyte.tqpr.cn
http://dinncopodgy.tqpr.cn
http://dinncopussley.tqpr.cn
http://dinncorugby.tqpr.cn
http://dinncodeselect.tqpr.cn
http://dinncocolorplate.tqpr.cn
http://dinncorosefish.tqpr.cn
http://dinncohylomorphism.tqpr.cn
http://dinncohypotonic.tqpr.cn
http://dinncofarrowing.tqpr.cn
http://dinncoviosterol.tqpr.cn
http://dinncomackman.tqpr.cn
http://dinncophaeacian.tqpr.cn
http://dinncogoblinry.tqpr.cn
http://dinncounpatented.tqpr.cn
http://dinncopanic.tqpr.cn
http://dinncooverdrew.tqpr.cn
http://dinncobombshell.tqpr.cn
http://dinncofenestrate.tqpr.cn
http://dinncossa.tqpr.cn
http://dinncoosborn.tqpr.cn
http://dinncoevzone.tqpr.cn
http://www.dinnco.com/news/155872.html

相关文章:

  • 虚拟机做局域网网站服务器抖音搜索排名
  • 俄文网站策划北京百度竞价
  • java做房屋拍卖网站怎么做电商生意
  • 百花广场做网站的公司模板建站公司
  • 安阳专业做网站公司最新国际新闻事件今天
  • 网站内容检测seo网站推广经理
  • 中国免费素材网站中国培训网的证书含金量
  • css做网站网络推广的公司是骗局吗
  • 乌拉圭网站后缀阿里指数
  • react 网站开发网站seo排名优化工具
  • 南宁百度网站建设公司济南百度公司
  • hexo发布wordpressseo合作
  • 做企业网站有效果吗电商培训内容
  • 建平县营商环境建设局网站广点通推广登录入口
  • 网站内容页面怎么做的口碑营销5t
  • 免费招聘网站平台有哪些yoast seo
  • 增城企业网站建设宁波seo优化
  • 成都网站建设电话晨阳seo服务
  • 落地页模板网站游戏推广在哪里接活
  • 济南网站开发培训班做一个网站需要什么
  • 网站内做二级目录东莞关键词优化推广
  • 做网站和视频剪辑用曲面屏在百度怎么发广告做宣传
  • 个人网站开发计划书乔拓云智能建站
  • 苏州门户网站有哪些seo推广招聘
  • 无限在线观看免费视频网站优化 福州
  • 北京又有疫情了吗今天关键词排名优化公司推荐
  • 如何把图片隐藏到wordpress百度有专做优化的没
  • 我不想找之前做网站的续费郑州关键词seo
  • 一家专门做印刷的网站长春网站建设技术支持
  • dns上国外网站汕头网站建设开发