naman1102 commited on
Commit
1daaf06
·
1 Parent(s): f9eca1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -7,7 +7,7 @@ from typing import Dict, Any, List, TypedDict, Optional
7
  from langgraph.graph import Graph, StateGraph
8
  from langgraph.prebuilt import ToolNode
9
  from tools import simple_search
10
- from langchain_community.llms import HuggingFaceEndpoint
11
 
12
  print("trial")
13
  # (Keep Constants as is)
@@ -30,11 +30,10 @@ class BasicAgent:
30
  if not HF_TOKEN:
31
  raise ValueError("HF_TOKEN environment variable not set. Please set your Hugging Face API token.")
32
 
33
- # Initialize LLM
34
- self.llm = HuggingFaceEndpoint(
35
- # repo_id="Qwen/Qwen2.5-Coder-7B-Instruct",
36
- repo_id="HuggingFaceH4/zephyr-7b-alpha",
37
- huggingfacehub_api_token=HF_TOKEN
38
  )
39
 
40
  # Create the agent workflow
@@ -43,9 +42,16 @@ class BasicAgent:
43
  print("BasicAgent initialization complete.")
44
 
45
  def _call_llm_api(self, prompt: str) -> str:
46
- """Call the Qwen model through the Hugging Face API using langchain."""
47
  try:
48
- return self.llm(prompt) # Using direct call syntax
 
 
 
 
 
 
 
49
  except Exception as e:
50
  print(f"Error calling LLM API: {e}")
51
  return f"Error getting response from LLM: {str(e)}"
 
7
  from langgraph.graph import Graph, StateGraph
8
  from langgraph.prebuilt import ToolNode
9
  from tools import simple_search
10
+ from huggingface_hub import InferenceClient
11
 
12
  print("trial")
13
  # (Keep Constants as is)
 
30
  if not HF_TOKEN:
31
  raise ValueError("HF_TOKEN environment variable not set. Please set your Hugging Face API token.")
32
 
33
+ # Initialize LLM client
34
+ self.llm = InferenceClient(
35
+ model="Qwen/Qwen2.5-Coder-7B-Instruct",
36
+ token=HF_TOKEN
 
37
  )
38
 
39
  # Create the agent workflow
 
42
  print("BasicAgent initialization complete.")
43
 
44
  def _call_llm_api(self, prompt: str) -> str:
45
+ """Call the Qwen model through the Hugging Face API using InferenceClient."""
46
  try:
47
+ response = self.llm.text_generation(
48
+ prompt,
49
+ max_new_tokens=200,
50
+ temperature=0.7,
51
+ top_p=0.95,
52
+ repetition_penalty=1.1
53
+ )
54
+ return response
55
  except Exception as e:
56
  print(f"Error calling LLM API: {e}")
57
  return f"Error getting response from LLM: {str(e)}"