Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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, create_react_agent
|
| 7 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 8 |
import chess, chess.engine
|
| 9 |
from bs4 import BeautifulSoup
|
|
@@ -152,16 +152,16 @@ class BasicAgent:
|
|
| 152 |
prompt = f"{self.system_prompt}Q: {question}\nA:"
|
| 153 |
#out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
|
| 154 |
#return out[0]["generated_text"].strip()
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
)
|
| 162 |
#agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)
|
| 163 |
-
result = agent.invoke({"input": question})
|
| 164 |
-
return JsonOutputParser().parse(result)
|
| 165 |
|
| 166 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 167 |
"""
|
|
|
|
| 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, create_react_agent, initialize_agent, AgentType
|
| 7 |
from youtube_transcript_api import YouTubeTranscriptApi
|
| 8 |
import chess, chess.engine
|
| 9 |
from bs4 import BeautifulSoup
|
|
|
|
| 152 |
prompt = f"{self.system_prompt}Q: {question}\nA:"
|
| 153 |
#out = self.generator(prompt, max_new_tokens=16, return_full_text=False)
|
| 154 |
#return out[0]["generated_text"].strip()
|
| 155 |
+
# build a zero-shot-react-description agent for LLM+tools
|
| 156 |
+
agent_executor = initialize_agent(tools=TOOLS, llm=self.llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
| 157 |
+
# simply run the agent on the user’s question
|
| 158 |
+
answer = agent_executor.run(question)
|
| 159 |
+
return answer.strip()
|
| 160 |
+
#agent = create_react_agent(llm=self.llm, tools=TOOLS, prompt=prompt)
|
| 161 |
+
#agent = AgentExecutor(agent=agent, tools=TOOLS, verbose=True, return_intermediate_steps=False)
|
| 162 |
#agent = AgentExecutor(agent=self.llm, tools=TOOLS, prompt=prompt, verbose=False, return_intermediate_steps=False)
|
| 163 |
+
#result = agent.invoke({"input": question})
|
| 164 |
+
#return JsonOutputParser().parse(result)
|
| 165 |
|
| 166 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 167 |
"""
|