gabejavitt commited on
Commit
f0ae60b
Β·
verified Β·
1 Parent(s): 142419b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -27
app.py CHANGED
@@ -36,6 +36,8 @@ from langgraph.graph import START, END, StateGraph
36
  from langchain_groq import ChatGroq
37
  from langchain_google_genai import ChatGoogleGenerativeAI
38
  from langchain_community.llms import HuggingFaceHub
 
 
39
 
40
  # RAG
41
  from langchain_text_splitters import RecursiveCharacterTextSplitter
@@ -1055,34 +1057,35 @@ REMEMBER: One tool per turn. No reasoning without tools. Exact answer format.
1055
  # max_new_tokens=2048, # Increased token limit for potentially longer reasoning/tool use
1056
  # temperature=0.01, # Keep temperature low for factual tasks
1057
  # Use tool_choice="any" to FORCE tool usage
1058
- print("Initializing Groq LLM...")
1059
- try:
1060
- self.llm_with_tools = ChatGroq(
1061
- temperature=0,
1062
- groq_api_key=GROQ_API_KEY,
1063
- model_name="llama-3.1-8b-instant",
1064
- max_tokens=4096,
1065
- timeout=60
1066
- ).bind_tools(self.tools, tool_choice="auto")
1067
- print("βœ… LLM initialized without FORCED tool usage.")
1068
-
1069
- except Exception as e:
1070
- print(f"❌ Error initializing HuggingFace: {e}")
1071
- raise
1072
- # print("Initializing LLM Endpoint...")
1073
- # llm = HuggingFaceEndpoint(
1074
- # repo_id="Qwen/Qwen2.5-Coder-32B-Instruct", # Changed model
1075
- # huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
1076
- # max_new_tokens=2048, # Increased token limit for potentially longer reasoning/tool use
1077
- # temperature=0.01, # Keep temperature low for factual tasks
1078
- # )
1079
- # chat_llm = ChatHuggingFace(llm=llm)
1080
- # print("βœ… LLM Endpoint initialized.")
1081
  #
1082
- # # 6. Bind tools to the LLM
1083
- # # Ensure the LLM knows how to format calls for the tools
1084
- # self.llm_with_tools = chat_llm.bind_tools(self.tools)
1085
- # print("βœ… Tools bound to LLM.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1086
  # print("Initializing Google Gemini LLM...")
1087
  # try:
1088
  # self.llm_with_tools = ChatGoogleGenerativeAI(
 
36
  from langchain_groq import ChatGroq
37
  from langchain_google_genai import ChatGoogleGenerativeAI
38
  from langchain_community.llms import HuggingFaceHub
39
+ from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
40
+
41
 
42
  # RAG
43
  from langchain_text_splitters import RecursiveCharacterTextSplitter
 
1057
  # max_new_tokens=2048, # Increased token limit for potentially longer reasoning/tool use
1058
  # temperature=0.01, # Keep temperature low for factual tasks
1059
  # Use tool_choice="any" to FORCE tool usage
1060
+ # print("Initializing Groq LLM...")
1061
+ # try:
1062
+ # self.llm_with_tools = ChatGroq(
1063
+ # temperature=0,
1064
+ # groq_api_key=GROQ_API_KEY,
1065
+ # model_name="llama-3.1-8b-instant",
1066
+ # max_tokens=4096,
1067
+ # timeout=60
1068
+ # ).bind_tools(self.tools, tool_choice="auto")
1069
+ # print("βœ… LLM initialized without FORCED tool usage.")
 
 
 
 
 
 
 
 
 
 
 
 
 
1070
  #
1071
+ # except Exception as e:
1072
+ # print(f"❌ Error initializing HuggingFace: {e}")
1073
+ # raise
1074
+ # print("Initializing LLM Endpoint...")
1075
+ print("Initializing HuggingFace LLM...")
1076
+
1077
+ llm = HuggingFaceEndpoint(
1078
+ repo_id="meta-llama/Llama-3.1-70B-Instruct", # Free on HF Inference API
1079
+ huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
1080
+ max_new_tokens=4096,
1081
+ temperature=0.01,
1082
+ )
1083
+ chat_llm = ChatHuggingFace(llm=llm)
1084
+ print("βœ… HuggingFace LLM Endpoint initialized.")
1085
+
1086
+ # Bind tools to the LLM
1087
+ self.llm_with_tools = chat_llm.bind_tools(self.tools, tool_choice="auto")
1088
+ print("βœ… Tools bound to LLM.")
1089
  # print("Initializing Google Gemini LLM...")
1090
  # try:
1091
  # self.llm_with_tools = ChatGoogleGenerativeAI(