mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-02 20:32:38 +02:00
feat: replace CONFIG with OPTIONS
This commit is contained in:
parent
3a96405a69
commit
3243078b77
3 changed files with 19 additions and 8 deletions
|
|
@ -1,15 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/8/28
|
||||
@Author : mashenquan
|
||||
@File : talk_action.py
|
||||
@Desc : Act as it’s a talk
|
||||
"""
|
||||
|
||||
from metagpt.actions import Action, ActionOutput
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import DEFAULT_LANGUAGE
|
||||
from metagpt.logs import logger
|
||||
|
||||
|
||||
|
||||
class TalkAction(Action):
|
||||
def __init__(self, options, name: str = '', talk='', history_summary='', knowledge='', context=None, llm=None, **kwargs):
|
||||
def __init__(self, name: str = '', talk='', history_summary='', knowledge='', context=None, llm=None, **kwargs):
|
||||
context = context or {}
|
||||
context["talk"] = talk
|
||||
context["history_summery"] = history_summary
|
||||
context["knowledge"] = knowledge
|
||||
super(TalkAction, self).__init__(options=options, name=name, context=context, llm=llm)
|
||||
super(TalkAction, self).__init__(name=name, context=context, llm=llm)
|
||||
self._talk = talk
|
||||
self._history_summary = history_summary
|
||||
self._knowledge = knowledge
|
||||
|
|
@ -21,7 +31,7 @@ class TalkAction(Action):
|
|||
prompt += f"{self._history_summary}\n\n"
|
||||
if self._history_summary != "":
|
||||
prompt += "According to the historical conversation above, "
|
||||
language = self.options.get("language", "Chinese")
|
||||
language = CONFIG.language or DEFAULT_LANGUAGE
|
||||
prompt += f"Answer in {language}:\n {self._talk}"
|
||||
return prompt
|
||||
|
||||
|
|
@ -32,4 +42,3 @@ class TalkAction(Action):
|
|||
logger.info(rsp)
|
||||
self._rsp = ActionOutput(content=rsp)
|
||||
return self._rsp
|
||||
|
||||
|
|
|
|||
|
|
@ -38,3 +38,4 @@ RESEARCH_PATH = DATA_PATH / "research"
|
|||
MEM_TTL = 24 * 30 * 3600
|
||||
|
||||
OPTIONS = contextvars.ContextVar("OPTIONS")
|
||||
DEFAULT_LANGUAGE = "Engilish"
|
||||
|
|
@ -19,6 +19,7 @@ from pydantic import BaseModel
|
|||
from tenacity import retry, stop_after_attempt, after_log, wait_fixed, retry_if_exception_type
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.const import DEFAULT_LANGUAGE
|
||||
from metagpt.logs import logger
|
||||
from metagpt.provider.base_gpt_api import BaseGPTAPI
|
||||
from metagpt.utils.token_counter import (
|
||||
|
|
@ -291,7 +292,7 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
"""Generate text summary"""
|
||||
if len(text) < max_words:
|
||||
return text
|
||||
language = CONFIG.language or self.DEFAULT_LANGUAGE
|
||||
language = CONFIG.language or DEFAULT_LANGUAGE
|
||||
command = f"Translate the above content into a {language} summary of less than {max_words} words."
|
||||
msg = text + "\n\n" + command
|
||||
logger.info(f"summary ask:{msg}")
|
||||
|
|
@ -312,7 +313,7 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
if len(summaries) == 1:
|
||||
return summaries[0]
|
||||
|
||||
language = CONFIG.language or self.DEFAULT_LANGUAGE
|
||||
language = CONFIG.language or DEFAULT_LANGUAGE
|
||||
command = f"Translate the above summary into a {language} title of less than {max_words} words."
|
||||
summaries.append(command)
|
||||
msg = "\n".join(summaries)
|
||||
|
|
@ -398,4 +399,4 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
raise openai.error.OpenAIError("Exceeds the maximum retries")
|
||||
|
||||
MAX_TRY = 5
|
||||
DEFAULT_LANGUAGE = "Engilish"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue