🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
refine code
geekan244fa81ffe33
diff --git a/metagpt/provider/fireworks_api.py b/metagpt/provider/fireworks_api.pyindex 09581a2f3..8c0b268e6 100644--- a/metagpt/provider/fireworks_api.py+++ b/metagpt/provider/fireworks_api.py@@ -78,7 +78,7 @@ class FireworksLLM(OpenAILLM):self.cost_manager = FireworksCostManager()def _make_client_kwargs(self) -> dict:- kwargs = dict(api_key=self.config.fireworks_api_key, base_url=self.config.fireworks_api_base)+ kwargs = dict(api_key=self.config.api_key, base_url=self.config.base_url)return kwargsdef _update_costs(self, usage: CompletionUsage):diff --git a/metagpt/utils/yaml_model.py b/metagpt/utils/yaml_model.pyindex 162866609..60f866f7e 100644--- a/metagpt/utils/yaml_model.py+++ b/metagpt/utils/yaml_model.py@@ -17,6 +17,8 @@ class YamlModel(BaseModel):@classmethoddef read_yaml(cls, file_path: Path) -> Dict:+ if not file_path.exists():+ return {}with open(file_path, "r") as file:return yaml.safe_load(file)diff --git a/tests/metagpt/provider/mock_llm_config.py b/tests/metagpt/provider/mock_llm_config.pynew file mode 100644index 000000000..969ec2ab6--- /dev/null+++ b/tests/metagpt/provider/mock_llm_config.py@@ -0,0 +1,14 @@+#!/usr/bin/env python+# -*- coding: utf-8 -*-+"""+@Time : 2024/1/8 17:03+@Author : alexanderwu+@File : mock_llm_config.py+"""++from metagpt.configs.llm_config import LLMConfig++mock_llm_config = LLMConfig(+ llm_type="mock",+ api_key="mock_api_key",+)diff --git a/tests/metagpt/provider/test_anthropic_api.py b/tests/metagpt/provider/test_anthropic_api.pyindex 4410717a9..6962ab064 100644--- a/tests/metagpt/provider/test_anthropic_api.py+++ b/tests/metagpt/provider/test_anthropic_api.py@@ -6,10 +6,8 @@import pytestfrom anthropic.resources.completions import Completion-from metagpt.config import CONFIGfrom metagpt.provider.anthropic_api import Claude2--CONFIG.anthropic_api_key = "xxx"+from tests.metagpt.provider.mock_llm_config import mock_llm_configprompt = "who are you"resp = "I'am Claude2"@@ -25,10 +23,10 @@ async def mock_anthropic_acompletions_create(self, model: str, prompt: str, max_def test_claude2_ask(mocker):mocker.patch("anthropic.resources.completions.Completions.create", mock_anthropic_completions_create)- assert resp == Claude2().ask(prompt)+ assert resp == Claude2(mock_llm_config).ask(prompt)@pytest.mark.asyncioasync def test_claude2_aask(mocker):mocker.patch("anthropic.resources.completions.AsyncCompletions.create", mock_anthropic_acompletions_create)- assert resp == await Claude2().aask(prompt)+ assert resp == await Claude2(mock_llm_config).aask(prompt)diff --git a/tests/metagpt/provider/test_azure_openai_api.py b/tests/metagpt/provider/test_azure_llm.pysimilarity index 100%rename from tests/metagpt/provider/test_azure_openai_api.pyrename to tests/metagpt/provider/test_azure_llm.pydiff --git a/tests/metagpt/provider/test_base_gpt_api.py b/tests/metagpt/provider/test_base_llm.pysimilarity index 100%rename from tests/metagpt/provider/test_base_gpt_api.pyrename to tests/metagpt/provider/test_base_llm.pydiff --git a/tests/metagpt/provider/test_fireworks_api.py b/tests/metagpt/provider/test_fireworks_api.pyindex d48686eaa..66b55e5b2 100644--- a/tests/metagpt/provider/test_fireworks_api.py+++ b/tests/metagpt/provider/test_fireworks_api.py@@ -13,17 +13,13 @@ from openai.types.chat.chat_completion_chunk import Choice as AChoicefrom openai.types.chat.chat_completion_chunk import ChoiceDeltafrom openai.types.completion_usage import CompletionUsage-from metagpt.config import CONFIGfrom metagpt.provider.fireworks_api import (MODEL_GRADE_TOKEN_COSTS,FireworksCostManager,FireworksLLM,)from metagpt.utils.cost_manager import Costs--CONFIG.fireworks_api_key = "xxx"-CONFIG.max_budget = 10-CONFIG.calc_usage = True+from tests.metagpt.provider.mock_llm_config import mock_llm_configresp_content = "I'm fireworks"default_resp = ChatCompletion(@@ -92,7 +88,7 @@ async def mock_openai_acompletions_create(self, stream: bool = False, **kwargs)async def test_fireworks_acompletion(mocker):mocker.patch("openai.resources.chat.completions.AsyncCompletions.create", mock_openai_acompletions_create)- fireworks_gpt = FireworksLLM()+ fireworks_gpt = FireworksLLM(mock_llm_config)fireworks_gpt.model = "llama-v2-13b-chat"fireworks_gpt._update_costs(