Update app.py
Browse files
app.py
CHANGED
|
@@ -24,15 +24,18 @@ developer_topics = [
|
|
| 24 |
|
| 25 |
# Function to fetch chatbot completion from Groq API
|
| 26 |
def get_response(query):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def main():
|
| 38 |
st.title("Programming Developer Advisor Chatbot")
|
|
@@ -52,7 +55,9 @@ def main():
|
|
| 52 |
if any(topic.lower() in user_input.lower() for topic in developer_topics):
|
| 53 |
response = get_response(query)
|
| 54 |
st.write("### Response:")
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
else:
|
| 57 |
st.write("Sorry, I can only answer programming-related questions.")
|
| 58 |
else:
|
|
|
|
| 24 |
|
| 25 |
# Function to fetch chatbot completion from Groq API
|
| 26 |
def get_response(query):
|
| 27 |
+
try:
|
| 28 |
+
completion = client.chat.completions.create(
|
| 29 |
+
model="llama-3.3-70b-versatile",
|
| 30 |
+
messages=[{"role": "user", "content": query}],
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
max_completion_tokens=2024,
|
| 33 |
+
top_p=1,
|
| 34 |
+
)
|
| 35 |
+
response = completion.choices[0].message.content
|
| 36 |
+
return response
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error: {str(e)}"
|
| 39 |
|
| 40 |
def main():
|
| 41 |
st.title("Programming Developer Advisor Chatbot")
|
|
|
|
| 55 |
if any(topic.lower() in user_input.lower() for topic in developer_topics):
|
| 56 |
response = get_response(query)
|
| 57 |
st.write("### Response:")
|
| 58 |
+
# Display the response with proper formatting, and if it is long, we can show it in a scrollable container
|
| 59 |
+
st.markdown(f"#### Query: {query}")
|
| 60 |
+
st.text_area("Response:", response, height=300)
|
| 61 |
else:
|
| 62 |
st.write("Sorry, I can only answer programming-related questions.")
|
| 63 |
else:
|