Update app.py
Browse files123456126 unmodified lines1331341351361371381391403 unmodified lines144145146147148149150import os, re, requests, pandas as pd, gradio as grfrom transformers import pipelinefrom langchain_huggingface.llms import HuggingFacePipelinefrom langchain.tools import toolfrom langchain_core.output_parsers import JsonOutputParserfrom langchain.agents import AgentExecutor126 unmodified lines# initialize HF inference pipeline onceif HF_TOKEN is None:raise ValueError("HF_TOKEN not set in environment")pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)self.llm = HuggingFacePipeline(pipeline=pipe).bind_tools(TOOLS)# The GAIA system prompt (no "FINAL ANSWER:" at the end)self.system_prompt = SYSTEM_MESSAGEprint("BasicAgent initialized with LLM.")3 unmodified linesprompt = f"{self.system_prompt}Q: {q}\nA:"#out = self.generator(prompt, max_new_tokens=16, return_full_text=False)#return out[0]["generated_text"].strip()agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)result = agent.invoke({"input": question})return JsonOutputParser().parse(result)123456126 unmodified lines1331341351361371381391401411421431441451461471483 unmodified lines152153154155156157158159160161162163164import os, re, requests, pandas as pd, gradio as grfrom transformers import pipelinefrom langchain_huggingface import HuggingFacePipeline, ChatHuggingFacefrom langchain.tools import toolfrom langchain_core.output_parsers import JsonOutputParserfrom langchain.agents import AgentExecutor126 unmodified lines# initialize HF inference pipeline onceif HF_TOKEN is None:raise ValueError("HF_TOKEN not set in environment")#pipe = pipeline("text-generation", model="EleutherAI/gpt-neo-125M", max_new_tokens=16)#self.llm = HuggingFacePipeline(pipeline=pipe).bind_tools(TOOLS)hf_pipe = HuggingFacePipeline.from_model_id(model_id="EleutherAI/gpt-neo-125M",task="text-generation",pipeline_kwargs={"max_new_tokens":16},)chat = ChatHuggingFace(llm=hf_pipe) # wrap in chat‐modelself.llm = chat.bind_tools(TOOLS) # now this works :contentReference[oaicite:0]{index=0}# The GAIA system prompt (no "FINAL ANSWER:" at the end)self.system_prompt = SYSTEM_MESSAGEprint("BasicAgent initialized with LLM.")3 unmodified linesprompt = f"{self.system_prompt}Q: {q}\nA:"#out = self.generator(prompt, max_new_tokens=16, return_full_text=False)#return out[0]["generated_text"].strip()agent = AgentExecutor.from_llm_and_tools(llm=self.llm,tools=TOOLS,system_message=self.system_prompt,verbose=True,)#agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)result = agent.invoke({"input": question})return JsonOutputParser().parse(result)
app.py+18-4