Adinarayana02 commited on
Commit
379f3b9
·
verified ·
1 Parent(s): c4b8e86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -29
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- import openai
3
  import streamlit as st
4
  from dotenv import load_dotenv
5
  from typing import List
@@ -8,12 +8,11 @@ import abc
8
 
9
  # Load environment variables (API keys)
10
  load_dotenv()
11
- openai.api_key = os.getenv("OPENAI_API_KEY")
12
 
13
  # Define constants
14
  CONVO_TRAIL_CUTOFF = 5
15
  PERSONAL_AI_ASSISTANT_PROMPT_HEAD = "You are a helpful assistant. [[previous_interactions]] [[latest_input]]"
16
- ASSISTANT_TYPE = "OpenAIPAF"
17
 
18
  # Define Interaction class
19
  class Interaction:
@@ -38,21 +37,27 @@ class PersonalAssistantFramework(abc.ABC):
38
  def think(self, prompt: str) -> str:
39
  pass
40
 
41
- class OpenAIPAF(PersonalAssistantFramework):
 
 
 
42
  def setup(self):
43
- self.llm_model = None # Assume build_mini_model is not defined
44
 
45
  @PersonalAssistantFramework.timeit_decorator
46
  def think(self, thought: str) -> str:
47
- response = openai.ChatCompletion.create(
48
- model="gpt-4o-mini",
49
- messages=[
50
- {"role": "system", "content": "You are a helpful assistant."},
51
- {"role": "user", "content": thought}
52
- ],
53
- max_tokens=500
54
- )
55
- return response.choices[0].message['content'].strip()
 
 
 
56
 
57
  def build_prompt(latest_input: str, previous_interactions: List[Interaction]) -> str:
