Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from langchain_community.vectorstores import Chroma
|
|
| 13 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 14 |
from langchain.chains import RetrievalQA
|
| 15 |
from langchain import LLMChain, PromptTemplate
|
| 16 |
-
from langchain.agents import AgentExecutor, Tool
|
| 17 |
from langchain.llms import OpenAI
|
| 18 |
from PIL import Image
|
| 19 |
from decord import VideoReader, cpu
|
|
@@ -154,15 +154,27 @@ def handle_input(user_prompt, image=None, video=None, audio=None, doc=None, webs
|
|
| 154 |
)
|
| 155 |
)
|
| 156 |
|
| 157 |
-
#
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
llm_chain = LLMChain(llm=llm, prompt=prompt_template)
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
|
|
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
if image:
|
| 168 |
image = Image.open(image).convert('RGB')
|
|
|
|
| 13 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 14 |
from langchain.chains import RetrievalQA
|
| 15 |
from langchain import LLMChain, PromptTemplate
|
| 16 |
+
from langchain.agents import AgentExecutor, Tool, ZeroShotAgent
|
| 17 |
from langchain.llms import OpenAI
|
| 18 |
from PIL import Image
|
| 19 |
from decord import VideoReader, cpu
|
|
|
|
| 154 |
)
|
| 155 |
)
|
| 156 |
|
| 157 |
+
# Add this new code block:
|
| 158 |
+
prefix = """You are an AI assistant. You have access to the following tools:"""
|
| 159 |
+
suffix = """Begin!"
|
|
|
|
| 160 |
|
| 161 |
+
{chat_history}
|
| 162 |
+
Human: {input}
|
| 163 |
+
AI: I will do my best to assist you. Let me think about this step-by-step:"""
|
| 164 |
|
| 165 |
+
prompt = ZeroShotAgent.create_prompt(
|
| 166 |
+
tools,
|
| 167 |
+
prefix=prefix,
|
| 168 |
+
suffix=suffix,
|
| 169 |
+
input_variables=["input", "chat_history"]
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
llm = Groq(model=MODEL)
|
| 173 |
+
llm_chain = LLMChain(llm=llm, prompt=prompt)
|
| 174 |
+
|
| 175 |
+
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)
|
| 176 |
+
|
| 177 |
+
agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True
|
| 178 |
|
| 179 |
if image:
|
| 180 |
image = Image.open(image).convert('RGB')
|