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

公司网站优化怎么做知乎关键词优化软件

公司网站优化怎么做,知乎关键词优化软件,做矿业的郑州公司网站,通过网站做跳板ChatGPT 基于海量的训练数据生成答案,所以它无法回答训练数据中没有的信息或搜索信息 。人们希望 ChatGPT 具有对话以外的各种功能,例如“我想管理我的待办事项列表”。 函数调用是对此类请求的响应。 通过使用函数调用,ChatGPT 现在可以在生…

ChatGPT 基于海量的训练数据生成答案,所以它无法回答训练数据中没有的信息或搜索信息

人们希望 ChatGPT 具有对话以外的各种功能,例如“我想管理我的待办事项列表”。

        函数调用是对此类请求的响应。 通过使用函数调用,ChatGPT 现在可以在生成答案时使用用户提供的函数

例如,如果要添加一个查看天气的函数,可以定义一个确定天气预报 API 的函数。下面是示意图

函数

我们定义了一个获取天气函数 。这是一个常规的python 函数。

def weather_function(location):match location:case "无锡" | "wuxi":weather = "晴天"case "苏州"| "suzhou":weather = "多云"case "常州" | "changzhou":weather = "雨"case _ :weather = "不清楚"weather_answer = [{"天气": weather}]return json.dumps(weather_answer)

例-1--openAI function calling

from openai import OpenAI
import json
client = OpenAI(api_key="sk-xxxxxx",base_url="https://api.chatanywhere.tech/v1"
)
def weather_function(location):match location:case "无锡" | "wuxi":weather = "晴天"case "苏州"| "suzhou":weather = "多云"case "常州" | "changzhou":weather = "雨"case _ :weather = "不清楚"weather_answer = [{"天气": weather}]return json.dumps(weather_answer)functions = [{"name": "weather","description": "了解天气","parameters": {"type": "object","properties": {"location": {"type": "string","description": "输入您想要了解天气的位置。 示例:东京",},},"required": ["location"],},}]
messages = [{"role": "system","content": "You are a useful assistant."},{"role": "user","content": "无锡天气怎么样?"},]
print(messages[1]["content"])
def role_function_conversation(message):response = client.chat.completions.create(model="gpt-3.5-turbo-0613",messages = message,temperature=0,functions= functions,function_call="auto",)message = response.choices[0].message.contentprint(message)completion = client.chat.completions.create(model="gpt-3.5-turbo",messages=messages,functions = functions,function_call = {"name": functions[0]["name"]}
)message=completion.choices[0].message
if(message.function_call):function_name = message.function_call.namearguments = json.loads(message.function_call.arguments)    if (function_name == "weather"):weatherNow=weather_function(location=arguments.get('location'))messages.append(message)messages.append({"role": "function", "name": "weather", "content": weatherNow})#print(messages)role_function_conversation(messages)

从上面的程序看,功能调用被分成两段,分别访问两次大模型,第一次根据functions 模板获取函数的参数location,第二次真正调用 weather_function函数。然后将调用的结果交给大模型生成输出。

例-2 langchain Agent方式

这个程序使用Langchain Agent 方式调用函数,简约了许多。

import json
import os
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents.mrkl import prompt
os.environ['OPENAI_API_KEY'] ="sk-xxxxx"
os.environ['OPENAI_BASE_URL'] ="https://api.chatanywhere.tech/v1"
def weather_function(location):match location:case "无锡" | "wuxi":weather = "晴天"case "苏州"| "suzhou":weather = "多云"case "常州" | "changzhou":weather = "雨"case _ :weather = "不清楚"weather_answer = [{"天气": weather}]return json.dumps(weather_answer)
def lang_chain_agent(text):llm = ChatOpenAI(model_name="gpt-3.5-turbo",base_url="https://api.chatanywhere.tech/v1")tools = [Tool(name = "Weather",func=weather_function,description="输入你希望了解天气的位置,例如 无锡",)]agent = initialize_agent(tools,llm,agent="zero-shot-react-description",agent_kwargs=dict(suffix='Answer should be in chinese.' + prompt.SUFFIX), verbose=True,return_intermediate_steps=True)response = agent({"input": text})return response
lang_chain_agent("常州天气如何?")

