RalphThings commited on
Commit
4ea9079
·
verified ·
1 Parent(s): 6ce6484

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import os, re, requests, pandas as pd, gradio as gr
2
  from transformers import pipeline
3
- from langchain_huggingface.llms import HuggingFacePipeline
4
  from langchain.tools import tool
5
  from langchain_core.output_parsers import JsonOutputParser
6
  from langchain.agents import AgentExecutor
@@ -133,8 +133,16 @@ class BasicAgent:
133
  # initialize HF inference pipeline once
134
  if HF_TOKEN is None:
135
  raise ValueError("HF_TOKEN not set in environment")
136
- pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)
137
- self.llm = HuggingFacePipeline(pipeline=pipe).bind_tools(TOOLS)
 
 
 
 
 
 
 
 
138
  # The GAIA system prompt (no "FINAL ANSWER:" at the end)
139
  self.system_prompt = SYSTEM_MESSAGE
140
  print("BasicAgent initialized with LLM.")
@@ -144,7 +152,13 @@ class BasicAgent:
144
  prompt = f"{self.system_prompt}Q: {q}\nA:"
145
  #out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
146
  #return out[0]["generated_text"].strip()
147
- agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)
 
 
 
 
 
 
148
  result = agent.invoke({"input": question})
149
  return JsonOutputParser().parse(result)
150
 
 
1
  import os, re, requests, pandas as pd, gradio as gr
2
  from transformers import pipeline
3
+ from langchain_huggingface import HuggingFacePipeline, ChatHuggingFace
4
  from langchain.tools import tool
5
  from langchain_core.output_parsers import JsonOutputParser
6
  from langchain.agents import AgentExecutor
 
133
  # initialize HF inference pipeline once
134
  if HF_TOKEN is None:
135
  raise ValueError("HF_TOKEN not set in environment")
136
+ #pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)
137
+ #self.llm = HuggingFacePipeline(pipeline=pipe).bind_tools(TOOLS)
138
+ hf_pipe = HuggingFacePipeline.from_model_id(
139
+ model_id="EleutherAI/gpt-neo-125M",
140
+ task="text-generation",
141
+ pipeline_kwargs={"max_new_tokens":16},
142
+ )
143
+ chat = ChatHuggingFace(llm=hf_pipe) # wrap in chat‐model
144
+ self.llm = chat.bind_tools(TOOLS) # now this works :contentReference[oaicite:0]{index=0}
145
+
146
  # The GAIA system prompt (no "FINAL ANSWER:" at the end)
147
  self.system_prompt = SYSTEM_MESSAGE
148
  print("BasicAgent initialized with LLM.")
 
152
  prompt = f"{self.system_prompt}Q: {q}\nA:"
153
  #out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
154
  #return out[0]["generated_text"].strip()
155
+ agent = AgentExecutor.from_llm_and_tools(
156
+ llm=self.llm,
157
+ tools=TOOLS,
158
+ system_message=self.system_prompt,
159
+ verbose=True,
160
+ )
161
+ #agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)
162
  result = agent.invoke({"input": question})
163
  return JsonOutputParser().parse(result)
164