Update app.py
Browse files
app.py
CHANGED
|
@@ -28,33 +28,31 @@ def chatbot_api(input_text):
|
|
| 28 |
# Your existing setup for API call
|
| 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 |
-
{"role": "system", "content": "You are DJ JINX, a Drum'n'Bass DJ
|
| 38 |
{"role": "user", "content": input_text}
|
| 39 |
],
|
| 40 |
"model": "goliath-120b-16k-gptq",
|
| 41 |
-
"stream": False, #
|
| 42 |
-
"max_tokens":
|
| 43 |
}
|
| 44 |
response = requests.post(url, headers=headers, json=data)
|
| 45 |
response_json = response.json()
|
| 46 |
-
print(response_json)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
full_content = response_json['choices'][0]['content']
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
filtered_response = "No response received from the API."
|
| 54 |
|
|
|
|
| 55 |
send_to_corrade(filtered_response)
|
| 56 |
return filtered_response
|
| 57 |
-
|
| 58 |
# Example usage with Gradio
|
| 59 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
| 60 |
iface.launch()
|
|
|
|
| 28 |
# Your existing setup for API call
|
| 29 |
url = "https://chat.tune.app/api/chat/completions"
|
| 30 |
headers = {
|
| 31 |
+
"Authorization": os.environ.get('api'), # Ensure this is set
|
| 32 |
"Content-Type": "application/json"
|
| 33 |
}
|
| 34 |
data = {
|
| 35 |
+
"temperature": 0.5,
|
| 36 |
"messages": [
|
| 37 |
+
{"role": "system", "content": "You are DJ JINX, a Drum'n'Bass DJ from Canada. DJ JINX RESPONDS: "},
|
| 38 |
{"role": "user", "content": input_text}
|
| 39 |
],
|
| 40 |
"model": "goliath-120b-16k-gptq",
|
| 41 |
+
"stream": False, # Adjusted for a direct response
|
| 42 |
+
"max_tokens": 1000
|
| 43 |
}
|
| 44 |
response = requests.post(url, headers=headers, json=data)
|
| 45 |
response_json = response.json()
|
|
|
|
| 46 |
|
| 47 |
+
# Corrected part: Accessing the 'content' within 'message'
|
| 48 |
+
try:
|
| 49 |
+
full_content = response_json['choices'][0]['message']['content']
|
| 50 |
+
except (KeyError, IndexError):
|
| 51 |
+
full_content = "Error: The expected response format has changed or is missing."
|
|
|
|
| 52 |
|
| 53 |
+
filtered_response = filter_non_alphanumeric(full_content)
|
| 54 |
send_to_corrade(filtered_response)
|
| 55 |
return filtered_response
|
|
|
|
| 56 |
# Example usage with Gradio
|
| 57 |
iface = gr.Interface(fn=chatbot_api, inputs="text", outputs="text")
|
| 58 |
iface.launch()
|