VanguardAI commited on
Commit
fee053d
·
verified ·
1 Parent(s): 72769c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
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
- # Create an LLMChain using a prompt template and the model
158
- prompt_template = PromptTemplate(input_variables=["query"], template="{query}")
159
- llm = OpenAI(model=MODEL)
160
- llm_chain = LLMChain(llm=llm, prompt=prompt_template)
161
 
162
- def llm_function(query):
163
- return llm_chain.run(query)
 
164
 
165
- agent_executor = AgentExecutor.from_agent_and_tools(llm=llm_function, tools=tools, verbose=True)
 
 
 
 
 
 
 
 
 
 
 
 
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')