Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,8 +17,8 @@ if not api_key:
|
|
| 17 |
# β
Configure Gemini Model
|
| 18 |
model = ChatGoogleGenerativeAI(model="gemini-1.5-pro", api_key=api_key)
|
| 19 |
|
| 20 |
-
# β
Add Memory to Make It Context-Aware
|
| 21 |
-
memory = ConversationBufferMemory()
|
| 22 |
|
| 23 |
# β
Define Prompt for Data Science Focus
|
| 24 |
prompt_template = """
|
|
@@ -28,15 +28,18 @@ You are an AI Data Science tutor.
|
|
| 28 |
- Provide clear, detailed, and accurate explanations with examples where applicable.
|
| 29 |
- Avoid overly technical language unless necessary.
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
User: {input}
|
| 32 |
AI:
|
| 33 |
"""
|
| 34 |
|
| 35 |
-
# β
Create Conversation Chain
|
| 36 |
conversation = ConversationChain(
|
| 37 |
llm=model,
|
| 38 |
memory=memory,
|
| 39 |
-
prompt=PromptTemplate(template=prompt_template, input_variables=["input"])
|
| 40 |
)
|
| 41 |
|
| 42 |
# β
Streamlit UI
|
|
|
|
| 17 |
# β
Configure Gemini Model
|
| 18 |
model = ChatGoogleGenerativeAI(model="gemini-1.5-pro", api_key=api_key)
|
| 19 |
|
| 20 |
+
# β
Add Memory to Make It Context-Aware (Fix for 'history' error)
|
| 21 |
+
memory = ConversationBufferMemory(input_key="input")
|
| 22 |
|
| 23 |
# β
Define Prompt for Data Science Focus
|
| 24 |
prompt_template = """
|
|
|
|
| 28 |
- Provide clear, detailed, and accurate explanations with examples where applicable.
|
| 29 |
- Avoid overly technical language unless necessary.
|
| 30 |
|
| 31 |
+
Chat History:
|
| 32 |
+
{history}
|
| 33 |
+
|
| 34 |
User: {input}
|
| 35 |
AI:
|
| 36 |
"""
|
| 37 |
|
| 38 |
+
# β
Create Conversation Chain (Matching Memory Keys)
|
| 39 |
conversation = ConversationChain(
|
| 40 |
llm=model,
|
| 41 |
memory=memory,
|
| 42 |
+
prompt=PromptTemplate(template=prompt_template, input_variables=["history", "input"])
|
| 43 |
)
|
| 44 |
|
| 45 |
# β
Streamlit UI
|