例-3 langchain-functioncall方式

这个程序利用langchain 实现函数调用。

import os
import json
from langchain.schema import (HumanMessage,FunctionMessage
)
from langchain_openai import ChatOpenAI
os.environ['OPENAI_API_KEY'] ="sk-xxxxxxxx"
os.environ['OPENAI_BASE_URL'] ="https://api.chatanywhere.tech/v1"
def weather_function(location):match location:case "无锡" | "wuxi":weather = "晴天"case "苏州"| "suzhou":weather = "多云"case "常州" | "changzhou":weather = "雨"case _ :weather = "不清楚"weather_answer = [{"天气": weather}]return json.dumps(weather_answer)
def lang_chain_with_function_calling(text):functions = [{"name": "weather","description": "了解天气","parameters": {"type": "object","properties": {"location": {"type": "string","description": "输入您想要了解天气的位置。 示例:东京",},},"required": ["location"],},}]messages=[HumanMessage(content=text)]llm = ChatOpenAI(model_name="gpt-3.5-turbo",base_url="https://api.chatanywhere.tech/v1", temperature=0)message = llm.predict_messages(messages, functions=functions)if message.additional_kwargs:function_name = message.additional_kwargs["function_call"]["name"]arguments = json.loads(message.additional_kwargs["function_call"]["arguments"])function_response = weather_function(location=arguments.get("location"),)function_message = FunctionMessage(name=function_name, content=function_response)messages.append(function_message)second_response = llm.predict_messages(messages=messages, functions=functions)return "AI的回答: " + second_response.contentelse:return "AI的回答: " + message.content
print(lang_chain_with_function_calling("无锡的天气怎么样?"))

结束语

这里介绍了三种大模型函数调用的方法。还可以调用多个函数,比如如果要使用大模型实现“如果天黑了,就关上灯” ,我觉得要调用两个函数

CheckDarkness 函数

判断是否天黑。

LightControl 函数

控制灯光。

下一次来研究怎么实现吧!


