RalphThings commited on
Commit
1d65282
·
verified ·
1 Parent(s): bb7b849

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -123,30 +123,39 @@ class BasicAgent:
123
  # initialize HF inference pipeline once
124
  if HF_TOKEN is None:
125
  raise ValueError("HF_TOKEN not set in environment")
126
- #pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)
127
- #self.llm = HuggingFacePipeline(pipeline=pipe).bind_tools(TOOLS)
128
- hf_pipe = HuggingFacePipeline.from_model_id(
129
- model_id="EleutherAI/gpt-neo-125M",
130
- task="text-generation",
131
- pipeline_kwargs={"max_new_tokens":16},
 
 
 
 
 
 
 
 
 
 
132
  )
133
- chat = ChatHuggingFace(llm=hf_pipe) # wrap in chat‐model
134
- self.llm = chat.bind_tools(TOOLS) # now this works :contentReference[oaicite:0]{index=0}
135
 
136
  # The GAIA system prompt (no "FINAL ANSWER:" at the end)
137
- self.system_prompt = SYSTEM_MESSAGE
138
  print("BasicAgent initialized with LLM.")
139
 
140
  # --- Core dispatcher/fallback ---
141
  def __call__(self, question: str) -> str:
142
- prompt = f"{self.system_prompt}Q: {question}\nA:"
143
  #out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
144
  #return out[0]["generated_text"].strip()
145
  # build a zero-shot-react-description agent for LLM+tools
146
- agent_executor = initialize_agent(tools=TOOLS, llm=self.llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
147
  # simply run the agent on the user’s question
148
- answer = agent_executor.run(question)
149
- return answer.strip()
 
150
  #agent = create_react_agent(llm=self.llm, tools=TOOLS, prompt=prompt)
151
  #agent = AgentExecutor(agent=agent, tools=TOOLS, verbose=True, return_intermediate_steps=False)
152
  #agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)
 
123
  # initialize HF inference pipeline once
124
  if HF_TOKEN is None:
125
  raise ValueError("HF_TOKEN not set in environment")
126
+ pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)
127
+ self.llm = HuggingFacePipeline(pipeline=pipe) #.bind_tools(TOOLS)
128
+ #hf_pipe = HuggingFacePipeline.from_model_id(
129
+ # model_id="EleutherAI/gpt-neo-125M",
130
+ # task="text-generation",
131
+ # pipeline_kwargs={"max_new_tokens":16},
132
+ #)
133
+ #chat = ChatHuggingFace(llm=hf_pipe) # wrap in chat‐model
134
+ #self.llm = chat.bind_tools(TOOLS) # now this works :contentReference[oaicite:0]{index=0}
135
+
136
+ self.agent = initialize_agent(
137
+ tools=TOOLS,
138
+ llm=self.llm,
139
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
140
+ system_message=SYSTEM_MESSAGE,
141
+ verbose=True,
142
  )
 
 
143
 
144
  # The GAIA system prompt (no "FINAL ANSWER:" at the end)
145
+ #self.system_prompt = SYSTEM_MESSAGE
146
  print("BasicAgent initialized with LLM.")
147
 
148
  # --- Core dispatcher/fallback ---
149
  def __call__(self, question: str) -> str:
150
+ #prompt = f"{self.system_prompt}Q: {question}\nA:"
151
  #out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
152
  #return out[0]["generated_text"].strip()
153
  # build a zero-shot-react-description agent for LLM+tools
154
+ #agent_executor = initialize_agent(tools=TOOLS, llm=self.llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
155
  # simply run the agent on the user’s question
156
+ #answer = agent_executor.run(question)
157
+ #return answer.strip()
158
+ return self.agent.run(question).strip()
159
  #agent = create_react_agent(llm=self.llm, tools=TOOLS, prompt=prompt)
160
  #agent = AgentExecutor(agent=agent, tools=TOOLS, verbose=True, return_intermediate_steps=False)
161
  #agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)