Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Merge branch 'geekan:main' into main

brucemeeka0e6d2003449
diff --cc metagpt/actions/write_test.py
index 944d02192,5e50fdb55..ddf65c373
--- a/metagpt/actions/write_test.py
+++ b/metagpt/actions/write_test.py
@@@ -1,11 -1,10 +1,10 @@@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
-@Time : 2023/5/11 17:45
+@Time : 2023/5/11 22:12
@Author : alexanderwu
-@File : write_test.py
+@File : environment.py
"""
- from metagpt.logs import logger
from metagpt.actions.action import Action
from metagpt.utils.common import CodeParser
diff --cc metagpt/document_store/base_store.py
index 27b5d94e0,3dc96c0d6..5d7015e8b
--- a/metagpt/document_store/base_store.py
+++ b/metagpt/document_store/base_store.py
@@@ -12,10 -12,10 +12,10 @@@ from metagpt.config import Confi
class BaseStore(ABC):
- """FIXME: consider add_index, set_index and think 颗粒度"""
+ """FIXME: consider add_index, set_index and think about granularity."""
@abstractmethod
- def search(self, query, *args, **kwargs):
+ def search(self, *args, **kwargs):
raise NotImplementedError
@abstractmethod
diff --cc metagpt/provider/openai_api.py
index 551810546,79121c8de..ff8943d3b
--- a/metagpt/provider/openai_api.py
+++ b/metagpt/provider/openai_api.py
@@@ -100,28 -102,29 +100,37 @@@ class CostManager(metaclass=Singleton)
"""
return self.total_completion_tokens
- def get_total_cost(self):
- """
- Get the total cost of API calls.
+def get_total_cost(self):
+ """
+ Get the total cost of API calls.
- Returns:
- float: The total cost of API calls.
- """
- return self.total_cost
+ Returns:
+ float: The total cost of API calls.
+ """
+ return self.total_cost
- def get_costs(self) -> Costs:
- """获得所有开销"""
- return Costs(self.total_prompt_tokens, self.total_completion_tokens, self.total_cost, self.total_budget)
+def get_costs(self) -> Costs:
+ """Get all costs"""
+ return Costs(self.total_prompt_tokens, self.total_completion_tokens, self.total_cost, self.total_budget)
+
+def log_and_reraise(retry_state):
+ logger.error(f"Retry attempts exhausted. Last exception: {retry_state.outcome.exception()}")
+ logger.warning("""
+Recommend going to https://deepwisdom.feishu.cn/wiki/MsGnwQBjiif9c3koSJNcYaoSnu4#part-XdatdVlhEojeAfxaaEZcMV3ZniQ
+See FAQ 5.8
+""")
+ raise retry_state.outcome.exception()
+ def log_and_reraise(retry_state):
+ logger.error(f"Retry attempts exhausted. Last exception: {retry_state.outcome.exception()}")
+ logger.warning("""
+ Recommend going to https://deepwisdom.feishu.cn/wiki/MsGnwQBjiif9c3koSJNcYaoSnu4#part-XdatdVlhEojeAfxaaEZcMV3ZniQ
+ See FAQ 5.8
+ """)
+ raise retry_state.outcome.exception()
+
+
class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
"""
Check https://platform.openai.com/examples for examples
@@@ -223,14 -226,19 +232,19 @@@
def _calc_usage(self, messages: list[dict], rsp: str) -> dict:
usage = {}
if CONFIG.calc_usage:
- prompt_tokens = count_message_tokens(messages, self.model)
- completion_tokens = count_string_tokens(rsp, self.model)
- usage['prompt_tokens'] = prompt_tokens
- usage['completion_tokens'] = completion_tokens
- return usage
+ try:
+ prompt_tokens = count_message_tokens(messages, self.model)
+ completion_tokens = count_string_tokens(rsp, self.model)
+ usage['prompt_tokens'] = prompt_tokens
+ usage['completion_tokens'] = completion_tokens
+ return usage
+ except Exception as e:
+ logger.error("usage calculation failed!", e)
+ else:
+ return usage
async def acompletion_batch(self, batch: list[list[dict]]) -> list[dict]:
- """返回完整JSON"""
+ """Return full JSON"""
split_batches = self.split_batches(batch)
all_results = []