国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

做噯噯的網(wǎng)站科學(xué)新概念外鏈平臺

做噯噯的網(wǎng)站,科學(xué)新概念外鏈平臺,北京十大室內(nèi)設(shè)計(jì)公司排名,今日頭條網(wǎng)站開發(fā)背景描述 這一節(jié)內(nèi)容比較復(fù)雜: 涉及到使用工具進(jìn)行百科的檢索(有現(xiàn)成的插件)有AgentExecutor來幫助我們執(zhí)行后續(xù)由于上下文過大, 我們通過計(jì)算num_tokens,來控制我們的上下文 安裝依賴 pip install --upgrade --qu…

背景描述

這一節(jié)內(nèi)容比較復(fù)雜:

  • 涉及到使用工具進(jìn)行百科的檢索(有現(xiàn)成的插件)
  • AgentExecutor來幫助我們執(zhí)行
  • 后續(xù)由于上下文過大, 我們通過計(jì)算num_tokens,來控制我們的上下文

安裝依賴

pip install --upgrade --quiet  langchain langchain-openai wikipedia

代碼編寫

GPT 3.5 Turbo 解決這個問題總是出錯,偶爾可以正常解決,所以這里使用了 GPT-4-Turbo,準(zhǔn)確率基本時100%

from operator import itemgetter
from langchain.agents import AgentExecutor, load_tools
from langchain.agents.format_scratchpad import format_to_openai_function_messages
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
from langchain.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain_core.prompt_values import ChatPromptValue
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_openai import ChatOpenAI# Initialize Wikipedia tool with a wrapper for querying
wiki = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(top_k_results=5, doc_content_chars_max=10_000)
)
tools = [wiki]prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant"),("user", "{input}"),MessagesPlaceholder(variable_name="agent_scratchpad"),]
)
llm = ChatOpenAI(model="gpt-4-0125-preview")agent = ({"input": itemgetter("input"),"agent_scratchpad": lambda x: format_to_openai_function_messages(x["intermediate_steps"]),}| prompt| llm.bind_functions(tools)| OpenAIFunctionsAgentOutputParser()
)agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# agent_executor.invoke(
#     {
#         "input": "Who is the current US president? What's their home state? What's their home state's bird? What's that bird's scientific name?"
#     }
# )agent_executor.invoke({"input": "大模型Grok是什么?作者是誰?他還干了什么?Grok是開源模型嗎?如果是什么時候開源的?"}
)

運(yùn)行結(jié)果

