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

广州有几个区哪个区最好百度官方优化指南

广州有几个区哪个区最好,百度官方优化指南,前端网站开发培训,wordpress腾讯视频播放器OpenAI的Function calling openai最近发布的gpt-3.5-turbo-0613 和 gpt-4-0613版本模型增加了function calling的功能,该功能通过定义功能函数,gpt通过分析问题和函数功能描述来决定是否调用函数,并且生成函数对应的入参。函数调用的功能可以…

OpenAI的Function calling

         openai最近发布的gpt-3.5-turbo-0613 和 gpt-4-0613版本模型增加了function calling的功能,该功能通过定义功能函数,gpt通过分析问题和函数功能描述来决定是否调用函数,并且生成函数对应的入参。函数调用的功能可以弥补gpt的一些缺点,比如实时信息的缺乏、特定领域能力,使得能够进一步利用gpt的逻辑推理能力,可以将问题进行分解处理,解决问题能力更加强大。

gpt的函数调用功能步骤如下:
    1.使用问句和函数定义调用gpt
         2.gpt选择是否调用函数,并输出参数
         3.解析参数 调用函数
         4.将函数返回作为追加信息再次调用gpt

下面是一个通过调用search api的例子

1.定义+描述函数

        下面代码介绍了一个搜索函数,可以通过GoogleSerperAPI实时搜索网络上的信息。

###定义functions,用于描述函数作用和参数介绍。
functions = [{"name": "get_info_from_web","description": "get more informations from internet use google search","parameters": {"type": "object","properties": {"query": {"type": "string","description": "all the questions or information you want search from internet",}},"required": ["query"],},}
]###函数定义
def get_info_from_web(query):search = GoogleSerperAPIWrapper(serper_api_key="xxxxx")return search.run(query)

2.调用gpt,决定是否调用函数以及函数参数

        当用户问句为"今天杭州天气怎么样?"时,gpt做出了进行调用get_info_from_web函数的决定,并且调用的参数为"query": "杭州天气"。

messages = []
messages.append({"role": "system", "content": "Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous. "})
messages.append({"role": "user", "content": "今天杭州天气怎么样?"})
chat_response = chat_completion_request(messages, functions=functions
)
assistant_message = chat_response.json()["choices"][0]["message"]
messages.append(assistant_message)
print(assistant_message)>>>
{'role': 'assistant','content': None,'function_call': {'name': 'get_info_from_web','arguments': '{\n  "query": "杭州天气"\n}'}
}

3.执行gpt的决定,获得回答问题的中间结果

        调用第2步中gpt输出的参数执行相应的函数,获得中间结果。

assistant_message = chat_response.json()["choices"][0]["message"]
if assistant_message.get("function_call"):if assistant_message["function_call"]["name"] == "get_info_from_web":query = json.loads(assistant_message["function_call"]["arguments"])["query"]results = get_info_from_web(query)else:results = f"Error: function {assistant_message['function_call']['name']} does not exist"
print(results)>>>
81°F

4.函数结果和原始问题再次询问gpt,获得最终结果

messages.append({"role": "function", "name": assistant_message["function_call"]["name"], "content": results})
second_response = openai.ChatCompletion.create(model= GPT_MODEL,messages=messages)
print(second_response["choices"][0]["message"]["content"])>>>
今天杭州的天气是81°F。

LangChain的Search Agent        

        在openai的function calling发布之前,LangChain的Agent就可以实现类似功能。Agent接口是LangChain中一个重要的模块,一些应用程序需要根据用户输入灵活地调用LLM和其他工具。Agent接口为此类应用程序提供了灵活性。Agent可以访问一套工具,并根据用户输入确定要使用哪些工具。Agent可以使用多个工具,并将一个工具的输出用作下一个工具的输入。

        以下是search agent的例子。定义GoogleSerperApi工具作为LLM可用的tool,帮助解决相关问题。

