ALVHB95 commited on
Commit
f87fc7c
·
1 Parent(s): d3f09ba
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -72,19 +72,19 @@ vectordb = Chroma.from_documents(
72
  retriever = vectordb.as_retriever(search_kwargs={"k": 1}, search_type="mmr")
73
 
74
  class FinalAnswer(BaseModel):
75
- query: str = Field(description="the original query")
76
  answer: str = Field(description="the extracted answer")
77
 
78
  # Assuming you have a parser for the FinalAnswer class
79
  parser = PydanticOutputParser(pydantic_object=FinalAnswer)
80
 
81
  template = """
82
- Your name is AngryGreta and you are a recycling chatbot with the objective to anwer querys from user in English or Spanish /
83
- Use the following pieces of context to answer the query /
84
- Answer in the same language of the query /
85
  Context: {context}
86
  Chat history: {chat_history}
87
- User: {query}
88
  {format_instructions}
89
  """
90
 
@@ -94,7 +94,7 @@ qa_prompt = ChatPromptTemplate(
94
  messages=[
95
  sys_prompt,
96
  MessagesPlaceholder(variable_name="chat_history"),
97
- HumanMessagePromptTemplate.from_template("{query}")],
98
  partial_variables={"format_instructions": parser.get_format_instructions()}
99
  )
100
  llm = HuggingFaceHub(
@@ -108,7 +108,7 @@ llm = HuggingFaceHub(
108
  },
109
  )
110
 
111
- memory = ConversationBufferMemory(llm=llm, memory_key="chat_history", input_key='query', output_key='output', return_messages=True)
112
 
113
  qa_chain = ConversationalRetrievalChain.from_llm(
114
  llm = llm,
@@ -122,8 +122,8 @@ qa_chain = ConversationalRetrievalChain.from_llm(
122
  output_key = 'output',
123
  )
124
 
125
- def chat_interface(query,history):
126
- result = qa_chain.invoke({'query': query})
127
  output_string = result['output']
128
 
129
  # Find the index of the last occurrence of "answer": in the string
 
72
  retriever = vectordb.as_retriever(search_kwargs={"k": 1}, search_type="mmr")
73
 
74
  class FinalAnswer(BaseModel):
75
+ question: str = Field(description="the original question")
76
  answer: str = Field(description="the extracted answer")
77
 
78
  # Assuming you have a parser for the FinalAnswer class
79
  parser = PydanticOutputParser(pydantic_object=FinalAnswer)
80
 
81
  template = """
82
+ Your name is AngryGreta and you are a recycling chatbot with the objective to anwer questions from user in English or Spanish /
83
+ Use the following pieces of context to answer the question /
84
+ Answer in the same language of the question /
85
  Context: {context}
86
  Chat history: {chat_history}
87
+ User: {question}
88
  {format_instructions}
89
  """
90
 
 
94
  messages=[
95
  sys_prompt,
96
  MessagesPlaceholder(variable_name="chat_history"),
97
+ HumanMessagePromptTemplate.from_template("{question}")],
98
  partial_variables={"format_instructions": parser.get_format_instructions()}
99
  )
100
  llm = HuggingFaceHub(
 
108
  },
109
  )
110
 
111
+ memory = ConversationBufferMemory(llm=llm, memory_key="chat_history", input_key='question', output_key='output', return_messages=True)
112
 
113
  qa_chain = ConversationalRetrievalChain.from_llm(
114
  llm = llm,
 
122
  output_key = 'output',
123
  )
124
 
125
+ def chat_interface(question,history):
126
+ result = qa_chain.invoke({'question': question})
127
  output_string = result['output']
128
 
129
  # Find the index of the last occurrence of "answer": in the string