Sure, the translation of "LangChain Memory and Agents Simplified" into simplified Chinese while keeping HTML structure would be: ```html LangChain 记忆和代理简化 ``` In this translation: - "LangChain" remains unchanged as it is a proper noun. - "记忆和代理简化" translates "Memory and Agents Simplified" into simplified Chinese, reflecting the meaning accurately.
To translate "Pure Python implementations of two prompt engineering methods" into simplified Chinese while keeping the HTML structure, you would write: ```html
两种基于纯Python的即时工程方法的实现
``` This HTML snippet preserves the structure and inserts the translated text.这篇文章假设读者对语言建模和提示工程有一定的了解。
Sure, here's how you would write "Introduction" in simplified Chinese while keeping the HTML structure intact: ```html
介绍
``` In this HTML snippet, `` denotes a paragraph tag, and "介绍" (jièshào) is the translation for "Introduction" in simplified Chinese.
在保持HTML结构的情况下,将以下英文文本翻译为简体中文: "引导工程是我们为了完成像聊天、推理和问答等复杂任务而投入的所有努力。其中一些努力包括:" 请注意,这里的翻译保持了原文的意思和结构,并使用了常见的简体中文表达方式。
- Sure, here's the text translated into simplified Chinese while keeping the HTML structure: ```html 少样本学习(展示如何通过少数示例执行) ``` This HTML structure ensures that the translation can be integrated into a web page seamlessly.
- Sure, here's the translation in simplified Chinese while keeping the HTML structure intact: ```html 检索增强生成(从私人文件中获取必要信息) ```
- Sure, here's how you can translate "conversation memory (reminding what was talked previously)" into simplified Chinese while keeping the HTML structure: ```html 对话记忆(提醒之前讨论过的内容) ``` In this HTML snippet: - `` is used to denote a section of text that needs specific styling or semantic meaning. - `对话记忆(提醒之前讨论过的内容)` is the translation of "conversation memory (reminding what was talked previously)" into simplified Chinese.
- Sure, the translation of "agents -a.k.a. tool-use- (providing external tools as helper)" into simplified Chinese while keeping the HTML structure intact would be: ```html 代理人 -又名工具使用者-(提供外部工具作为助手) ``` In this HTML snippet: - `` tags are used to ensure inline styling without altering the document's overall structure.
```html
LangChain 🦜️🔗 是一个实现这些详细内容的令人兴奋的框架。它是开发者构建LLM应用程序的首选库。我个人用它来获取了很多关于这个主题的实际经验。然而,它从一开始就抽象了许多概念,导致学习曲线陡峭(请参阅这些Reddit和YCombinator帖子)。
```在本文中,我使用纯Python实现了两个重要的工程概念,即对话记忆和代理。我旨在展示编写这些强大方法有多么简单,并且如何根据不同的使用情况进行定制。代码可在GitHub上找到。
Sure, here's how you can write "Setting up the environment" in simplified Chinese while keeping the HTML structure: ```html
设置环境
``` This HTML snippet ensures the text "设置环境" (which translates to "Setting up the environment" in English) is displayed in a paragraph (``) element.
To translate the given English text into simplified Chinese and maintain HTML structure, you can use the following: ```html
我的LLM选择是OpenAI的gpt-3.5-turbo。我只需将API密钥放入.env文件中。您可以选择像HuggingFaceH4/zephyr-7b-beta这样的开源模型。
``` In this HTML snippet: - `` tags are used to wrap the translated text, indicating a paragraph in HTML. - Chinese text is inserted directly within the `
` tags. This maintains the structure and semantics while ensuring the text is correctly displayed in simplified Chinese.
import os
import ast
from dotenv import load_dotenv
import arxiv
from openai import OpenAI
# parse .env file and load all variables
load_dotenv()
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
# initialize open ai client for api calls
client = OpenAI()
Certainly! Here is the text "Conversation Memories" translated to simplified Chinese while keeping the HTML structure: ```html 对话记忆 ``` In this HTML snippet, `` is used to encapsulate the translated text "对话记忆" which means "Conversation Memories" in simplified Chinese.
To translate the provided English text into simplified Chinese while keeping the HTML structure intact, you can use the following: ```html LLMs 是无状态的,即它们独立处理每个提示。我们需要在每个新提示中嵌入过去的交互,以创建类似聊天的对话。我们有几种方式来存储这些过去的交互: ``` This HTML snippet maintains the structure of the text while providing the simplified Chinese translation.
Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html ConversationBufferMemory: 一种简单且适合大多数情况的记忆类型。它简单地将完整的对话历史存储在一个变量(history)中,并在每次新输入时将其放入提示作为当前对话。 ``` This HTML structure ensures that each part of the translated text is contained within `` tags, preserving the integrity of the text while allowing for easy styling or formatting if needed.
prompt = """System: This is a conversation between a software engineer and
intellectual AI bot. AI bot is talkative and teaches concepts to the engineer.
Current Conversation:
{history}
Human: {input}
AI:"""
history = ''
def talk(question):
global history
# put current values of the variables into prompt string
prompt_after_formatting = prompt.format(input=question,
history=history)
# make API call
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt_after_formatting}
]
)
# processing open ai's response
output = completion.choices[0].message.content
# my way of adding human and ai messages into history
history += f"Human: {question}\nAI: {output}\n"
return output
请看它的实际运行情况。以下是向LLM提问3个问题后的一个示例提示。您可以观察它有效地利用记忆来回答第二个问题。
talk("Do you know anything about OOP?")
talk("Sorry. What did I ask you?")
talk("What is SQL?")
print(prompt.format(input="current question",history=history))
System: This is a conversation between a software engineer and intellectual AI bot. AI bot is talkative and teaches concepts to the engineer.
Current Conversation:
Human: Do you know anything about OOP?
AI: Yes, Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects, which can contain data in the form of fields (attributes or properties) and code in the form of procedures (methods). OOP focuses on organizing code into reusable, modular components, allowing for easier maintenance and scalability. Is there a specific aspect of OOP you'd like more information on?
Human: Sorry. What did I ask you?
AI: You asked me if I know anything about OOP (Object-Oriented Programming).
Human: What is SQL?
AI: SQL stands for Structured Query Language, and it is used to communicate with and manipulate databases. SQL allows users to perform tasks such as retrieving data, creating, updating, and deleting records, and managing a database's structure. It is a standard language for interacting with relational databases and is essential for anyone working with data management and storage. Is there a specific aspect of SQL you'd like to know more about?
Human: current question
AI:
Sure, here is the translated text in simplified Chinese while keeping the HTML structure: ```html
2- ConversationSummaryMemory: ConservationBufferMemory fills up input token limit too quickly for a long chat history. Even though gpt-3.5-turbo has a huge limit (16k), longer prompts cost higher. For this, we can summarize the full conversation history using a second LLM to extract only the most important points.
``` Translated to Chinese: ```html2- 会话摘要记忆:保存缓冲记忆会因为输入令牌限制而在长时间聊天历史中迅速填满。尽管 gpt-3.5-turbo 有很大的限制(16k),但更长的提示成本更高。因此,我们可以使用第二个LLM来总结完整的对话历史,仅提取最重要的要点。
```prompt = """System: This is a conversation between a software engineer and
intellectual AI bot. AI bot is talkative and teaches concepts to the engineer.
Current Conversation Summary:
{summary}
Human: {input}
AI:"""
summary_prompt = """System: Your task is to summarize below conversation with
emphasis on key points. If nothing given, return ''.
{history}
Summary:"""
history = ''
def talk(question):
global history
# put history variable into summary prompt string
summary_prompt_after_formatting = summary_prompt.format(history=history)
# make API call for summarization
summary_completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": summary_prompt_after_formatting}
]
)
# processing open ai's response
summary = summary_completion.choices[0].message.content
# put current values of the variables into prompt string
prompt_after_formatting = prompt.format(input=question,
summary=summary)
# make API call for answering question
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt_after_formatting}
]
)
# processing open ai's response
output = completion.choices[0].message.content
print(prompt_after_formatting)
# my way of adding human and ai messages into history
history += f"Human: {question}\nAI: {output}\n"
return output
To translate "Let’s see this in action. You can see that summary includes all key points necessary to answer upcoming questions." into simplified Chinese while keeping the HTML structure intact, you can use the following: ```html 看看这个实例。您可以看到,总结包含了回答即将出现的问题所需的所有关键点。 ``` This HTML structure ensures that the translated Chinese text remains embedded in the context of the original sentence.
talk("How are you today?")
talk("Sorry. What did I ask you?")
talk("do you know about football?")
talk("when did england compete in euros first?")
talk("what were the other teams in the same competition?")
input prompt for last question:
System: This is a conversation between a software engineer and intellectual AI bot. AI bot is talkative and teaches concepts to the engineer.
Current Conversation Summary:
The conversation includes inquiries about the AI's knowledge of football and the Euros, specifically when England competed in the Euros for the first time in 1968 and the other teams that participated in the same competition. The AI provides detailed information about the tournament and the teams involved. It also emphasizes that it is ready to assist with any other questions related to football history or the Euros.
Human: what were the other teams in the same competition?
AI:
---
response for last question:
'In the 1968 European Championship, besides England, the other teams that competed were Italy, Yugoslavia, and the Soviet Union. Italy emerged as the champions of the tournament after defeating Yugoslavia in the final. If you have any more questions about the competition or football history, feel free to ask!'
Sure, the translation of "Agents and Tool-use" into simplified Chinese while keeping the HTML structure intact would be:
```html
代理和工具使用
```
```html
代理人只是一个可以借助描述性提示调用辅助功能(工具)的LLM的酷名字。LLM的推理能力和知识库对于无缺陷地回答任何问题是有限的。然而,当配备必要的工具如计算器、Google搜索、数学函数、天气API等时,它们表现出色。面对问题时,LLM不是试图提出可能包括幻觉和错误计算的答案,而是作为一个编排者逐步调用必要的函数来达到正确答案。通过这种方式,我们平衡了LLM的推理和行动能力,并且不仅仅依赖它已经有限的推理能力。有关代理人的更多信息,请参阅ReAct论文。
```Sure, here's the translated text in simplified Chinese, while maintaining HTML structure: ```html
让我们开始编写上述机制。首先,我实现了我的LLM可能用来回答我的问题的函数。作为概念验证,我只添加了两个函数,尽管实际上我们可能会有数十个。
``` This HTML snippet contains the translated text: "让我们开始编写上述机制。首先,我实现了我的LLM可能用来回答我的问题的函数。作为概念验证,我只添加了两个函数,尽管实际上我们可能会有数十个。"tools = {
'convert_time': 'A function to convert a time string with format H:MM:SS to seconds, args: {"time": {"type": "string"}}',
'arxiv_search': 'A function to get information about a scientific article or articles, args: {"query": {"type": "string"}, "id": {"type": "string"}}'
}
def arxiv_search(args):
# Construct the default API client.
client = arxiv.Client()
# Search for the paper with ID
search_by_id = arxiv.Search(query=args['query'],
id_list=[args['id']])
# Reuse client to fetch the paper, then print its title.
first_result = next(client.results(search_by_id))
return first_result.title
def convert_time(args):
temp = args['time'].split(':')
return int(temp[0])*3600 + int(temp[1])*60 + int(temp[2])
Sure, here's the translated text in simplified Chinese while keeping the HTML structure: ```html 我们的提示介绍了工具中可用的工具,规定了思考-行动-观察的推理格式和最终答案的回答格式。agent_scratchpad 是一个变量,用于存储LLM生成的所有先前推理步骤,作为下一步使用的参考(即内部记忆)。 ``` This translation maintains the structure and content while converting the text into simplified Chinese.
system_prompt = """
Answer the following questions as best you can. You have access to the
following tools:
{tools}
ALWAYS use the following format:
Question: the input question you must answer
Thought: you should always think about what to do. only one action at a time.
Action: the action to take, should be one of {tool_names}
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you
provide a definitive answer.
Question: {input}
Thought:{agent_scratchpad}
"""
Sure, here's the translated text in simplified Chinese while keeping the HTML structure: ```html 当LLM请求调用辅助工具时,我们通过观察「观察:字符串」来理解它。因此,这成为我们的停止准则。这隐含着LLM正在等待使用动作输入调用的结果。我们持续这个循环,直到LLM生成「最终答案:字符串」为止。 ``` This translation maintains the original structure and conveys the meaning accurately in simplified Chinese.
agent_scratchpad = ''
def ask(question):
global agent_scratchpad
# convert function description into suitable string for prompt
tools_str = ''
for func, desc in tools.items():
tools_str += f"{func} : {desc}\n"
# put current values of the variables into prompt string
prompt_after_formatting = system_prompt.format(input=question,
agent_scratchpad=agent_scratchpad,
tools=tools_str,
tool_names=list(tools.keys()))
print(prompt_after_formatting)
# make API call for answering question
# stop generation when see Observation:
# as it signs that we need a call a function externally
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt_after_formatting}
],
stop=["Observation:"]
)
# processing open ai's response
output = completion.choices[0].message.content
print(output)
# keep reasoning until see Final Answer: string
while output.find("Final Answer: ")==-1:
# append previous reasoning step
agent_scratchpad += output
# parse LLM output string into function and its arguments
function_name = output.split("Action: ")[1].split('\n')[0]
function_args = ast.literal_eval(output.split("Action Input: ")[1].split('\n')[0])
# call function externally
result = globals()[function_name](function_args)
# append function output to logs
agent_scratchpad += f"Observation: {result}\n"
print(f"Observation: {result}\n")
# put current values of the variables into prompt string
prompt_after_formatting = system_prompt.format(input=question,
agent_scratchpad=agent_scratchpad,
tools=tools_str,
tool_names=list(tools.keys()))
# make the next API call, this time with the result of
# previously requested function by LLM
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt_after_formatting}
],
stop=["Observation:"]
)
# processing open ai's response
output = completion.choices[0].message.content
print(output)
return output
Sure, here's the translated text in simplified Chinese while keeping the HTML structure: ```html 让我们看看它的实际表现。这是向我们的代理提出的一个两步问题。请注意,它没有偏离所需的格式,并且在其过去的行动基础上保持了正确的推理。 ```
ask("how many seconds in 4:00:01. What's the paper 2311.01606 about?")
Answer the following questions as best you can. You have access to the following tools:
convert_time : A function to convert a time string with format H:MM:SS to seconds, args: {"time": {"type": "string"}}
arxiv_search : A function to get information about a scientific article or articles, args: {"query": {"type": "string"}, "id": {"type": "string"}}
ALWAYS use the following format:
Question: the input question you must answer
Thought: you should always think about what to do. only one action at a time.
Action: the action to take, should be one of ['convert_time', 'arxiv_search']
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer.
Question: First answer how many seconds in 4:00:01. Then answer What's the paper 2311.01606 about?
Thought:
I need to convert the time 4:00:01 to seconds first before searching for the paper.
Action: convert_time
Action Input: {"time": "4:00:01"}
Observation: 14401
Action: arxiv_search
Action Input: {"query": "", "id": "2311.01606"}
Observation: KG-FRUS: a Novel Graph-based Dataset of 127 Years of US Diplomatic Relations
Final Answer: 14401 seconds. The paper 2311.01606 is about "KG-FRUS: a Novel Graph-based Dataset of 127 Years of US Diplomatic Relations".
To translate "Conclusion" into simplified Chinese while keeping the HTML structure intact, you would write:
```html
结论
```
In this translation:
- `` and ` ` are HTML tags indicating the beginning and end of the translated text.
- "结论" is the simplified Chinese translation of "Conclusion".
Certainly! Here is the text translated into simplified Chinese while keeping the HTML structure: ```html
引导工程是我们如何玩弄LLM输入输出的方式。它提升了LLM的效果,为日益智能的产品提供了空间。一旦理解了基本原理,实施各种引导工程方法并不难。
``` This HTML snippet contains the translated text: **引导工程**是我们如何玩弄LLM输入输出的方式。它提升了LLM的效果,为日益智能的产品提供了空间。一旦理解了基本原理,实施各种**引导工程**方法并不难。Sure, here's the text translated into simplified Chinese, while keeping the HTML structure intact: ```html
希望您喜欢阅读。您可以通过Linkedin联系我,讨论更多内容。下次,我将发布内容,证明RAG有多简单!
``` This HTML snippet maintains the original text's meaning while presenting it in simplified Chinese.