? python3 test15.py
/Users/wuzikang/Desktop/py/langchain_test/own_learn/env/lib/python3.12/site-packages/langchain/tools/__init__.py:63: LangChainDeprecationWarning: Importing tools from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:`from langchain_community.tools import WikipediaQueryRun`.To install langchain-community run `pip install -U langchain-community`.warnings.warn(> Entering new AgentExecutor chain...Invoking: `wikipedia` with `Grok large model`Page: Grok (chatbot)
Summary: Grok is a generative artificial intelligence chatbot developed by xAI, based on a large language model (LLM). It was developed as an initiative by Elon Musk as a direct response to the rise of OpenAI's ChatGPT which Musk co-founded. The chatbot is advertised as "having a sense of humor" and direct access to Twitter (X). It is currently under beta testing for those with the premium version of X.Page: Large language model
Summary: A large language model (LLM) is a language model notable for its ability to achieve general-purpose language generation and other natural language processing tasks such as classification. LLMs acquire these abilities by learning statistical relationships from text documents during a computationally intensive self-supervised and semi-supervised training process. LLMs can be used for text generation, a form of generative AI, by taking an input text and repeatedly predicting the next token or word.LLMs are artificial neural networks. The largest and most capable are built with a decoder-only transformer-based architecture while some recent implementations are based on other architectures, such as recurrent neural network variants and Mamba (a state space model).Up to 2020, fine tuning was the only way a model could be adapted to be able to accomplish specific tasks. Larger sized models, such as GPT-3, however, can be prompt-engineered to achieve similar results. They are thought to acquire knowledge about syntax, semantics and "ontology" inherent in human language corpora, but also inaccuracies and biases present in the corpora.Some notable LLMs are OpenAI's GPT series of models (e.g., GPT-3.5 and GPT-4, used in ChatGPT and Microsoft Copilot), Google's PaLM and Gemini (the latter of which is currently used in the chatbot of the same name), xAI's Grok, Meta's LLaMA family of open-source models, Anthropic's Claude models, and Mistral AI's open source models.Page: Gemini (language model)
Summary: Gemini is a family of multimodal large language models developed by Google DeepMind, serving as the successor to LaMDA and PaLM 2. Comprising Gemini Ultra, Gemini Pro, and Gemini Nano, it was announced on December 6, 2023, positioned as a competitor to OpenAI's GPT-4. It powers the generative artificial intelligence chatbot of the same name.Page: Language model
Summary: A language model is a probabilistic model of a natural language. In 1980, the first significant statistical language model was proposed, and during the decade IBM performed ‘Shannon-style’ experiments, in which potential sources for language modeling improvement were identified by observing and analyzing the performance of human subjects in predicting or correcting text.Language models are useful for a variety of tasks, including speech recognition (helping prevent predictions of low-probability (e.g. nonsense) sequences), machine translation, natural language generation (generating more human-like text), optical character recognition, handwriting recognition, grammar induction, and information retrieval.Large language models, currently their most advanced form, are a combination of larger datasets (frequently using scraped words from the public internet), feedforward neural networks, and transformers. They have superseded recurrent neural network-based models, which had previously superseded the pure statistical models, such as word n-gram language model.Page: ChatGPT
Summary: ChatGPT (Chat Generative Pre-trained Transformer) is a chatbot developed by OpenAI and launched on November 30, 2022. Based on a large language model, it enables users to refine and steer a conversation towards a desired length, format, style, level of detail, and language. Successive prompts and replies, known as prompt engineering, are considered at each conversation stage as a context.By January 2023, it had become what was then the fastest-growing consumer software application in history, gaining over 100 million users and contributing to the growth of OpenAI's valuation to $29 billion. ChatGPT's release spurred the release of competing products, including Gemini, Ernie Bot, LLaMA, Claude, and Grok. Microsoft launched Copilot, based on OpenAI's GPT-4. Some observers raised concern about the potential of ChatGPT and similar programs to displace or atrophy human intelligence, enable plagiarism, or fuel misinformation.ChatGPT is available for use online in two versions, one built on GPT-3.5 and the other on GPT-4, both of which are members of OpenAI's proprietary series of generative pre-trained transformer (GPT) models, based on the transformer architecture developed by Google—and is fine-tuned for conversational applications using a combination of supervised learning and reinforcement learning from human feedback. ChatGPT was released as a freely available research preview, but due to its popularity, OpenAI now operates the service on a freemium model. It allows users on its free tier to access the GPT-3.5-based version, while the more advanced GPT-4-based version and priority access to newer features are provided to paid subscribers under the commercial name "ChatGPT Plus".
ChatGPT is credited with starting the AI boom, which has led to ongoing rapid and unprecedented investment in and public attention to the field of artificial intelligence.Grok是一個基于大型語言模型(LLM)的生成式人工智能聊天機(jī)器人,由xAI開發(fā)。Grok的開發(fā)是由Elon Musk作為對OpenAI推出的ChatGPT崛起的直接回應(yīng)而啟動的項(xiàng)目,其中Elon Musk是OpenAI的共同創(chuàng)始人。Grok的一個特點(diǎn)是它被宣傳為“具有幽默感”,并且可以直接訪問Twitter(現(xiàn)X)。目前,Grok仍處于Beta測試階段,僅對X的高級版用戶開放。至于Grok是否是一個開源模型,從目前的信息來看,并沒有提及Grok是一個開源項(xiàng)目。通常,是否開源以及開源的時間點(diǎn)是由開發(fā)該模型的組織或團(tuán)隊(duì)決定的,關(guān)于Grok的開源狀態(tài),可能需要進(jìn)一步從xAI或相關(guān)的官方消息中獲取確切信息。Elon Musk是一位知名的企業(yè)家和工程師,他創(chuàng)辦或領(lǐng)導(dǎo)了多個著名的技術(shù)和航天公司,包括SpaceX、Tesla Inc.、Neuralink和The Boring Company。他在推動太空探索、電動汽車發(fā)展和人工智能領(lǐng)域都有顯著的貢獻(xiàn)。> Finished chain.

可以看到 Agent 幫助我們執(zhí)行總結(jié)出了結(jié)果:

Grok是一個基于大型語言模型(LLM)的生成式人工智能聊天機(jī)器人,由xAI開發(fā)。Grok的開發(fā)是由Elon Musk作為對OpenAI推出的ChatGPT崛起的直接回應(yīng)而啟動的項(xiàng)目,其中Elon Musk是OpenAI的共同創(chuàng)始人。Grok的一個特點(diǎn)是它被宣傳為“具有幽默感”,并且可以直接訪問Twitter(現(xiàn)X)。目前,Grok仍處于Beta測試階段,僅對X的高級版用戶開放。至于Grok是否是一個開源模型,從目前的信息來看,并沒有提及Grok是一個開源項(xiàng)目。通常,是否開源以及開源的時間點(diǎn)是由開發(fā)該模型的組織或團(tuán)隊(duì)決定的,關(guān)于Grok的開源狀態(tài),可能需要進(jìn)一步從xAI或相關(guān)的官方消息中獲取確切信息。Elon Musk是一位知名的企業(yè)家和工程師,他創(chuàng)辦或領(lǐng)導(dǎo)了多個著名的技術(shù)和航天公司,包括SpaceX、Tesla Inc.、Neuralink和The Boring Company。他在推動太空探索、電動汽車發(fā)展和人工智能領(lǐng)域都有顯著的貢獻(xiàn)。

在這里插入圖片描述

消耗情況

由于上下文過大,資費(fèi)是非??植赖?/code>
在這里插入圖片描述

優(yōu)化代碼

我們通過定義了一個condense_prompt函數(shù)來計(jì)算和控制上下文

# 控制上下文大小
def condense_prompt(prompt: ChatPromptValue) -> ChatPromptValue:messages = prompt.to_messages()num_tokens = llm.get_num_tokens_from_messages(messages)ai_function_messages = messages[2:]# 這里限制了while num_tokens > 4_000:ai_function_messages = ai_function_messages[2:]num_tokens = llm.get_num_tokens_from_messages(messages[:2] + ai_function_messages)messages = messages[:2] + ai_function_messagesreturn ChatPromptValue(messages=messages)

完整的代碼如下

from operator import itemgetter
from langchain.agents import AgentExecutor, load_tools
from langchain.agents.format_scratchpad import format_to_openai_function_messages
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
from langchain.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain_core.prompt_values import ChatPromptValue
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_openai import ChatOpenAI# Initialize Wikipedia tool with a wrapper for querying
wiki = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper(top_k_results=5, doc_content_chars_max=10_000)
)
tools = [wiki]prompt = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant"),("user", "{input}"),MessagesPlaceholder(variable_name="agent_scratchpad"),]
)
llm = ChatOpenAI(model="gpt-4-0125-preview")# 控制上下文大小
def condense_prompt(prompt: ChatPromptValue) -> ChatPromptValue:messages = prompt.to_messages()num_tokens = llm.get_num_tokens_from_messages(messages)ai_function_messages = messages[2:]# 這里限制了while num_tokens > 4_000:ai_function_messages = ai_function_messages[2:]num_tokens = llm.get_num_tokens_from_messages(messages[:2] + ai_function_messages)messages = messages[:2] + ai_function_messagesreturn ChatPromptValue(messages=messages)# 注意在Chain中加入
agent = ({"input": itemgetter("input"),"agent_scratchpad": lambda x: format_to_openai_function_messages(x["intermediate_steps"]),}| prompt| condense_prompt| llm.bind_functions(tools)| OpenAIFunctionsAgentOutputParser()
)agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# agent_executor.invoke(
#     {
#         "input": "Who is the current US president? What's their home state? What's their home state's bird? What's that bird's scientific name?"
#     }
# )agent_executor.invoke({"input": "大模型Grok是什么?作者是誰?他還干了什么?Grok是開源模型嗎?如果是什么時候開源的?"}
)

