🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
feat: replace CONFIG with OPTIONS
莘权 马3243078b77d1
diff --git a/metagpt/actions/talk_action.py b/metagpt/actions/talk_action.pyindex 5692cf4f4..555b202d1 100644--- a/metagpt/actions/talk_action.py+++ b/metagpt/actions/talk_action.py@@ -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_LANGUAGEfrom 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"] = talkcontext["history_summery"] = history_summarycontext["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 = talkself._history_summary = history_summaryself._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_LANGUAGEprompt += 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-diff --git a/metagpt/const.py b/metagpt/const.pyindex 20513461a..0e50f2c39 100644--- a/metagpt/const.py+++ b/metagpt/const.py@@ -38,3 +38,4 @@ RESEARCH_PATH = DATA_PATH / "research"MEM_TTL = 24 * 30 * 3600OPTIONS = contextvars.ContextVar("OPTIONS")+DEFAULT_LANGUAGE = "Engilish"\ No newline at end of filediff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.pyindex 02bf5126c..45e67739b 100644--- a/metagpt/provider/openai_api.py+++ b/metagpt/provider/openai_api.py@@ -19,6 +19,7 @@ from pydantic import BaseModelfrom tenacity import retry, stop_after_attempt, after_log, wait_fixed, retry_if_exception_typefrom metagpt.config import CONFIG+from metagpt.const import DEFAULT_LANGUAGEfrom metagpt.logs import loggerfrom metagpt.provider.base_gpt_api import BaseGPTAPIfrom 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_LANGUAGEcommand = f"Translate the above content into a {language} summary of less than {max_words} words."msg = text + "\n\n" + commandlogger.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_LANGUAGEcommand = 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"+