leofltt commited on
Commit
0d9fbce
·
1 Parent(s): db4e661

add more modes

Browse files
Files changed (2) hide show
  1. agent.py +36 -10
  2. requirements.txt +3 -1
agent.py CHANGED
@@ -20,7 +20,14 @@ import json
20
  from langchain_core.messages import SystemMessage
21
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
22
  from langchain_ollama import ChatOllama
 
 
23
  from langgraph.prebuilt import create_react_agent
 
 
 
 
 
24
 
25
  # (Keep Constants as is)
26
  # --- Constants -- -
@@ -292,16 +299,35 @@ class BasicAgent:
292
  space_id = os.getenv("SPACE_ID")
293
 
294
  if space_id:
295
- print("Detected Hugging Face Space environment. Initializing Qwen2.5-72B-Instruct via Inference Endpoint...")
296
- llm_engine = HuggingFaceEndpoint(
297
- repo_id="Qwen/Qwen2.5-72B-Instruct",
298
- huggingfacehub_api_token=hf_token,
299
- task="text-generation",
300
- max_new_tokens=2048,
301
- do_sample=False,
302
- timeout=300,
303
- )
304
- self.llm = ChatHuggingFace(llm=llm_engine)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  else:
306
  print("Detected local environment. Initializing local Ollama with Qwen3...")
307
  self.llm = ChatOllama(
 
20
  from langchain_core.messages import SystemMessage
21
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
22
  from langchain_ollama import ChatOllama
23
+ from langchain_google_genai import ChatGoogleGenerativeAI
24
+ from langchain_groq import ChatGroq
25
  from langgraph.prebuilt import create_react_agent
26
+ import warnings
27
+ from bs4 import GuessedAtParserWarning
28
+
29
+ # Suppress the specific BeautifulSoup warning from the wikipedia library
30
+ warnings.filterwarnings("ignore", category=GuessedAtParserWarning)
31
 
32
  # (Keep Constants as is)
33
  # --- Constants -- -
 
299
  space_id = os.getenv("SPACE_ID")
300
 
301
  if space_id:
302
+ print("Detected Hugging Face Space environment.")
303
+ google_api_key = os.getenv("GOOGLE_API_KEY")
304
+ groq_api_key = os.getenv("GROQ_API_KEY")
305
+
306
+ if google_api_key:
307
+ print("Initializing Gemini 1.5 Flash...")
308
+ self.llm = ChatGoogleGenerativeAI(
309
+ model="gemini-1.5-flash",
310
+ google_api_key=google_api_key,
311
+ temperature=0.0,
312
+ )
313
+ elif groq_api_key:
314
+ print("Initializing Llama-3-70b via Groq (Free Tier)...")
315
+ self.llm = ChatGroq(
316
+ model="llama3-70b-8192",
317
+ groq_api_key=groq_api_key,
318
+ temperature=0.0,
319
+ )
320
+ else:
321
+ print("Warning: No Gemini or Groq key found. Falling back to HF Endpoint...")
322
+ llm_engine = HuggingFaceEndpoint(
323
+ repo_id="Qwen/Qwen2.5-72B-Instruct",
324
+ huggingfacehub_api_token=hf_token,
325
+ task="text-generation",
326
+ max_new_tokens=2048,
327
+ do_sample=False,
328
+ timeout=300,
329
+ )
330
+ self.llm = ChatHuggingFace(llm=llm_engine)
331
  else:
332
  print("Detected local environment. Initializing local Ollama with Qwen3...")
333
  self.llm = ChatOllama(
requirements.txt CHANGED
@@ -26,4 +26,6 @@ torchvision
26
  av
27
  ffmpeg-python
28
  Pillow
29
- huggingface_hub
 
 
 
26
  av
27
  ffmpeg-python
28
  Pillow
29
+ huggingface_hub
30
+ langchain-google-genai
31
+ langchain-groq