Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,20 @@ from langchain_core.messages import SystemMessage
|
|
11 |
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
12 |
from langchain_groq import ChatGroq
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
model_name=model
|
21 |
-
)
|
22 |
|
23 |
-
# Manages the chat history, ensuring the AI remembers the specified number of history messages, in this case 5.
|
24 |
-
memory = ConversationBufferWindowMemory(k=5, memory_key="chat_history", return_messages=True)
|
25 |
|
|
|
|
|
|
|
|
|
26 |
prompt = ChatPromptTemplate.from_messages(
|
27 |
[
|
28 |
# This is the persistent system prompt, sets the initial context for the AI.
|
@@ -63,7 +65,6 @@ example1 = [
|
|
63 |
["What to San Francisco?"],
|
64 |
["Then what to Beijing?"],
|
65 |
["And what to Kyoto?"],
|
66 |
-
["Who are you?"],
|
67 |
]
|
68 |
|
69 |
# Create the Gradio interface
|
|
|
11 |
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
12 |
from langchain_groq import ChatGroq
|
13 |
|
14 |
+
# Initialize Groq Langchain chat object and conversation
|
15 |
+
groq_chat = ChatGroq(
|
16 |
+
groq_api_key=os.environ.get("GROQ_API_KEY"),
|
17 |
+
)
|
18 |
|
19 |
+
# Initialize memory to manages the chat history,
|
20 |
+
# ensuring the AI remembers the specified number of history messages, in this case 5.
|
21 |
+
memory = ConversationBufferWindowMemory(k=5, memory_key="chat_history", return_messages=True)
|
|
|
|
|
22 |
|
|
|
|
|
23 |
|
24 |
+
def generate_response(user_input, history, model, temperature, max_tokens, top_p, seed):
|
25 |
+
print( "Model =", model)
|
26 |
+
|
27 |
+
groq_chat.model_name = model_name
|
28 |
prompt = ChatPromptTemplate.from_messages(
|
29 |
[
|
30 |
# This is the persistent system prompt, sets the initial context for the AI.
|
|
|
65 |
["What to San Francisco?"],
|
66 |
["Then what to Beijing?"],
|
67 |
["And what to Kyoto?"],
|
|
|
68 |
]
|
69 |
|
70 |
# Create the Gradio interface
|