Jose-Maria Segui commited on
Commit
c512d5c
·
1 Parent(s): 79c84f9

Switch to HuggingFace API (Groq rate limited)

Browse files
Files changed (1) hide show
  1. agent.py +16 -7
agent.py CHANGED
@@ -25,7 +25,7 @@ from langchain_community.tools import DuckDuckGoSearchRun
25
  from langchain_community.document_loaders import WikipediaLoader
26
  from langchain_community.document_loaders import ArxivLoader
27
  from langgraph.prebuilt import ToolNode, tools_condition
28
- from langchain_huggingface import HuggingFaceEmbeddings
29
  from langchain_groq import ChatGroq
30
  from langchain_community.vectorstores import SupabaseVectorStore
31
  from langchain_core.messages import SystemMessage, HumanMessage
@@ -741,12 +741,21 @@ tools = [
741
  def build_graph():
742
  """Build the graph"""
743
 
744
- # Use Groq (fast, reliable, free tier)
745
- # Model: qwen/qwen3-32b works well with LangChain tool calling
746
- llm = ChatGroq(
747
- model="qwen/qwen3-32b",
748
- temperature=0,
749
- api_key=os.environ.get("GROQ_API_KEY")
 
 
 
 
 
 
 
 
 
750
  )
751
 
752
  # Bind tools to LLM
 
25
  from langchain_community.document_loaders import WikipediaLoader
26
  from langchain_community.document_loaders import ArxivLoader
27
  from langgraph.prebuilt import ToolNode, tools_condition
28
+ from langchain_huggingface import HuggingFaceEmbeddings, ChatHuggingFace, HuggingFaceEndpoint
29
  from langchain_groq import ChatGroq
30
  from langchain_community.vectorstores import SupabaseVectorStore
31
  from langchain_core.messages import SystemMessage, HumanMessage
 
741
  def build_graph():
742
  """Build the graph"""
743
 
744
+ # Try Groq first, fall back to HuggingFace if rate limited
745
+ groq_key = os.environ.get("GROQ_API_KEY")
746
+ hf_token = os.environ.get("HF_TOKEN")
747
+
748
+ # Use HuggingFace as primary (more reliable, no strict daily limits)
749
+ llm = ChatHuggingFace(
750
+ llm=HuggingFaceEndpoint(
751
+ repo_id="Qwen/Qwen2.5-72B-Instruct",
752
+ task="text-generation",
753
+ max_new_tokens=4096,
754
+ do_sample=False,
755
+ temperature=0.01,
756
+ huggingfacehub_api_token=hf_token
757
+ ),
758
+ verbose=False,
759
  )
760
 
761
  # Bind tools to LLM