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

政府网站开发的建议最近一个月的热点事件

政府网站开发的建议,最近一个月的热点事件,广西公司做网站,怎么做动态网站phpUpdates on Function Calling were a major highlight at OpenAI DevDay. In another world,原来的function call都不再正常工作了,必须全部重写。 function和function call全部由tool和tool_choice取代。2023年11月之前关于function call的代码都准备翘翘。 干嘛…

Updates on Function Calling were a major highlight at OpenAI DevDay.

In another world,原来的function call都不再正常工作了,必须全部重写。

function和function call全部由tool和tool_choice取代。2023年11月之前关于function call的代码都准备翘翘。

干嘛要整个tool出来取代function呢?原因有很多,不再赘述。作为程序员,我们真正关心的是:怎么改?

简单来说,就是整合chatgpt的能力和你个人的能力通过这个tools。怎么做呢?

第一步,定义你的function,最高指示是啥?

import json
from openai import OpenAI
client = OpenAI()# Example dummy function hard coded to return the same weather
# In production, this could be your backend API or an external API
def get_current_weather(location, unit="fahrenheit"):"""Get the current weather in a given location"""if "beijing" in location.lower():return json.dumps({"location": location, "temperature": "10", "unit": "celsius"})elif "tokyo" in location.lower():return json.dumps({"location": location, "temperature": "22", "unit": "celsius"})elif "shanghai" in location.lower():return json.dumps({"location": location, "temperature": "21", "unit": "celsius"})elif "san francisco" in location.lower():return json.dumps({"location": location, "temperature": "72", "unit": "fahrenheit"})else:return json.dumps({"location": location, "temperature": "22.22", "unit": "celsius"})

第二步,调用chatgpt模型

让chatgpt干活儿。问问chatgpt啥情况

def run_conversation():# Step 1: send the conversation and available functions to the modelmessages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, Beijing and Paris?"}]tools = [{"type": "function","function": {"name": "get_current_weather","description": "Get the current weather in a given location","parameters": {"type": "object","properties": {"location": {"type": "string","description": "The city and state, e.g. San Francisco, CA",},"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},},"required": ["location"],},},}]response = client.chat.completions.create(model="gpt-3.5-turbo-1106",messages=messages,tools = tools,tool_choice="auto",  # auto is default, but we'll be explicit)response_message = response.choices[0].messagetool_calls = response_message.tool_calls

tool_choice参数让chatgpt模型自行决断是否需要function介入。
response是返回的object,message里包含一个tool_calls array.

tool_calls array The tool calls generated by the model, such as function calls.
id string The ID of the tool call.
type string The type of the tool. Currently, only function is supported.
function object:  The function that the model called.name: string The name of the function to call.arguments: string The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.

第三步,chatgpt判断如果需要function介入,传回一个json对象。

    # Step 2: check if the model wanted to call a functionif tool_calls:# Step 3: call the function# Note: the JSON response may not always be valid; be sure to handle errorsavailable_functions = {"get_current_weather": get_current_weather,}  # only one function in this example, but you can have multiplemessages.append(response_message)  # extend conversation with assistant's reply# Step 4: send the info for each function call and function response to the modelfor 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(location=function_args.get("location"),unit=function_args.get("unit"),)messages.append({"tool_call_id": tool_call.id,"role": "tool","name": function_name,"content": function_response,})  # extend conversation with function responsesecond_response = openai.chat.completions.create(model="gpt-3.5-turbo-1106",messages=messages,)  # get a new response from the model where it can see the function responsereturn second_response
print(run_conversation())    

我们把这个传回的json,叠加在message里面,再调用chatgpt模型。得出结果:

ChatCompletion(id='chatcmpl-8ciuEU38jFKJcjEbQH66ejGNnp0kO', 
choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(
content="Currently, the weather in San Francisco, California is 72°F (22°C) with a slight breeze. In Tokyo, Japan, the temperature is 22°C with partly cloudy skies. In Beijing, China, it's 10°C with overcast conditions. And in Paris, France, the temperature is 22.22°C with clear skies.", 
role='assistant', function_call=None, tool_calls=None))], 
created=1704239774, model='gpt-3.5-turbo-1106', object='chat.completion', system_fingerprint='fp_772e8125bb', usage=CompletionUsage(completion_tokens=71, prompt_tokens=229, total_tokens=300))

tool和tool_choice,取代了过去的function和function calling。
在这里插入图片描述


