Spaces:
Running
Running
File size: 3,309 Bytes
3be03dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 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", "")
|