remove global config

This commit is contained in:
shenchucheng 2024-08-13 22:34:12 +08:00
parent 6e0990f251
commit 2968c181c1
39 changed files with 193 additions and 123 deletions

View file

@ -8,7 +8,6 @@ from pathlib import Path
from typing import Any, Optional, Union
from metagpt.actions.action import Action
from metagpt.config2 import config
from metagpt.ext.stanford_town.utils.const import PROMPTS_DIR
from metagpt.logs import logger
@ -62,13 +61,13 @@ class STAction(Action):
async def _run_gpt35_max_tokens(self, prompt: str, max_tokens: int = 50, retry: int = 3):
for idx in range(retry):
try:
tmp_max_tokens_rsp = getattr(config.llm, "max_token", 1500)
setattr(config.llm, "max_token", max_tokens)
tmp_max_tokens_rsp = getattr(self.config.llm, "max_token", 1500)
setattr(self.config.llm, "max_token", max_tokens)
self.llm.use_system_prompt = False # to make it behave like a non-chat completions
llm_resp = await self._aask(prompt)
setattr(config.llm, "max_token", tmp_max_tokens_rsp)
setattr(self.config.llm, "max_token", tmp_max_tokens_rsp)
logger.info(f"Action: {self.cls_name} llm _run_gpt35_max_tokens raw resp: {llm_resp}")
if self._func_validate(llm_resp, prompt):
return self._func_cleanup(llm_resp, prompt)

View file

@ -13,7 +13,7 @@ from typing import Union
from openai import OpenAI
from metagpt.config2 import config
from metagpt.config2 import Config
from metagpt.logs import logger
@ -48,6 +48,7 @@ def read_csv_to_list(curr_file: str, header=False, strip_trail=True):
def get_embedding(text, model: str = "text-embedding-ada-002"):
config = Config.default()
text = text.replace("\n", " ")
if not text:
text = "this is blank"