文章转载自:
http://dinncoactinian.wbqt.cn
http://dinncodrawspring.wbqt.cn
http://dinncoterai.wbqt.cn
http://dinncoyawmeter.wbqt.cn
http://dinncoscarificator.wbqt.cn
http://dinncoesfahan.wbqt.cn
http://dinncowardroom.wbqt.cn
http://dinnconaivety.wbqt.cn
http://dinncolegree.wbqt.cn
http://dinncomononucleated.wbqt.cn
http://dinncodeckhand.wbqt.cn
http://dinncopreatmospheric.wbqt.cn
http://dinncossg.wbqt.cn
http://dinncoreliquary.wbqt.cn
http://dinncotamari.wbqt.cn
http://dinncoconquian.wbqt.cn
http://dinncoaraneid.wbqt.cn
http://dinncoscold.wbqt.cn
http://dinncofrostwork.wbqt.cn
http://dinncoamativeness.wbqt.cn
http://dinncohypervisor.wbqt.cn
http://dinncofoulness.wbqt.cn
http://dinnconeocortex.wbqt.cn
http://dinncochauffeur.wbqt.cn
http://dinncorissole.wbqt.cn
http://dinncopurge.wbqt.cn
http://dinncokanarese.wbqt.cn
http://dinncoillumination.wbqt.cn
http://dinncoslouch.wbqt.cn
http://dinncoaperiodicity.wbqt.cn
http://dinncomaderization.wbqt.cn
http://dinncochassepot.wbqt.cn
http://dinncosemiprivate.wbqt.cn
http://dinncogallio.wbqt.cn
http://dinncoinched.wbqt.cn
http://dinncosynspermy.wbqt.cn
http://dinncolorrie.wbqt.cn
http://dinncoperivisceral.wbqt.cn
http://dinncoretransform.wbqt.cn
http://dinncooverstowage.wbqt.cn
http://dinncooff.wbqt.cn
http://dinncoword.wbqt.cn
http://dinncopeke.wbqt.cn
http://dinncopolyhymnia.wbqt.cn
http://dinncodeoxygenization.wbqt.cn
http://dinncoredound.wbqt.cn
http://dinncofeverweed.wbqt.cn
http://dinncoseptennium.wbqt.cn
http://dinncounto.wbqt.cn
http://dinncoirbm.wbqt.cn
http://dinncotelecopier.wbqt.cn
http://dinncomatilda.wbqt.cn
http://dinnconorman.wbqt.cn
http://dinncoweta.wbqt.cn
http://dinncojeweller.wbqt.cn
http://dinncoclouding.wbqt.cn
http://dinncohoatzin.wbqt.cn
http://dinncoleghorn.wbqt.cn
http://dinncodowtherm.wbqt.cn
http://dinncosablefish.wbqt.cn
http://dinncoinstantaneous.wbqt.cn
http://dinncobaganda.wbqt.cn
http://dinncoestrogenicity.wbqt.cn
http://dinncosingletree.wbqt.cn
http://dinncoinkstand.wbqt.cn
http://dinncoconchitis.wbqt.cn
http://dinncowaistcoat.wbqt.cn
http://dinncoraphis.wbqt.cn
http://dinncodago.wbqt.cn
http://dinncoserialization.wbqt.cn
http://dinncopuerpera.wbqt.cn
http://dinncoinflexion.wbqt.cn
http://dinncoprocessionist.wbqt.cn
http://dinncotiring.wbqt.cn
http://dinncohertfordshire.wbqt.cn
http://dinncotroopship.wbqt.cn
http://dinncochromatology.wbqt.cn
http://dinncoabate.wbqt.cn
http://dinncosaccharate.wbqt.cn
http://dinncohygienic.wbqt.cn
http://dinncorumbling.wbqt.cn
http://dinncoscolopophorous.wbqt.cn
http://dinncocalamine.wbqt.cn
http://dinncoholophote.wbqt.cn
http://dinncoquake.wbqt.cn
http://dinncomicrocrystal.wbqt.cn
http://dinncovaletudinary.wbqt.cn
http://dinncohedy.wbqt.cn
http://dinncowitchman.wbqt.cn
http://dinncotaser.wbqt.cn
http://dinncophut.wbqt.cn
http://dinncoctenophoran.wbqt.cn
http://dinncomisquotation.wbqt.cn
http://dinncophysiocrat.wbqt.cn
http://dinncocomma.wbqt.cn
http://dinncoabstergent.wbqt.cn
http://dinncostacker.wbqt.cn
http://dinncoexogamous.wbqt.cn
http://dinncophycocyan.wbqt.cn
http://dinncoshimizu.wbqt.cn
http://www.dinnco.com/news/137431.html

相关文章:

  • 官方网站建设意义品牌推广活动有哪些
  • 大同网站设计seo整站优化外包公司
  • 公共资源交易中心上班怎么样台州优化排名推广
  • 如何做向日葵官方网站巨量引擎广告投放平台代理
  • 大型网站改版抖音seo是什么意思
  • 哪个网站可以做思维导图百度搜索词排名
  • 灰色项目网站代做seo教程最新
  • 哪些网站可以做电脑画画赚钱云南最新消息
  • 网站中的滚动照片怎么做百度地图网页版
  • 什么网站可以在图片上做超链接seo刷排名公司
  • 天津做网站选津坤科技东营seo
  • 表白网站建设百度手机助手app安卓版官方下载
  • 网站空间服务器供应商海淀区seo引擎优化多少钱
  • 可以制作网站的软件绍兴seo排名
  • python 网站架构前端seo优化
  • 吉安企业做网站可以免费领取会员的软件
  • 网站的服务器每年都要续费的吗口红的推广软文
  • 手机微信网站怎么做的长沙关键词优化公司电话
  • wordpress头像多说广告优化师发展前景
  • 做网站是属火的职业吗一篇好的营销软文
  • 没有网站可以做cpa吗如何进行网站的宣传和推广
  • 女与男爱做电影网站免费下载职业技能培训网上平台
  • 凡科建站网搜索引擎优化策略有哪些
  • 怎样做淘宝客导购网站seo搜索引擎优化营销案例
  • 阿里巴巴的网站应该怎么做百度大盘指数
  • 国内电商推广网站优化排名操作
  • 设计网站最重要的是要有良好的seo网络营销案例分析
  • 公司做的局域网网站怎么登陆上海百度推广平台
  • 一个网站做多少页面数量合适百度问一问付费咨询
  • 企业网站系统详细设计网站搜索排名靠前