mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-23 15:48:11 +02:00
Merge branch 'dev' into code_intepreter
This commit is contained in:
commit
afb702c3f3
38 changed files with 537 additions and 366 deletions
|
|
@ -42,8 +42,8 @@ Determine the ONE file to rewrite in order to fix the error, for example, xyz.py
|
|||
Determine if all of the code works fine, if so write PASS, else FAIL,
|
||||
WRITE ONLY ONE WORD, PASS OR FAIL, IN THIS SECTION
|
||||
## Send To:
|
||||
Please write Engineer if the errors are due to problematic development codes, and QaEngineer to problematic test codes, and NoOne if there are no errors,
|
||||
WRITE ONLY ONE WORD, Engineer OR QaEngineer OR NoOne, IN THIS SECTION.
|
||||
Please write NoOne if there are no errors, Engineer if the errors are due to problematic development codes, else QaEngineer,
|
||||
WRITE ONLY ONE WORD, NoOne OR Engineer OR QaEngineer, IN THIS SECTION.
|
||||
---
|
||||
You should fill in necessary instruction, status, send to, and finally return all content between the --- segment line.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ Options:
|
|||
Default: 'google'
|
||||
|
||||
Example:
|
||||
python3 -m metagpt.actions.write_docstring ./metagpt/startup.py --overwrite False --style=numpy
|
||||
python3 -m metagpt.actions.write_docstring ./metagpt/software_company.py --overwrite False --style=numpy
|
||||
|
||||
This script uses the 'fire' library to create a command-line interface. It generates docstrings for the given Python code using
|
||||
the specified docstring style and adds them to the code.
|
||||
|
|
|
|||
|
|
@ -67,17 +67,16 @@ class Config(CLIParams, YamlModel):
|
|||
code_review_k_times: int = 2
|
||||
|
||||
# Will be removed in the future
|
||||
METAGPT_TEXT_TO_IMAGE_MODEL_URL: str = ""
|
||||
metagpt_tti_url: str = ""
|
||||
language: str = "English"
|
||||
redis_key: str = "placeholder"
|
||||
IFLYTEK_APP_ID: str = ""
|
||||
IFLYTEK_API_SECRET: str = ""
|
||||
IFLYTEK_API_KEY: str = ""
|
||||
AZURE_TTS_SUBSCRIPTION_KEY: str = ""
|
||||
AZURE_TTS_REGION: str = ""
|
||||
mermaid_engine: str = "nodejs"
|
||||
OPENAI_VISION_MODEL: str = "gpt-4-vision-preview"
|
||||
VISION_MAX_TOKENS: int = 4096
|
||||
iflytek_app_id: str = ""
|
||||
iflytek_api_secret: str = ""
|
||||
iflytek_api_key: str = ""
|
||||
azure_tts_subscription_key: str = ""
|
||||
azure_tts_region: str = ""
|
||||
openai_vision_model: str = "gpt-4-vision-preview"
|
||||
vision_max_tokens: int = 4096
|
||||
|
||||
@classmethod
|
||||
def from_home(cls, path):
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ async def text_to_image(text, size_type: str = "512x512", config: Config = metag
|
|||
"""
|
||||
image_declaration = "data:image/png;base64,"
|
||||
|
||||
model_url = config.METAGPT_TEXT_TO_IMAGE_MODEL_URL
|
||||
model_url = config.metagpt_tti_url
|
||||
if model_url:
|
||||
binary_data = await oas3_metagpt_text_to_image(text, size_type, model_url)
|
||||
elif config.get_openai_llm():
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ async def text_to_speech(
|
|||
|
||||
"""
|
||||
|
||||
subscription_key = config.AZURE_TTS_SUBSCRIPTION_KEY
|
||||
region = config.AZURE_TTS_REGION
|
||||
subscription_key = config.azure_tts_subscription_key
|
||||
region = config.azure_tts_region
|
||||
if subscription_key and region:
|
||||
audio_declaration = "data:audio/wav;base64,"
|
||||
base64_data = await oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
|
||||
|
|
@ -50,9 +50,9 @@ async def text_to_speech(
|
|||
return f"[{text}]({url})"
|
||||
return audio_declaration + base64_data if base64_data else base64_data
|
||||
|
||||
iflytek_app_id = config.IFLYTEK_APP_ID
|
||||
iflytek_api_key = config.IFLYTEK_API_KEY
|
||||
iflytek_api_secret = config.IFLYTEK_API_SECRET
|
||||
iflytek_app_id = config.iflytek_app_id
|
||||
iflytek_api_key = config.iflytek_api_key
|
||||
iflytek_api_secret = config.iflytek_api_secret
|
||||
if iflytek_app_id and iflytek_api_key and iflytek_api_secret:
|
||||
audio_declaration = "data:audio/mp3;base64,"
|
||||
base64_data = await oas3_iflytek_tts(
|
||||
|
|
@ -65,5 +65,5 @@ async def text_to_speech(
|
|||
return audio_declaration + base64_data if base64_data else base64_data
|
||||
|
||||
raise ValueError(
|
||||
"AZURE_TTS_SUBSCRIPTION_KEY, AZURE_TTS_REGION, IFLYTEK_APP_ID, IFLYTEK_API_KEY, IFLYTEK_API_SECRET error"
|
||||
"azure_tts_subscription_key, azure_tts_region, iflytek_app_id, iflytek_api_key, iflytek_api_secret error"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class BaseLLM(ABC):
|
|||
|
||||
def get_choice_delta_text(self, rsp: dict) -> str:
|
||||
"""Required to provide the first text of stream choice"""
|
||||
return rsp.get("choices")[0]["delta"]["content"]
|
||||
return rsp.get("choices", [{}])[0].get("delta", {}).get("content", "")
|
||||
|
||||
def get_choice_function(self, rsp: dict) -> dict:
|
||||
"""Required to provide the first function of choice
|
||||
|
|
|
|||
|
|
@ -17,17 +17,17 @@ app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
|
|||
|
||||
def generate_repo(
|
||||
idea,
|
||||
investment,
|
||||
n_round,
|
||||
code_review,
|
||||
run_tests,
|
||||
implement,
|
||||
project_name,
|
||||
inc,
|
||||
project_path,
|
||||
reqa_file,
|
||||
max_auto_summarize_code,
|
||||
recover_path,
|
||||
investment=3.0,
|
||||
n_round=5,
|
||||
code_review=True,
|
||||
run_tests=False,
|
||||
implement=True,
|
||||
project_name="",
|
||||
inc=False,
|
||||
project_path="",
|
||||
reqa_file="",
|
||||
max_auto_summarize_code=0,
|
||||
recover_path=None,
|
||||
) -> ProjectRepo:
|
||||
"""Run the startup logic. Can be called from CLI or other Python scripts."""
|
||||
from metagpt.roles import (
|
||||
|
|
@ -35,14 +35,10 @@ class GPTvGenerator:
|
|||
def __init__(self):
|
||||
from metagpt.config2 import config
|
||||
|
||||
OPENAI_API_BASE = config.llm.base_url
|
||||
API_KEY = config.llm.api_key
|
||||
MODEL = config.OPENAI_VISION_MODEL
|
||||
MAX_TOKENS = config.VISION_MAX_TOKENS
|
||||
self.api_key = API_KEY
|
||||
self.api_base = OPENAI_API_BASE
|
||||
self.model = MODEL
|
||||
self.max_tokens = MAX_TOKENS
|
||||
self.api_key = config.llm.api_key
|
||||
self.api_base = config.llm.base_url
|
||||
self.model = config.openai_vision_model
|
||||
self.max_tokens = config.vision_max_tokens
|
||||
|
||||
def analyze_layout(self, image_path):
|
||||
return self.get_result(image_path, ANALYZE_LAYOUT_PROMPT)
|
||||
|
|
|
|||
|
|
@ -99,6 +99,13 @@ class ProjectRepo(FileRepository):
|
|||
self.tests = self._git_repo.new_file_repository(relative_path=TEST_CODES_FILE_REPO)
|
||||
self.test_outputs = self._git_repo.new_file_repository(relative_path=TEST_OUTPUTS_FILE_REPO)
|
||||
self._srcs_path = None
|
||||
self.code_files_exists()
|
||||
|
||||
def __str__(self):
|
||||
repo_str = f"ProjectRepo({self._git_repo.workdir})"
|
||||
docs_str = f"Docs({self.docs.all_files})"
|
||||
srcs_str = f"Srcs({self.srcs.all_files})"
|
||||
return f"{repo_str}\n{docs_str}\n{srcs_str}"
|
||||
|
||||
@property
|
||||
async def requirement(self):
|
||||
|
|
|
|||
|
|
@ -119,15 +119,22 @@ def repair_json_format(output: str) -> str:
|
|||
logger.info(f"repair_json_format: {'}]'}")
|
||||
elif output.startswith("{") and output.endswith("]"):
|
||||
output = output[:-1] + "}"
|
||||
|
||||
# remove `#` in output json str, usually appeared in `glm-4`
|
||||
# remove comments in output json string, after json value content, maybe start with #, maybe start with //
|
||||
arr = output.split("\n")
|
||||
new_arr = []
|
||||
for line in arr:
|
||||
idx = line.find("#")
|
||||
if idx >= 0:
|
||||
line = line[:idx]
|
||||
new_arr.append(line)
|
||||
for json_line in arr:
|
||||
# look for # or // comments and make sure they are not inside the string value
|
||||
comment_index = -1
|
||||
for match in re.finditer(r"(\".*?\"|\'.*?\')|(#|//)", json_line):
|
||||
if match.group(1): # if the string value
|
||||
continue
|
||||
if match.group(2): # if comments
|
||||
comment_index = match.start(2)
|
||||
break
|
||||
# if comments, then delete them
|
||||
if comment_index != -1:
|
||||
json_line = json_line[:comment_index].rstrip()
|
||||
new_arr.append(json_line)
|
||||
output = "\n".join(new_arr)
|
||||
return output
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue