Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
headers = {
|
10 |
"Content-Type": "application/json",
|
11 |
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"
|
12 |
}
|
@@ -19,31 +16,37 @@ BOT_PERSONA = (
|
|
19 |
)
|
20 |
|
21 |
def chat_with_nietzsche(user_input):
|
22 |
-
headers = {
|
23 |
-
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
|
24 |
-
"Content-Type": "application/json"
|
25 |
-
}
|
26 |
-
|
27 |
# Define the conversation history
|
28 |
messages = [
|
29 |
{"role": "system", "content": BOT_PERSONA},
|
30 |
{"role": "user", "content": user_input}
|
31 |
]
|
32 |
|
33 |
-
#
|
34 |
data = {
|
35 |
-
"
|
36 |
-
"
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
|
48 |
# Streamlit app
|
49 |
def main():
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
|
4 |
+
# Third-party API endpoint and headers
|
5 |
+
API_URL = "https://api.hyperbolic.xyz/v1/chat/completions"
|
6 |
+
API_HEADERS = {
|
|
|
|
|
|
|
7 |
"Content-Type": "application/json",
|
8 |
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"
|
9 |
}
|
|
|
16 |
)
|
17 |
|
18 |
def chat_with_nietzsche(user_input):
|
|
|
|
|
|
|
|
|
|
|
19 |
# Define the conversation history
|
20 |
messages = [
|
21 |
{"role": "system", "content": BOT_PERSONA},
|
22 |
{"role": "user", "content": user_input}
|
23 |
]
|
24 |
|
25 |
+
# Prepare the request payload
|
26 |
data = {
|
27 |
+
"messages": messages,
|
28 |
+
"model": "deepseek-ai/DeepSeek-V3", # Model specified by the third-party API
|
29 |
+
"max_tokens": 512, # Maximum number of tokens in the response
|
30 |
+
"temperature": 0.1, # Controls randomness (lower = more deterministic)
|
31 |
+
"top_p": 0.9 # Controls diversity (higher = more diverse)
|
32 |
}
|
33 |
|
34 |
+
try:
|
35 |
+
# Send the request to the third-party API
|
36 |
+
response = requests.post(API_URL, headers=API_HEADERS, json=data)
|
37 |
+
response_data = response.json()
|
38 |
+
|
39 |
+
# Print the API response and status code for debugging
|
40 |
+
print("API Response:", response_data)
|
41 |
+
print("Status Code:", response.status_code)
|
42 |
|
43 |
+
# Extract the bot's reply
|
44 |
+
if response.status_code == 200:
|
45 |
+
return response_data["choices"][0]["message"]["content"]
|
46 |
+
else:
|
47 |
+
return f"Error: Unable to get a response from the bot. Status Code: {response.status_code}"
|
48 |
+
except Exception as e:
|
49 |
+
return f"Error: An exception occurred - {str(e)}"
|
50 |
|
51 |
# Streamlit app
|
52 |
def main():
|