add gemini minimal python version warning

This commit is contained in:
better629 2023-12-21 14:18:50 +08:00
parent f3eb9f638e
commit bdb427d5b7
3 changed files with 14 additions and 3 deletions

View file

@ -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

View file

@ -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)

View file

@ -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