from langchain.utilities import GoogleSerperAPIWrapper
from langchain.llms.openai import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentTypellm = OpenAI(temperature=0)
search = GoogleSerperAPIWrapper(serper_api_key="xxxxxx")
tools = [Tool(name="Intermediate Answer",func=search.run,description="useful for when you need to ask with search",)
]self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True
)self_ask_with_search.run("今天杭州天气怎么样?"
)>>>
> Entering new AgentExecutor chain...Yes.
Follow up: 今天是几号?
Intermediate answer: Sunday, July 16, 2023
Follow up: 杭州今天的天气情况?
Intermediate answer: 88°F
So the final answer is: 88°F> Finished chain.
88°F

       agent功能通过设计prompt实现,search agent的prompt设计如下:

"""Question: Who lived longer, Muhammad Ali or Alan Turing?
Are follow up questions needed here: Yes.
Follow up: How old was Muhammad Ali when he died?
Intermediate answer: Muhammad Ali was 74 years old when he died.
Follow up: How old was Alan Turing when he died?
Intermediate answer: Alan Turing was 41 years old when he died.
So the final answer is: Muhammad AliQuestion: When was the founder of craigslist born?
Are follow up questions needed here: Yes.
Follow up: Who was the founder of craigslist?
Intermediate answer: Craigslist was founded by Craig Newmark.
Follow up: When was Craig Newmark born?
Intermediate answer: Craig Newmark was born on December 6, 1952.
So the final answer is: December 6, 1952Question: Who was the maternal grandfather of George Washington?
Are follow up questions needed here: Yes.
Follow up: Who was the mother of George Washington?
Intermediate answer: The mother of George Washington was Mary Ball Washington.
Follow up: Who was the father of Mary Ball Washington?
Intermediate answer: The father of Mary Ball Washington was Joseph Ball.
So the final answer is: Joseph BallQuestion: Are both the directors of Jaws and Casino Royale from the same country?
Are follow up questions needed here: Yes.
Follow up: Who is the director of Jaws?
Intermediate answer: The director of Jaws is Steven Spielberg.
Follow up: Where is Steven Spielberg from?
Intermediate answer: The United States.
Follow up: Who is the director of Casino Royale?
Intermediate answer: The director of Casino Royale is Martin Campbell.
Follow up: Where is Martin Campbell from?
Intermediate answer: New Zealand.
So the final answer is: NoQuestion: {input}
Are followup questions needed here:{agent_scratchpad}"""

 可以从prompt看出,通过四个例子提出了解决问题的方式,即通过follow up + Intermediate answer 分解问题并解决子问题。follow up是gpt的输出,表示需要search tool搜索的问题, Intermediate answer 则为search tool的答案,循环多次之后得到最终答案。
 

http://www.yidumall.com/news/19933.html

相关文章:

  • 营销型网站建设的特别之处都有哪些淘宝app官方下载
  • 网站直播是未开票收入怎么做小程序开发教程全集免费
  • 今天中国疫情最新消息黑帽seo技术论坛
  • 厦门 外贸商城网站建设网站优化排名易下拉系统
  • 郑州网站推广排名公司太仓网站制作
  • 做网站用动易siteweaver cms还是phpcms淄博信息港聊天室网址
  • 阳泉购物网站开发设计网店代运营可靠吗
  • 自己的电脑做服务区 网站典型的口碑营销案例
  • 网站建设有必要做手机端吗东莞商城网站建设
  • 小程序开发平台哪家服务好北京seo推广外包
  • 搜索引擎网站排名官方百度
  • 上海哪家公司做网站比较好个人博客网站模板
  • 滨州正规网站建设哪家好百度文库个人登录入口
  • 技术支持 嘉兴网站建设厦门网站建设公司名单
  • 西安有什么好玩的地方轻松seo优化排名
  • 免费的小网站百度经验发布平台
  • 3如何做网站推广搜狗站长平台主动提交
  • 白银做网站网站优化方案怎么写
  • 网站防采集如何建立一个自己的网站?
  • 手机模版网站价格微信seo是什么意思
  • 网站 日历插件网站数据统计工具
  • 音乐网站开发文档全网营销平台
  • 网站发送邮件功能seo学徒
  • 惠州做公司网站做谷歌推广比较好的公司
  • 哪个网站专题做的好免费建立个人网站
  • 北京市住房城乡建设委官方网站做关键词优化
  • wordpress自适应博客主题郑州seo关键词排名优化
  • 做网站的宽和高有限制吗广告营销包括哪些方面
  • 一个网站为什么做的不好看买域名
  • 做电商网站价钱深圳最新疫情