mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-09 07:42:38 +02:00
添加一个代码
This commit is contained in:
commit
552547e662
58 changed files with 632 additions and 327 deletions
|
|
@ -1,11 +1,10 @@
|
|||
你是一个富有帮助的助理,可以帮助撰写、抽象、注释、摘要Python代码
|
||||
You are a helpful assistant that can assist in writing, abstracting, annotating, and summarizing Python code.
|
||||
|
||||
1. 不要提到类/函数名
|
||||
2. 不要提到除了系统库与公共库以外的类/函数
|
||||
3. 试着将类/函数总结为不超过6句话
|
||||
4. 你的回答应该是一行文本
|
||||
|
||||
举例,如果上下文是:
|
||||
Do not mention class/function names.
|
||||
Do not mention any class/function other than system and public libraries.
|
||||
Try to summarize the class/function in no more than 6 sentences.
|
||||
Your answer should be in one line of text.
|
||||
For instance, if the context is:
|
||||
|
||||
```python
|
||||
from typing import Optional
|
||||
|
|
@ -21,38 +20,38 @@
|
|||
self.desc = ""
|
||||
|
||||
def set_prefix(self, prefix):
|
||||
"""设置前缀以供后续使用"""
|
||||
"""Set prefix for subsequent use"""
|
||||
self.prefix = prefix
|
||||
|
||||
async def _aask(self, prompt: str, system_msgs: Optional[list[str]] = None):
|
||||
"""加上默认的prefix来使用prompt"""
|
||||
"""Use prompt with the default prefix"""
|
||||
if not system_msgs:
|
||||
system_msgs = []
|
||||
system_msgs.append(self.prefix)
|
||||
return await self.llm.aask(prompt, system_msgs)
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
"""运行动作"""
|
||||
"""Execute action"""
|
||||
raise NotImplementedError("The run method should be implemented in a subclass.")
|
||||
|
||||
PROMPT_TEMPLATE = """
|
||||
# 需求
|
||||
# Requirements
|
||||
{requirements}
|
||||
|
||||
# PRD
|
||||
根据需求创建一个产品需求文档(PRD),填补以下空缺
|
||||
Create a product requirement document (PRD) based on the requirements and fill in the blanks below:
|
||||
|
||||
产品/功能介绍:
|
||||
Product/Function Introduction:
|
||||
|
||||
目标:
|
||||
Goals:
|
||||
|
||||
用户和使用场景:
|
||||
Users and Usage Scenarios:
|
||||
|
||||
需求:
|
||||
Requirements:
|
||||
|
||||
约束与限制:
|
||||
Constraints and Limitations:
|
||||
|
||||
性能指标:
|
||||
Performance Metrics:
|
||||
|
||||
"""
|
||||
|
||||
|
|
@ -68,9 +67,8 @@ # PRD
|
|||
```
|
||||
|
||||
|
||||
主类/函数是 `WritePRD`。
|
||||
The main class/function is WritePRD.
|
||||
|
||||
那么你应该写:
|
||||
|
||||
这个类用来根据输入需求生成PRD。首先注意到有一个提示词模板,其中有产品、功能、目标、用户和使用场景、需求、约束与限制、性能指标,这个模板会以输入需求填充,然后调用接口询问大语言模型,让大语言模型返回具体的PRD。
|
||||
Then you should write:
|
||||
|
||||
This class is designed to generate a PRD based on input requirements. Notably, there's a template prompt with sections for product, function, goals, user scenarios, requirements, constraints, performance metrics. This template gets filled with input requirements and then queries a big language model to produce the detailed PRD.
|
||||
|
|
@ -7,34 +7,34 @@
|
|||
"""
|
||||
|
||||
METAGPT_SAMPLE = """
|
||||
### 设定
|
||||
### Settings
|
||||
|
||||
你是一个用户的编程助手,可以使用公共库与python系统库进行编程,你的回复应该有且只有一个函数。
|
||||
1. 函数本身应尽可能完整,不应缺失需求细节
|
||||
2. 你可能需要写一些提示词,用来让LLM(你自己)理解带有上下文的搜索请求
|
||||
3. 面对复杂的、难以用简单函数解决的逻辑,尽量交给llm解决
|
||||
You are a programming assistant for a user, capable of coding using public libraries and Python system libraries. Your response should have only one function.
|
||||
1. The function should be as complete as possible, not missing any details of the requirements.
|
||||
2. You might need to write some prompt words to let LLM (yourself) understand context-bearing search requests.
|
||||
3. For complex logic that can't be easily resolved with a simple function, try to let the llm handle it.
|
||||
|
||||
### 公共库
|
||||
### Public Libraries
|
||||
|
||||
你可以使用公共库metagpt提供的函数,不能使用其他第三方库的函数。公共库默认已经被import为x变量
|
||||
You can use the functions provided by the public library metagpt, but can't use functions from other third-party libraries. The public library is imported as variable x by default.
|
||||
- `import metagpt as x`
|
||||
- 你可以使用 `x.func(paras)` 方式来对公共库进行调用。
|
||||
- You can call the public library using the `x.func(paras)` format.
|
||||
|
||||
公共库中已有函数如下
|
||||
- def llm(question: str) -> str # 输入问题,基于大模型进行回答
|
||||
- def intent_detection(query: str) -> str # 输入query,分析意图,返回公共库函数名
|
||||
- def add_doc(doc_path: str) -> None # 输入文件路径或者文件夹路径,加入知识库
|
||||
- def search(query: str) -> list[str] # 输入query返回向量知识库搜索的多个结果
|
||||
- def google(query: str) -> list[str] # 使用google查询公网结果
|
||||
- def math(query: str) -> str # 输入query公式,返回对公式执行的结果
|
||||
- def tts(text: str, wav_path: str) # 输入text文本与对应想要输出音频的路径,将文本转为音频文件
|
||||
Functions already available in the public library are:
|
||||
- def llm(question: str) -> str # Input a question and get an answer based on the large model.
|
||||
- def intent_detection(query: str) -> str # Input query, analyze the intent, and return the function name from the public library.
|
||||
- def add_doc(doc_path: str) -> None # Input the path to a file or folder and add it to the knowledge base.
|
||||
- def search(query: str) -> list[str] # Input a query and return multiple results from a vector-based knowledge base search.
|
||||
- def google(query: str) -> list[str] # Use Google to search for public results.
|
||||
- def math(query: str) -> str # Input a query formula and get the result of the formula execution.
|
||||
- def tts(text: str, wav_path: str) # Input text and the path to the desired output audio, converting the text to an audio file.
|
||||
|
||||
### 用户需求
|
||||
### User Requirements
|
||||
|
||||
我有一个个人知识库文件,我希望基于它来实现一个带有搜索功能的个人助手,需求细则如下
|
||||
1. 个人助手会思考是否需要使用个人知识库搜索,如果没有必要,就不使用它
|
||||
2. 个人助手会判断用户意图,在不同意图下使用恰当的函数解决问题
|
||||
3. 用语音回答
|
||||
I have a personal knowledge base file. I hope to implement a personal assistant with a search function based on it. The detailed requirements are as follows:
|
||||
1. The personal assistant will consider whether to use the personal knowledge base for searching. If it's unnecessary, it won't use it.
|
||||
2. The personal assistant will judge the user's intent and use the appropriate function to address the issue based on different intents.
|
||||
3. Answer in voice.
|
||||
|
||||
"""
|
||||
# - def summarize(doc: str) -> str # 输入doc返回摘要
|
||||
# - def summarize(doc: str) -> str # Input doc and return a summary.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@
|
|||
@File : summarize.py
|
||||
"""
|
||||
|
||||
|
||||
# 出自插件:ChatGPT - 网站和 YouTube 视频摘要
|
||||
# https://chrome.google.com/webstore/detail/chatgpt-%C2%BB-summarize-every/cbgecfllfhmmnknmamkejadjmnmpfjmp?hl=zh-CN&utm_source=chrome-ntp-launcher
|
||||
# From the plugin: ChatGPT - Website and YouTube Video Summaries
|
||||
# https://chrome.google.com/webstore/detail/chatgpt-%C2%BB-summarize-every/cbgecfllfhmmnknmamkejadjmnmpfjmp?hl=en&utm_source=chrome-ntp-launcher
|
||||
SUMMARIZE_PROMPT = """
|
||||
Your output should use the following template:
|
||||
### Summary
|
||||
|
|
@ -22,9 +21,9 @@ a YouTube video, use the following text: {{CONTENT}}.
|
|||
"""
|
||||
|
||||
|
||||
# GCP-VertexAI-文本摘要(SUMMARIZE_PROMPT_2-5都是)
|
||||
# GCP-VertexAI-Text Summarization (SUMMARIZE_PROMPT_2-5 are from this source)
|
||||
# https://github.com/GoogleCloudPlatform/generative-ai/blob/main/language/examples/prompt-design/text_summarization.ipynb
|
||||
# 长文档需要map-reduce过程,见下面这个notebook
|
||||
# Long documents require a map-reduce process, see the following notebook
|
||||
# https://github.com/GoogleCloudPlatform/generative-ai/blob/main/language/examples/document-summarization/summarization_large_documents.ipynb
|
||||
SUMMARIZE_PROMPT_2 = """
|
||||
Provide a very short summary, no more than three sentences, for the following article:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue