Update app.py
Browse files
app.py
CHANGED
@@ -104,12 +104,22 @@ vectordb = Chroma.from_documents(
|
|
104 |
# define retriever
|
105 |
retriever = vectordb.as_retriever(search_kwargs={"k": 2}, search_type="mmr")
|
106 |
|
107 |
-
class
|
108 |
question: str = Field(description="the original question")
|
109 |
answer: str = Field(description="the extracted answer")
|
110 |
|
111 |
-
#
|
112 |
-
parser = PydanticOutputParser(pydantic_object=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
template = """
|
115 |
Your name is Greta and you are a recycling chatbot with the objective to anwer questions from user in English or Spanish /
|
|
|
104 |
# define retriever
|
105 |
retriever = vectordb.as_retriever(search_kwargs={"k": 2}, search_type="mmr")
|
106 |
|
107 |
+
class Answer(BaseModel):
|
108 |
question: str = Field(description="the original question")
|
109 |
answer: str = Field(description="the extracted answer")
|
110 |
|
111 |
+
# Set up a PydanticOutputParser
|
112 |
+
parser = PydanticOutputParser(pydantic_object=Answer)
|
113 |
+
|
114 |
+
|
115 |
+
parser = PydanticOutputParser(pydantic_object=Answer)
|
116 |
+
|
117 |
+
# Create a prompt with format instructions
|
118 |
+
prompt = PromptTemplate(
|
119 |
+
template="Answer the user query.\n{format_instructions}\n{query}\n",
|
120 |
+
input_variables=["query"],
|
121 |
+
partial_variables={"format_instructions": parser.get_format_instructions()},
|
122 |
+
)
|
123 |
|
124 |
template = """
|
125 |
Your name is Greta and you are a recycling chatbot with the objective to anwer questions from user in English or Spanish /
|