Update app.py
Browse files
app.py
CHANGED
|
@@ -24,45 +24,33 @@ def send_to_corrade(filtered_response):
|
|
| 24 |
response = requests.post(CORRADE_URL, data=data)
|
| 25 |
return response.status_code == 200
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
def chatbot_api(input_text):
|
| 28 |
-
stream = False
|
| 29 |
url = "https://chat.tune.app/api/chat/completions"
|
| 30 |
headers = {
|
| 31 |
-
"Authorization": os.environ.get('api'),
|
| 32 |
"Content-Type": "application/json"
|
| 33 |
}
|
| 34 |
data = {
|
| 35 |
-
"temperature": 0.
|
| 36 |
"messages": [
|
| 37 |
-
{
|
| 38 |
-
|
| 39 |
-
"content": "I am confirmed as a EXTREMELY EXCITED REACTIONIST for DJ's on Secondlife. ..."
|
| 40 |
-
},
|
| 41 |
-
{
|
| 42 |
-
"role": "user",
|
| 43 |
-
"content": input_text
|
| 44 |
-
}
|
| 45 |
],
|
| 46 |
"model": "goliath-120b-16k-gptq",
|
| 47 |
-
"stream":
|
| 48 |
-
"max_tokens":
|
| 49 |
}
|
| 50 |
-
response = requests.post(url, headers=headers, json=data)
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
if 'choices' in chat_response and len(chat_response['choices']) > 0:
|
| 56 |
-
chat_content = chat_response['choices'][0].get('message', {}).get('content', '')
|
| 57 |
-
if chat_content:
|
| 58 |
-
filtered_response = filter_non_alphanumeric(chat_content)
|
| 59 |
-
return filtered_response
|
| 60 |
-
else:
|
| 61 |
-
return "No content found in the chat response."
|
| 62 |
-
else:
|
| 63 |
-
return "The 'choices' key is missing or empty in the chat response."
|
| 64 |
-
else:
|
| 65 |
-
return f"Failed to get a successful response from the chat API. Status Code: {response.status_code}"
|
| 66 |
|
| 67 |
|
| 68 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
|
|
|
| 24 |
response = requests.post(CORRADE_URL, data=data)
|
| 25 |
return response.status_code == 200
|
| 26 |
|
| 27 |
+
import os
|
| 28 |
+
import requests
|
| 29 |
+
|
| 30 |
def chatbot_api(input_text):
|
|
|
|
| 31 |
url = "https://chat.tune.app/api/chat/completions"
|
| 32 |
headers = {
|
| 33 |
+
"Authorization": os.environ.get('api'), # Ideally, use os.environ.get('API_TOKEN') for security
|
| 34 |
"Content-Type": "application/json"
|
| 35 |
}
|
| 36 |
data = {
|
| 37 |
+
"temperature": 0.5,
|
| 38 |
"messages": [
|
| 39 |
+
{"role": "system", "content": "You are TuneChat"},
|
| 40 |
+
{"role": "user", "content": input_text}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
],
|
| 42 |
"model": "goliath-120b-16k-gptq",
|
| 43 |
+
"stream": True,
|
| 44 |
+
"max_tokens": 1000
|
| 45 |
}
|
| 46 |
+
response = requests.post(url, headers=headers, json=data, stream=True)
|
| 47 |
+
|
| 48 |
+
if response.encoding is None:
|
| 49 |
+
response.encoding = 'utf-8'
|
| 50 |
|
| 51 |
+
for line in response.iter_lines(decode_unicode=True):
|
| 52 |
+
if line:
|
| 53 |
+
print(line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|