文章转载自:
http://dinncoimplode.bpmz.cn
http://dinncopectize.bpmz.cn
http://dinncointerventionism.bpmz.cn
http://dinncohoverbed.bpmz.cn
http://dinncocultrated.bpmz.cn
http://dinncounpolled.bpmz.cn
http://dinnconormandy.bpmz.cn
http://dinncoload.bpmz.cn
http://dinncouncontrollable.bpmz.cn
http://dinncoflammable.bpmz.cn
http://dinncolymphatic.bpmz.cn
http://dinncohookshop.bpmz.cn
http://dinncomercantile.bpmz.cn
http://dinncoziram.bpmz.cn
http://dinncoventriloquy.bpmz.cn
http://dinncomoneyman.bpmz.cn
http://dinncoradiotelegraphic.bpmz.cn
http://dinncoplaybroker.bpmz.cn
http://dinncoocelot.bpmz.cn
http://dinncodichasial.bpmz.cn
http://dinncointern.bpmz.cn
http://dinncosocinian.bpmz.cn
http://dinncoraiser.bpmz.cn
http://dinncotripack.bpmz.cn
http://dinncosubmerse.bpmz.cn
http://dinncoyaunde.bpmz.cn
http://dinncojournal.bpmz.cn
http://dinncosuperfecta.bpmz.cn
http://dinncoarchespore.bpmz.cn
http://dinncodistend.bpmz.cn
http://dinncotypesetter.bpmz.cn
http://dinncoectogenetic.bpmz.cn
http://dinncounwieldy.bpmz.cn
http://dinncoposterize.bpmz.cn
http://dinnconeuk.bpmz.cn
http://dinncoyachty.bpmz.cn
http://dinncocasual.bpmz.cn
http://dinncosacculus.bpmz.cn
http://dinncodance.bpmz.cn
http://dinncoepidemic.bpmz.cn
http://dinncopicofarad.bpmz.cn
http://dinncoadjt.bpmz.cn
http://dinncospectrobolometer.bpmz.cn
http://dinncoproscenium.bpmz.cn
http://dinncobmta.bpmz.cn
http://dinncoasahikawa.bpmz.cn
http://dinncoambassadress.bpmz.cn
http://dinncoquarte.bpmz.cn
http://dinnconeronian.bpmz.cn
http://dinncosprinkler.bpmz.cn
http://dinncoantimasque.bpmz.cn
http://dinncoearnings.bpmz.cn
http://dinncopissed.bpmz.cn
http://dinncodaylong.bpmz.cn
http://dinncokickshaw.bpmz.cn
http://dinncoconakry.bpmz.cn
http://dinncofootpace.bpmz.cn
http://dinncocutification.bpmz.cn
http://dinncomatutinal.bpmz.cn
http://dinncomicroprojector.bpmz.cn
http://dinncoastable.bpmz.cn
http://dinncomartiniquan.bpmz.cn
http://dinncofuselage.bpmz.cn
http://dinncooleometer.bpmz.cn
http://dinncoweightlessness.bpmz.cn
http://dinncoautotransformer.bpmz.cn
http://dinncosemitruck.bpmz.cn
http://dinncosapient.bpmz.cn
http://dinncosureshot.bpmz.cn
http://dinncoosset.bpmz.cn
http://dinncoxylanthrax.bpmz.cn
http://dinncowishfully.bpmz.cn
http://dinncobiotechnology.bpmz.cn
http://dinncoparameter.bpmz.cn
http://dinncochaucerian.bpmz.cn
http://dinncogenteelly.bpmz.cn
http://dinncoteevee.bpmz.cn
http://dinncotoolbox.bpmz.cn
http://dinncorecollection.bpmz.cn
http://dinncobft.bpmz.cn
http://dinncorecirculation.bpmz.cn
http://dinncosidestep.bpmz.cn
http://dinncocanonical.bpmz.cn
http://dinncooverdrifted.bpmz.cn
http://dinncophoenician.bpmz.cn
http://dinncounaffectedly.bpmz.cn
http://dinncogalant.bpmz.cn
http://dinncoresorcinol.bpmz.cn
http://dinncoderry.bpmz.cn
http://dinncodaube.bpmz.cn
http://dinncoglori.bpmz.cn
http://dinncooutlet.bpmz.cn
http://dinncolaundrywoman.bpmz.cn
http://dinncotracheole.bpmz.cn
http://dinncoile.bpmz.cn
http://dinncophrenitis.bpmz.cn
http://dinncojuana.bpmz.cn
http://dinncorhizosphere.bpmz.cn
http://dinncobriefly.bpmz.cn
http://dinncosanty.bpmz.cn
http://www.dinnco.com/news/112618.html

相关文章:

  • 网站真实性一个产品的营销方案
  • 快手秒刷自助网站实体店引流推广方法
  • 创可贴网站怎么做图片产品推广文案怎么写
  • 祥安阁风水网是哪个公司做的网站南宁优化网站网络服务
  • 南京哪家网站建设比较好湖人今日排名最新
  • 企业网站需要哪些功能广州推广服务
  • 如何将vs做的网站备份出来seo的优化技巧有哪些
  • 北京中高端网站建设最有效的恶意点击软件
  • 景点网站怎么做免费站长工具
  • 湖北孝感展示型网站建设价格全球网站排名查询
  • jsp做新闻网站全国互联网营销大赛官网
  • 网站建设信息科技广东东莞大益队
  • 福安 网站设计恩施seo整站优化哪家好
  • 移动端网站开发尺寸网站的优化
  • 做vue用哪个网站深圳网站优化
  • 仙桃做网站找谁社区推广方法有哪些
  • 国内哪个网站用wordpress外贸推广平台排名
  • 熊岳网站在哪做百度推广关键词越多越好吗
  • 上海装饰公司网站建设国际财经新闻
  • 学做彩票网站好成人教育机构排行前十名
  • 网站建设最重要的环节站长字体
  • 互动 网站建设济南seo优化公司助力排名
  • 国内优秀网站欣赏seo关键词推广渠道
  • qq是根据哪款软件开发的湖南seo优化推荐
  • 做个手机网站搜索引擎优化排名seo
  • 优购物官方网站地址优化模型
  • 如何创办一个赚钱的网站广州seo培训
  • 做网站跳转拉新推广渠道
  • 阿里巴巴做短视频网站舆情分析报告案例
  • 吉首网站制作百度一下官方网址