mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-07 23:02:38 +02:00
修改内容:
调整llm引用模式 添加对星火大模型的支持 在模型报错时可以人工输入 可以通过config直接全人工输入
This commit is contained in:
parent
206bc252de
commit
6046f9c942
18 changed files with 277 additions and 29 deletions
|
|
@ -11,15 +11,16 @@ from typing import Optional
|
|||
from tenacity import retry, stop_after_attempt, wait_fixed
|
||||
|
||||
from metagpt.actions.action_output import ActionOutput
|
||||
from metagpt.llm import LLM
|
||||
import metagpt.llm as LLM
|
||||
from metagpt.utils.common import OutputParser
|
||||
from metagpt.logs import logger
|
||||
from metagpt.config import CONFIG
|
||||
|
||||
class Action(ABC):
|
||||
def __init__(self, name: str = '', context=None, llm: LLM = None):
|
||||
self.name: str = name
|
||||
if llm is None:
|
||||
llm = LLM()
|
||||
llm=LLM.DEFAULT_LLM
|
||||
self.llm = llm
|
||||
self.context = context
|
||||
self.prefix = ""
|
||||
|
|
@ -54,13 +55,42 @@ class Action(ABC):
|
|||
if not system_msgs:
|
||||
system_msgs = []
|
||||
system_msgs.append(self.prefix)
|
||||
content = await self.llm.aask(prompt, system_msgs)
|
||||
logger.debug(content)
|
||||
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
|
||||
parsed_data = OutputParser.parse_data_with_mapping(content, output_data_mapping)
|
||||
logger.debug(parsed_data)
|
||||
instruct_content = output_class(**parsed_data)
|
||||
return ActionOutput(content, instruct_content)
|
||||
if not CONFIG.no_api_mode:
|
||||
content = await self.llm.aask(prompt, system_msgs)
|
||||
logger.debug(content)
|
||||
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
|
||||
parsed_data = OutputParser.parse_data_with_mapping(content, output_data_mapping)
|
||||
logger.debug(parsed_data)
|
||||
try:
|
||||
instruct_content = output_class(**parsed_data)
|
||||
return ActionOutput(content, instruct_content)
|
||||
except Exception as e:
|
||||
print('Error:',e)
|
||||
print('自动运行出错,切换为手动运行')
|
||||
print('prompt为')
|
||||
print('\n'.join( system_msgs)+prompt)
|
||||
print('输入格式:')
|
||||
print(output_data_mapping)
|
||||
print('请准备输入,输入完成按ctrl+Z')
|
||||
while True:
|
||||
try:
|
||||
lines=[]
|
||||
while True:
|
||||
try:
|
||||
lines.append(input())
|
||||
except:
|
||||
break
|
||||
|
||||
content ='\n'.join(lines)
|
||||
output_class = ActionOutput.create_model_class(output_class_name, output_data_mapping)
|
||||
parsed_data = OutputParser.parse_data_with_mapping(content, output_data_mapping)
|
||||
logger.debug(parsed_data)
|
||||
instruct_content = output_class(**parsed_data)
|
||||
return ActionOutput(content, instruct_content)
|
||||
except Exception as e:
|
||||
print('Error:',e)
|
||||
print('输入错误,请重试')
|
||||
|
||||
|
||||
async def run(self, *args, **kwargs):
|
||||
"""Run action"""
|
||||
|
|
|
|||
|
|
@ -143,4 +143,5 @@ class WritePRD(Action):
|
|||
format_example=FORMAT_EXAMPLE)
|
||||
logger.debug(prompt)
|
||||
prd = await self._aask_v1(prompt, "prd", OUTPUT_MAPPING)
|
||||
|
||||
return prd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue