Spaces:
Sleeping
Sleeping
| import os | |
| from dotenv import load_dotenv | |
| from config.models import Groq, Gemini, Ollama | |
| load_dotenv() | |
| LLM_CONFIG = os.getenv("LLM_CONFIG", "local") | |
| def get_model_client(task: str = "analysis"): | |
| if LLM_CONFIG == "local": | |
| return _local_client() | |
| if LLM_CONFIG =="cloud": | |
| return _cheap_client() if task == "data" else _analysis_client() | |
| return _local_client() if task == "data" else _analysis_client() | |
| def _local_client(): | |
| from autogen_ext.models.openai import OpenAIChatCompletionClient | |
| return OpenAIChatCompletionClient( | |
| model = os.getenv("LOCAL_MODEL", Ollama.DEFAULT), | |
| base_url = os.getenv("LOCAL_BASE_URL", Ollama.BASE_URL), | |
| api_key = "ollama", | |
| model_capabilities = { | |
| "vision": False, | |
| "function_calling": False, | |
| "json_output": True, | |
| }, | |
| ) | |
| def _analysis_client(): | |
| groq_key = os.getenv("GROQ_API_KEY", "") | |
| if groq_key: | |
| from autogen_ext.models.openai import OpenAIChatCompletionClient | |
| return OpenAIChatCompletionClient( | |
| model = os.getenv("ANALYSIS_MODEL", Groq.ANALYSIS), | |
| base_url = Groq.BASE_URL, | |
| api_key = groq_key, | |
| model_capabilities={ | |
| "vision": False, | |
| "function_calling": True, | |
| "json_output": True, | |
| }, | |
| ) | |
| google_key = os.getenv("GOOGLE_API_KEY", "") | |
| if google_key: | |
| from autogen_ext.models.openai import OpenAIChatCompletionClient | |
| return OpenAIChatCompletionClient( | |
| model = os.getenv("ANALYSIS_MODEL", Gemini.ANALYSIS), | |
| base_url = Gemini.BASE_URL, | |
| api_key = google_key, | |
| model_capabilities={ | |
| "vision": False, | |
| "function_calling": True, | |
| "json_output": True, | |
| }, | |
| ) | |
| raise RuntimeError( | |
| "No LLM key available. Set GROQ_API_KEY or GOOGLE_API_KEY." | |
| ) | |
| def _cheap_client(): | |
| groq_key = os.getenv("GROQ_API_KEY", "") | |
| if groq_key: | |
| from autogen_ext.models.openai import OpenAIChatCompletionClient | |
| return OpenAIChatCompletionClient( | |
| model = os.getenv("DATA_MODEL", Groq.DATA), | |
| base_url = Groq.BASE_URL, | |
| api_key = groq_key, | |
| model_capabilities={ | |
| "vision": False, | |
| "function_calling": True, | |
| "json_output": True, | |
| }, | |
| ) | |
| google_key = os.getenv("GOOGLE_API_KEY", "") | |
| if google_key: | |
| from autogen_ext.models.openai import OpenAIChatCompletionClient | |
| return OpenAIChatCompletionClient( | |
| model = os.getenv("DATA_MODEL", Gemini.DATA), | |
| base_url = Gemini.BASE_URL, | |
| api_key = google_key, | |
| model_capabilities={ | |
| "vision": False, | |
| "function_calling": True, | |
| "json_output": True, | |
| }, | |
| ) | |
| raise RuntimeError( | |
| "No LLM key available. Set GROQ_API_KEY or GOOGLE_API_KEY." | |
| ) | |
| APP_ENV = os.getenv("APP_ENV", "development") | |
| ANALYSIS_TIMEOUT = int(os.getenv("ANALYSIS_TIMEOUT", "120")) | |
| MAX_CONCURRENT = int(os.getenv("MAX_CONCURRENT", "3")) | |
| NEWS_API_KEY = os.getenv("NEWS_API_KEY", "") | |