diff --git a/metagpt/provider/base_llm.py b/metagpt/provider/base_llm.py index 4d00adbc7..52dd96b1a 100644 --- a/metagpt/provider/base_llm.py +++ b/metagpt/provider/base_llm.py @@ -43,7 +43,7 @@ class BaseLLM(ABC): if system_msgs: message = self._system_msgs(system_msgs) else: - message = [self._default_system_msg()] + message = [self._default_system_msg()] if self.use_system_prompt else [] if format_msgs: message.extend(format_msgs) message.append(self._user_msg(msg)) diff --git a/metagpt/provider/fireworks_api.py b/metagpt/provider/fireworks_api.py index 638b0703d..f0af68818 100644 --- a/metagpt/provider/fireworks_api.py +++ b/metagpt/provider/fireworks_api.py @@ -64,8 +64,9 @@ class FireworksCostManager(CostManager): token_costs = self.model_grade_token_costs(model) cost = (prompt_tokens * token_costs["prompt"] + completion_tokens * token_costs["completion"]) / 1000000 self.total_cost += cost + max_budget = CONFIG.max_budget if CONFIG.max_budget else CONFIG.cost_manager.max_budget logger.info( - f"Total running cost: ${self.total_cost:.4f} | Max budget: ${CONFIG.max_budget:.3f} | " + f"Total running cost: ${self.total_cost:.4f} | Max budget: ${max_budget:.3f} | " f"Current cost: ${cost:.4f}, prompt_tokens: {prompt_tokens}, completion_tokens: {completion_tokens}" ) CONFIG.total_cost = self.total_cost diff --git a/metagpt/provider/ollama_api.py b/metagpt/provider/ollama_api.py index 95b944bf3..8ee04de7d 100644 --- a/metagpt/provider/ollama_api.py +++ b/metagpt/provider/ollama_api.py @@ -30,9 +30,9 @@ class OllamaCostManager(CostManager): """ self.total_prompt_tokens += prompt_tokens self.total_completion_tokens += completion_tokens - + max_budget = CONFIG.max_budget if CONFIG.max_budget else CONFIG.cost_manager.max_budget logger.info( - f"Max budget: ${CONFIG.max_budget:.3f} | " + f"Max budget: ${max_budget:.3f} | " f"prompt_tokens: {prompt_tokens}, completion_tokens: {completion_tokens}" ) CONFIG.total_cost = self.total_cost diff --git a/metagpt/provider/open_llm_api.py b/metagpt/provider/open_llm_api.py index 7f5870702..b0c484f5a 100644 --- a/metagpt/provider/open_llm_api.py +++ b/metagpt/provider/open_llm_api.py @@ -26,9 +26,9 @@ class OpenLLMCostManager(CostManager): """ self.total_prompt_tokens += prompt_tokens self.total_completion_tokens += completion_tokens - + max_budget = CONFIG.max_budget if CONFIG.max_budget else CONFIG.cost_manager.max_budget logger.info( - f"Max budget: ${CONFIG.max_budget:.3f} | reference " + f"Max budget: ${max_budget:.3f} | reference " f"prompt_tokens: {prompt_tokens}, completion_tokens: {completion_tokens}" ) diff --git a/metagpt/provider/zhipuai/zhipu_model_api.py b/metagpt/provider/zhipuai/zhipu_model_api.py index 72be0f333..c2c1bd3d8 100644 --- a/metagpt/provider/zhipuai/zhipu_model_api.py +++ b/metagpt/provider/zhipuai/zhipu_model_api.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # @Desc : zhipu model api to support sync & async for invoke & sse_invoke +import json import zhipuai from zhipuai.model_api.api import InvokeType, ModelAPI from zhipuai.utils.http_client import headers as zhipuai_default_headers @@ -51,7 +52,6 @@ class ZhiPuModelAPI(ModelAPI): params=kwargs, request_timeout=zhipuai.api_timeout_seconds, ) - return result @classmethod @@ -61,6 +61,8 @@ class ZhiPuModelAPI(ModelAPI): resp = await cls.arequest( invoke_type=InvokeType.SYNC, stream=False, method="post", headers=headers, kwargs=kwargs ) + resp = resp.decode("utf-8") + resp = json.loads(resp) return resp @classmethod diff --git a/metagpt/provider/zhipuai_api.py b/metagpt/provider/zhipuai_api.py index addbe58af..865b7fce1 100644 --- a/metagpt/provider/zhipuai_api.py +++ b/metagpt/provider/zhipuai_api.py @@ -38,12 +38,11 @@ class ZhiPuAILLM(BaseLLM): From now, there is only one model named `chatglm_turbo` """ - use_system_prompt: bool = False # zhipuai has no system prompt when use api - def __init__(self): self.__init_zhipuai(CONFIG) self.llm = ZhiPuModelAPI self.model = "chatglm_turbo" # so far only one model, just use it + self.use_system_prompt: bool = False # zhipuai has no system prompt when use api def __init_zhipuai(self, config: CONFIG): assert config.zhipuai_api_key @@ -101,7 +100,6 @@ class ZhiPuAILLM(BaseLLM): elif event.event == ZhiPuEvent.ERROR.value or event.event == ZhiPuEvent.INTERRUPTED.value: content = event.data logger.error(f"event error: {content}", end="") - collected_content.append([content]) elif event.event == ZhiPuEvent.FINISH.value: """ event.meta