wishwakankanamg commited on
Commit
b478018
·
1 Parent(s): 3b91398
Files changed (2) hide show
  1. __pycache__/agent.cpython-310.pyc +0 -0
  2. agent.py +23 -20
__pycache__/agent.cpython-310.pyc CHANGED
Binary files a/__pycache__/agent.cpython-310.pyc and b/__pycache__/agent.cpython-310.pyc differ
 
agent.py CHANGED
@@ -157,27 +157,30 @@ if not hf_token:
157
  # Build graph function
158
  def build_graph(provider: str = "groq"):
159
  """Build the graph"""
160
- # Load environment variables from .env file
161
- if provider == "google":
162
- # Google Gemini
163
- llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0)
164
- elif provider == "groq":
165
- # Groq https://console.groq.com/docs/models
166
- llm = ChatGroq(model="qwen-qwq-32b", temperature=0) # optional : qwen-qwq-32b gemma2-9b-it
167
- elif provider == "huggingface":
168
- # TODO: Add huggingface endpoint
169
- repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
170
- llm = ChatHuggingFace(
171
-
172
- llm=HuggingFaceEndpoint(
173
- repo_id=repo_id,
174
- temperature=0,
175
- huggingfacehub_api_token= hf_token
176
- ),
177
  )
178
- else:
179
- raise ValueError("Invalid provider. Choose 'google', 'groq' or 'huggingface'.")
180
- # Bind tools to LLM
 
 
 
 
 
181
  llm_with_tools = llm.bind_tools(tools)
182
 
183
  # Node
 
157
  # Build graph function
158
  def build_graph(provider: str = "groq"):
159
  """Build the graph"""
160
+
161
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
162
+
163
+ if not hf_token:
164
+ raise ValueError("HF_TOKEN environment variable not set. It's required for Hugging Face provider.")
165
+
166
+ try:
167
+ # Initialize the HuggingFaceEndpoint
168
+ endpoint_llm = HuggingFaceEndpoint(
169
+ repo_id=repo_id,
170
+ temperature=0,
171
+ huggingfacehub_api_token=hf_token,
172
+ # You might want to add other parameters like:
173
+ # max_new_tokens=512,
174
+ # model_kwargs={"top_k": 10}
 
 
175
  )
176
+ # Wrap it with ChatHuggingFace for a chat interface
177
+ llm = ChatHuggingFace(llm=endpoint_llm)
178
+ print(f"Successfully initialized Hugging Face LLM: {repo_id}")
179
+
180
+ except Exception as e:
181
+ # This error is specific to Hugging Face LLM instantiation failing
182
+ raise RuntimeError(f"Failed to initialize Hugging Face model ('{repo_id}'): {e}") from e
183
+
184
  llm_with_tools = llm.bind_tools(tools)
185
 
186
  # Node