在這里插入圖片描述

http://aloenet.com.cn/news/37368.html

相關(guān)文章:

  • 第三方網(wǎng)站開發(fā)優(yōu)缺點(diǎn)銷售渠道及方式
  • 廣告圖文制作用哪個軟件seoul是啥意思
  • 網(wǎng)站開發(fā)和app的區(qū)別優(yōu)化大師使用方法
  • 不用編程做APP和響應(yīng)式網(wǎng)站百度手機(jī)助手下載安卓版
  • 買公司的網(wǎng)站建設(shè)軟文寫作營銷
  • 銅川網(wǎng)站建設(shè)報(bào)價(jià)網(wǎng)絡(luò)推廣的主要工作內(nèi)容
  • 專門做網(wǎng)站需要敲代碼么旺道seo優(yōu)化軟件怎么用
  • 做網(wǎng)站宣傳圖片google全球推廣
  • 珠海建網(wǎng)站專業(yè)公司專業(yè)seo優(yōu)化推廣
  • 如何做網(wǎng)站條幅閃圖搜索關(guān)鍵詞怎么讓排名靠前
  • wordpress頭像網(wǎng)站百度ai人工智能平臺
  • 該怎么給做網(wǎng)站的提頁面需求深圳網(wǎng)絡(luò)推廣網(wǎng)絡(luò)
  • 廣東省廣州市白云區(qū)太和鎮(zhèn)名風(fēng)seo軟件
  • 中新生態(tài)城建設(shè)局門戶網(wǎng)站昆明seo案例
  • 佛山網(wǎng)站建設(shè)在哪手機(jī)優(yōu)化
  • 重慶網(wǎng)站建設(shè)公司銷售seo營銷推廣多少錢
  • 珠海企業(yè)網(wǎng)站建設(shè)seo優(yōu)化seo外包
  • b2b網(wǎng)站怎么發(fā)布信息站長之家論壇
  • 專業(yè)醫(yī)院網(wǎng)站建設(shè)百度網(wǎng)盤下載
  • 太原市做網(wǎng)站公司微信營銷軟件手機(jī)版
  • 企業(yè)做網(wǎng)站大概多少錢湖南關(guān)鍵詞網(wǎng)絡(luò)科技有限公司
  • plone wordpressseo人工智能
  • 平易云 網(wǎng)站建設(shè)看廣告賺錢
  • 政府網(wǎng)站建設(shè)培訓(xùn)講話惠州優(yōu)化怎么做seo
  • 漂亮企業(yè)網(wǎng)站源碼關(guān)鍵詞優(yōu)化排名軟件
  • 網(wǎng)站設(shè)計(jì)概述500字關(guān)鍵詞批量調(diào)詞軟件
  • 學(xué)生做爰網(wǎng)站微信群推廣網(wǎng)站
  • 專業(yè)鄭州做網(wǎng)站的公司今日國家新聞
  • 動態(tài)網(wǎng)站開發(fā)結(jié)束語東莞優(yōu)化怎么做seo
  • 彩票網(wǎng)站建設(shè)方案看網(wǎng)站時的關(guān)鍵詞