diff --git a/metagpt/config.py b/metagpt/config.py index 6ab537296..27d4488e0 100644 --- a/metagpt/config.py +++ b/metagpt/config.py @@ -79,7 +79,7 @@ class Config(metaclass=Singleton): (self.gemini_api_key, LLMProviderEnum.GEMINI), # reuse logic. but not a key ]: if self._is_valid_llm_key(k): - if self.openai_api_model: + if self.openai_api_key and self.openai_api_model: logger.info(f"OpenAI API Model: {self.openai_api_model}") return v raise NotConfiguredException("You should config a LLM configuration first") diff --git a/metagpt/provider/__init__.py b/metagpt/provider/__init__.py index 56dc19b4b..028c6f837 100644 --- a/metagpt/provider/__init__.py +++ b/metagpt/provider/__init__.py @@ -6,7 +6,16 @@ @File : __init__.py """ +from metagpt.provider.fireworks_api import FireWorksGPTAPI +from metagpt.provider.google_gemini_api import GeminiGPTAPI +from metagpt.provider.open_llm_api import OpenLLMGPTAPI from metagpt.provider.openai_api import OpenAIGPTAPI +from metagpt.provider.zhipuai_api import ZhiPuAIGPTAPI - -__all__ = ["OpenAIGPTAPI"] +__all__ = [ + "FireWorksGPTAPI", + "GeminiGPTAPI", + "OpenLLMGPTAPI", + "OpenAIGPTAPI", + "ZhiPuAIGPTAPI" +] diff --git a/metagpt/provider/google_gemini_api.py b/metagpt/provider/google_gemini_api.py index b68e013a0..213b53263 100644 --- a/metagpt/provider/google_gemini_api.py +++ b/metagpt/provider/google_gemini_api.py @@ -2,6 +2,12 @@ # -*- coding: utf-8 -*- # @Desc : Google Gemini LLM from https://ai.google.dev/tutorials/python_quickstart +import google.generativeai as genai +from google.ai import generativelanguage as glm +from google.generativeai.generative_models import GenerativeModel +from google.generativeai.types import content_types +from google.generativeai.types.generation_types import GenerateContentResponse, AsyncGenerateContentResponse +from google.generativeai.types.generation_types import GenerationConfig from tenacity import ( after_log, retry, @@ -9,16 +15,11 @@ from tenacity import ( stop_after_attempt, wait_random_exponential, ) -import google.generativeai as genai -from google.ai import generativelanguage as glm -from google.generativeai.types import content_types -from google.generativeai.generative_models import GenerativeModel -from google.generativeai.types.generation_types import GenerateContentResponse, AsyncGenerateContentResponse -from google.generativeai.types.generation_types import GenerationConfig -from metagpt.config import CONFIG +from metagpt.config import CONFIG, LLMProviderEnum from metagpt.logs import logger from metagpt.provider.base_gpt_api import BaseGPTAPI +from metagpt.provider.llm_provider_registry import register_provider from metagpt.provider.openai_api import CostManager, log_and_reraise @@ -29,18 +30,19 @@ class GeminiGenerativeModel(GenerativeModel): """ def count_tokens( - self, contents: content_types.ContentsType + self, contents: content_types.ContentsType ) -> glm.CountTokensResponse: contents = content_types.to_contents(contents) return self._client.count_tokens(model=self.model_name, contents=contents) async def count_tokens_async( - self, contents: content_types.ContentsType + self, contents: content_types.ContentsType ) -> glm.CountTokensResponse: contents = content_types.to_contents(contents) return await self._async_client.count_tokens(model=self.model_name, contents=contents) +@register_provider(LLMProviderEnum.GEMINI) class GeminiGPTAPI(BaseGPTAPI): """ Refs to `https://ai.google.dev/tutorials/python_quickstart`