58
  previous_interactions_str = "\n".join(
@@ -71,7 +76,7 @@ def build_prompt(latest_input: str, previous_interactions: List[Interaction]) ->
71
  return prepared_prompt
72
 
73
  # Set the page config for Streamlit
74
- st.set_page_config(page_title="AI Chatbot", page_icon="🤖", layout="wide")
75
 
76
  # Add premium CSS styling with the new blue color palette
77
  st.markdown("""
@@ -81,7 +86,6 @@ st.markdown("""
81
  color: #AFDDE5; /* Light blue text for contrast */
82
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Modern font */
83
  }
84
-
85
  .header {
86
  background-color: #024950; /* Medium blue header */
87
  padding: 20px;
@@ -91,7 +95,6 @@ st.markdown("""
91
  font-weight: bold;
92
  border-bottom: 1px solid #0FA4AF; /* Lighter blue border */
93
  }
94
-
95
  .chat-box {
96
  border-radius: 8px;
97
  padding: 15px;
@@ -101,14 +104,12 @@ st.markdown("""
101
  background-color: #024950; /* Medium blue chat box background */
102
  color: #AFDDE5; /* Light blue text for chat box */
103
  }
104
-
105
  .user-message {
106
  text-align: right;
107
  margin-left: auto;
108
  background-color: #0FA4AF; /* Aqua blue for user messages */
109
  color: #003135; /* Dark blue text for user messages */
110
  }
111
-
112
  .assistant-message {
113
  text-align: left;
114
  margin-right: auto;
@@ -117,7 +118,6 @@ st.markdown("""
117
  display: flex;
118
  align-items: center;
119
  }
120
-
121
  .assistant-logo {
122
  width: 40px;
123
  height: 40px;
@@ -128,19 +128,16 @@ st.markdown("""
128
  justify-content: center;
129
  align-items: center;
130
  }
131
-
132
  .assistant-logo img {
133
  width: 24px;
134
  height: 24px;
135
  }
136
-
137
  .message {
138
  display: inline-block;
139
  padding: 10px;
140
  border-radius: 15px;
141
  width: fit-content;
142
  }
143
-
144
  .stButton button {
145
  background-color: #0FA4AF; /* Aqua blue button color */
146
  color: #003135; /* Dark blue text on button */
@@ -150,11 +147,9 @@ st.markdown("""
150
  cursor: pointer;
151
  font-size: 16px;
152
  }
153
-
154
  .stButton button:hover {
155
  background-color: #024950; /* Medium blue on hover */
156
  }
157
-
158
  .stTextArea textarea {
159
  background-color: #024950; /* Medium blue background for text area */
160
  color: #AFDDE5; /* Light blue text for text area */
@@ -164,11 +159,9 @@ st.markdown("""
164
  width: 100%;
165
  resize: none;
166
  }
167
-
168
  .stTextArea textarea::placeholder {
169
  color: #AFDDE5; /* Light blue placeholder text */
170
  }
171
-
172
  .subheader {
173
  color: #AFDDE5; /* Light blue color for subheaders */
174
  font-size: 20px;
@@ -215,7 +208,7 @@ with st.container():
215
  # Submit button
216
  if st.button("Send"):
217
  if user_input:
218
- assistant = OpenAIPAF()
219
  assistant.setup()
220
 
221
  # Build prompt and get response
@@ -244,4 +237,4 @@ with st.container():
244
  else:
245
  st.warning("Please enter a message.")
246
 
247
- st.write("This chatbot uses GPT-4o-mini model to respond to your messages.")
 
1
  import os
2
+ from groq import Groq
3
  import streamlit as st
4
  from dotenv import load_dotenv
5
  from typing import List
 
8
 
9
  # Load environment variables (API keys)
10
  load_dotenv()
 
11
 
12
  # Define constants
13
  CONVO_TRAIL_CUTOFF = 5
14
  PERSONAL_AI_ASSISTANT_PROMPT_HEAD = "You are a helpful assistant. [[previous_interactions]] [[latest_input]]"
15
+ ASSISTANT_TYPE = "GroqPAF"
16
 
17
  # Define Interaction class
18
  class Interaction:
 
37
  def think(self, prompt: str) -> str:
38
  pass
39
 
40
+ class GroqPAF(PersonalAssistantFramework):
41
+ def __init__(self):
42
+ self.client = Groq(api_key=os.getenv("GROQ_API_KEY"))
43
+
44
  def setup(self):
45
+ self.llm_model = None
46
 
47
  @PersonalAssistantFramework.timeit_decorator
48
  def think(self, thought: str) -> str:
49
+ try:
50
+ response = self.client.chat.completions.create(
51
+ model="mixtral-8x7b-32768", # You can change this to other Groq models
52
+ messages=[
53
+ {"role": "system", "content": "You are a helpful assistant named Luna."},
54
+ {"role": "user", "content": thought}
55
+ ],
56
+ max_tokens=500
57
+ )
58
+ return response.choices[0].message.content.strip()
59
+ except Exception as e:
60
+ return f"An error occurred: {str(e)}"
61
 
62
  def build_prompt(latest_input: str, previous_interactions: List[Interaction]) -> str:
63
  previous_interactions_str = "\n".join(
 
76
  return prepared_prompt
77
 
78
  # Set the page config for Streamlit
79
+ st.set_page_config(page_title="Luna AI Chatbot", page_icon="🤖", layout="wide")
80
 
81
  # Add premium CSS styling with the new blue color palette
82
  st.markdown("""
 
86
  color: #AFDDE5; /* Light blue text for contrast */
87
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Modern font */
88
  }
 
89
  .header {
90
  background-color: #024950; /* Medium blue header */
91
  padding: 20px;
 
95
  font-weight: bold;
96
  border-bottom: 1px solid #0FA4AF; /* Lighter blue border */
97
  }
 
98
  .chat-box {
99
  border-radius: 8px;
100
  padding: 15px;
 
104
  background-color: #024950; /* Medium blue chat box background */
105
  color: #AFDDE5; /* Light blue text for chat box */
106
  }
 
107
  .user-message {
108
  text-align: right;
109
  margin-left: auto;
110
  background-color: #0FA4AF; /* Aqua blue for user messages */
111
  color: #003135; /* Dark blue text for user messages */
112
  }
 
113
  .assistant-message {
114
  text-align: left;
115
  margin-right: auto;
 
118
  display: flex;
119
  align-items: center;
120
  }
 
121
  .assistant-logo {
122
  width: 40px;
123
  height: 40px;
 
128
  justify-content: center;
129
  align-items: center;
130
  }
 
131
  .assistant-logo img {
132
  width: 24px;
133
  height: 24px;
134
  }
 
135
  .message {
136
  display: inline-block;
137
  padding: 10px;
138
  border-radius: 15px;
139
  width: fit-content;
140
  }
 
141
  .stButton button {
142
  background-color: #0FA4AF; /* Aqua blue button color */
143
  color: #003135; /* Dark blue text on button */
 
147
  cursor: pointer;
148
  font-size: 16px;
149
  }
 
150
  .stButton button:hover {
151
  background-color: #024950; /* Medium blue on hover */
152
  }
 
153
  .stTextArea textarea {
154
  background-color: #024950; /* Medium blue background for text area */
155
  color: #AFDDE5; /* Light blue text for text area */
 
159
  width: 100%;
160
  resize: none;
161
  }
 
162
  .stTextArea textarea::placeholder {
163
  color: #AFDDE5; /* Light blue placeholder text */
164
  }
 
165
  .subheader {
166
  color: #AFDDE5; /* Light blue color for subheaders */
167
  font-size: 20px;
 
208
  # Submit button
209
  if st.button("Send"):
210
  if user_input:
211
+ assistant = GroqPAF()
212
  assistant.setup()
213
 
214
  # Build prompt and get response
 
237
  else:
238
  st.warning("Please enter a message.")
239
 
240
+ st.write("This chatbot uses Groq's Mixtral 8x7B model to respond to your messages.")