VermaPankaj123 commited on
Commit
784c614
·
verified ·
1 Parent(s): 7f4d897

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -12
main.py CHANGED
@@ -8,28 +8,27 @@ from langchain_core.output_parsers import PydanticOutputParser
8
  from langchain.agents import create_tool_calling_agent, AgentExecutor
9
  from tools import search_tool, wiki_tool, save_tool
10
 
11
- os.getenv("HUGGINGFACEHUB_API_TOKEN")
12
-
13
- # Define the response format
14
- class ResearchResponse(BaseModel):
15
- topic: str
16
- summary: str
17
- sources: list[str]
18
- tools_used: list[str]
19
-
20
-
21
-
22
- # ✅ Use HuggingFace Mistral model (free)
23
 
 
24
  if hf_token is None:
25
  raise ValueError("Missing Hugging Face API token. Please set the 'HUGGINGFACEHUB_API_TOKEN' secret in your HF space settings.")
26
 
 
27
  llm = HuggingFaceHub(
28
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
29
  huggingfacehub_api_token=hf_token,
30
  model_kwargs={"temperature": 0.7, "max_new_tokens": 500},
31
  )
32
 
 
 
 
 
 
 
 
33
  # Create parser
34
  parser = PydanticOutputParser(pydantic_object=ResearchResponse)
35
 
 
8
  from langchain.agents import create_tool_calling_agent, AgentExecutor
9
  from tools import search_tool, wiki_tool, save_tool
10
 
11
+ # ✅ Get the token from environment variables
12
+ hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
 
 
 
 
 
 
 
 
 
 
13
 
14
+ # ✅ Check and raise an error if it's missing
15
  if hf_token is None:
16
  raise ValueError("Missing Hugging Face API token. Please set the 'HUGGINGFACEHUB_API_TOKEN' secret in your HF space settings.")
17
 
18
+ # ✅ Use HuggingFace Mistral model (free), Initialize your LLM using the token
19
  llm = HuggingFaceHub(
20
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
21
  huggingfacehub_api_token=hf_token,
22
  model_kwargs={"temperature": 0.7, "max_new_tokens": 500},
23
  )
24
 
25
+ # Define the response format
26
+ class ResearchResponse(BaseModel):
27
+ topic: str
28
+ summary: str
29
+ sources: list[str]
30
+ tools_used: list[str]
31
+
32
  # Create parser
33
  parser = PydanticOutputParser(pydantic_object=ResearchResponse)
34