diff --git a/metagpt/config.py b/metagpt/config.py index 27d4488e0..727b37b9c 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -7,6 +7,7 @@ Provide configuration, singleton 2. Add the parameter `src_workspace` for the old version project path. """ import os +import warnings from copy import deepcopy from enum import Enum from pathlib import Path @@ -17,6 +18,7 @@ import yaml from metagpt.const import DEFAULT_WORKSPACE_ROOT, METAGPT_ROOT, OPTIONS from metagpt.logs import logger from metagpt.tools import SearchEngineType, WebBrowserEngineType +from metagpt.utils.common import require_python_version from metagpt.utils.singleton import Singleton @@ -79,6 +81,9 @@ class Config(metaclass=Singleton): (self.gemini_api_key, LLMProviderEnum.GEMINI), # reuse logic. but not a key ]: if self._is_valid_llm_key(k): + logger.info(f"Use LLMProvider: {v.value}") + if v == LLMProviderEnum.GEMINI and not require_python_version(req_version=(3, 10)): + warnings.warn("Use Gemini requires Python >= 3.10") if self.openai_api_key and self.openai_api_model: logger.info(f"OpenAI API Model: {self.openai_api_model}") return v diff --git a/metagpt/provider/google_gemini_api.py b/metagpt/provider/google_gemini_api.py index 213b53263..10215e2d9 100644 --- a/metagpt/provider/google_gemini_api.py +++ b/metagpt/provider/google_gemini_api.py @@ -48,9 +48,8 @@ class GeminiGPTAPI(BaseGPTAPI): Refs to `https://ai.google.dev/tutorials/python_quickstart` """ - use_system_prompt: bool = False # google gemini has no system prompt when use api - def __init__(self): + self.use_system_prompt = False # google gemini has no system prompt when use api self.__init_gemini(CONFIG) self.model = "gemini-pro" # so far only one model self.llm = GeminiGenerativeModel(model_name=self.model) diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py index e5d4573e8..eec4176df 100644 --- a/metagpt/utils/common.py +++ b/metagpt/utils/common.py @@ -19,6 +19,7 @@ import json import os import platform import re +import sys import traceback import typing from pathlib import Path @@ -47,6 +48,12 @@ def check_cmd_exists(command) -> int: return result +def require_python_version(req_version: tuple[int]) -> bool: + if not (2 <= len(req_version) <= 3): + raise ValueError("req_version should be (3, 9) or (3, 10, 13)") + return True if sys.version_info > req_version else False + + class OutputParser: @classmethod def parse_blocks(cls, text: str): @@ -219,7 +226,7 @@ class OutputParser: if start_index != -1 and end_index != -1: # Extract the structure part - structure_text = text[start_index : end_index + 1] + structure_text = text[start_index: end_index + 1] try: # Attempt to convert the text to a Python data type using ast.literal_eval