Spaces:
Sleeping
Sleeping
Herman Scheepers commited on
Commit ·
61849d0
1
Parent(s): 9d1b90e
adding tray
Browse files
app.py
CHANGED
|
@@ -9,38 +9,6 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 9 |
TRAY_API_URL = "https://1591a0e5-d083-483b-a8b8-21fc282cdb21-api.trayapp.io/getResponse"
|
| 10 |
|
| 11 |
|
| 12 |
-
def respond_huggingface(
|
| 13 |
-
message,
|
| 14 |
-
history: list[tuple[str, str]],
|
| 15 |
-
system_message,
|
| 16 |
-
max_tokens,
|
| 17 |
-
temperature,
|
| 18 |
-
top_p,
|
| 19 |
-
):
|
| 20 |
-
messages = [{"role": "system", "content": system_message}]
|
| 21 |
-
|
| 22 |
-
for val in history:
|
| 23 |
-
if val[0]:
|
| 24 |
-
messages.append({"role": "user", "content": val[0]})
|
| 25 |
-
if val[1]:
|
| 26 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 27 |
-
|
| 28 |
-
messages.append({"role": "user", "content": message})
|
| 29 |
-
|
| 30 |
-
response = ""
|
| 31 |
-
|
| 32 |
-
for message in client.chat_completion(
|
| 33 |
-
messages,
|
| 34 |
-
max_tokens=max_tokens,
|
| 35 |
-
stream=True,
|
| 36 |
-
temperature=temperature,
|
| 37 |
-
top_p=top_p,
|
| 38 |
-
):
|
| 39 |
-
token = message.choices[0].delta.content
|
| 40 |
-
|
| 41 |
-
response += token
|
| 42 |
-
yield response
|
| 43 |
-
|
| 44 |
|
| 45 |
def respond_chatgpt(message, history, system_message, max_tokens, temperature, top_p):
|
| 46 |
messages = [{"role": "system", "content": system_message}]
|
|
@@ -56,15 +24,15 @@ def respond_chatgpt(message, history, system_message, max_tokens, temperature, t
|
|
| 56 |
|
| 57 |
# Call the Hugging Face model
|
| 58 |
response = ""
|
| 59 |
-
|
| 60 |
# Tray.io API call
|
| 61 |
try:
|
| 62 |
-
tray_response = requests.get(TRAY_API_URL, params={"
|
| 63 |
|
| 64 |
# Process Tray.io API response
|
| 65 |
if tray_response.status_code == 200:
|
| 66 |
tray_data = tray_response.json()
|
| 67 |
-
tray_message = tray_data.get("
|
| 68 |
response += f"\n\nTray.io Response: {tray_message}"
|
| 69 |
else:
|
| 70 |
response += "\n\nError: Failed to retrieve response from Tray.io."
|
|
|
|
| 9 |
TRAY_API_URL = "https://1591a0e5-d083-483b-a8b8-21fc282cdb21-api.trayapp.io/getResponse"
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def respond_chatgpt(message, history, system_message, max_tokens, temperature, top_p):
|
| 14 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 24 |
|
| 25 |
# Call the Hugging Face model
|
| 26 |
response = ""
|
| 27 |
+
|
| 28 |
# Tray.io API call
|
| 29 |
try:
|
| 30 |
+
tray_response = requests.get(TRAY_API_URL, params={"query": message})
|
| 31 |
|
| 32 |
# Process Tray.io API response
|
| 33 |
if tray_response.status_code == 200:
|
| 34 |
tray_data = tray_response.json()
|
| 35 |
+
tray_message = tray_data.get("message", "Tray.io did not return a response.")
|
| 36 |
response += f"\n\nTray.io Response: {tray_message}"
|
| 37 |
else:
|
| 38 |
response += "\n\nError: Failed to retrieve response from Tray.io."
|