Spaces:
Runtime error
Runtime error
update to together demo
Browse files
app.py
CHANGED
|
@@ -9,6 +9,12 @@ API_URL = "https://api.openai.com/v1/chat/completions"
|
|
| 9 |
#Streaming endpoint for OPENCHATKIT
|
| 10 |
API_URL_TGTHR = os.getenv('API_URL_TGTHR')
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
#Predict function for CHATGPT
|
| 13 |
def predict_chatgpt(inputs, top_p_chatgpt, temperature_chatgpt, openai_api_key, chat_counter_chatgpt, chatbot_chatgpt=[], history=[]):
|
| 14 |
#Define payload and header for chatgpt API
|
|
@@ -86,6 +92,7 @@ def predict_chatgpt(inputs, top_p_chatgpt, temperature_chatgpt, openai_api_key,
|
|
| 86 |
token_counter+=1
|
| 87 |
yield chat, history, chat_counter_chatgpt # this resembles {chatbot: chat, state: history}
|
| 88 |
|
|
|
|
| 89 |
#Predict function for OPENCHATKIT
|
| 90 |
def predict_together(model: str,
|
| 91 |
inputs: str,
|
|
@@ -101,6 +108,8 @@ def predict_together(model: str,
|
|
| 101 |
# debug
|
| 102 |
#print(f"^^client is - {client}")
|
| 103 |
user_name, assistant_name = "<human>:", "<bot>:"
|
|
|
|
|
|
|
| 104 |
|
| 105 |
history.append(inputs)
|
| 106 |
|
|
@@ -110,17 +119,17 @@ def predict_together(model: str,
|
|
| 110 |
|
| 111 |
if not user_data.startswith(user_name):
|
| 112 |
user_data = user_name + user_data
|
| 113 |
-
if not model_data.startswith("\n
|
| 114 |
-
model_data = "\n
|
| 115 |
|
| 116 |
-
past.append(user_data + model_data + "\n
|
| 117 |
|
| 118 |
if not inputs.startswith(user_name):
|
| 119 |
inputs = user_name + inputs
|
| 120 |
|
| 121 |
-
total_inputs = "".join(past) + inputs + "\n
|
| 122 |
# truncate total_inputs
|
| 123 |
-
total_inputs = total_inputs[-1000:]
|
| 124 |
|
| 125 |
partial_words = ""
|
| 126 |
|
|
|
|
| 9 |
#Streaming endpoint for OPENCHATKIT
|
| 10 |
API_URL_TGTHR = os.getenv('API_URL_TGTHR')
|
| 11 |
|
| 12 |
+
openchat_preprompt = (
|
| 13 |
+
"\n<human>: Hi!\n<bot>: My name is Bot, model version is 0.15, part of an open-source kit for "
|
| 14 |
+
"fine-tuning new bots! I was created by Together, LAION, and Ontocord.ai and the open-source "
|
| 15 |
+
"community. I am not human, not evil and not alive, and thus have no thoughts and feelings, "
|
| 16 |
+
"but I am programmed to be helpful, polite, honest, and friendly.\n")
|
| 17 |
+
|
| 18 |
#Predict function for CHATGPT
|
| 19 |
def predict_chatgpt(inputs, top_p_chatgpt, temperature_chatgpt, openai_api_key, chat_counter_chatgpt, chatbot_chatgpt=[], history=[]):
|
| 20 |
#Define payload and header for chatgpt API
|
|
|
|
| 92 |
token_counter+=1
|
| 93 |
yield chat, history, chat_counter_chatgpt # this resembles {chatbot: chat, state: history}
|
| 94 |
|
| 95 |
+
|
| 96 |
#Predict function for OPENCHATKIT
|
| 97 |
def predict_together(model: str,
|
| 98 |
inputs: str,
|
|
|
|
| 108 |
# debug
|
| 109 |
#print(f"^^client is - {client}")
|
| 110 |
user_name, assistant_name = "<human>:", "<bot>:"
|
| 111 |
+
preprompt = openchat_preprompt
|
| 112 |
+
sep = '\n'
|
| 113 |
|
| 114 |
history.append(inputs)
|
| 115 |
|
|
|
|
| 119 |
|
| 120 |
if not user_data.startswith(user_name):
|
| 121 |
user_data = user_name + user_data
|
| 122 |
+
if not model_data.startswith("\n" + assistant_name):
|
| 123 |
+
model_data = "\n" + assistant_name + model_data
|
| 124 |
|
| 125 |
+
past.append(user_data + model_data.rstrip() + "\n")
|
| 126 |
|
| 127 |
if not inputs.startswith(user_name):
|
| 128 |
inputs = user_name + inputs
|
| 129 |
|
| 130 |
+
total_inputs = preprompt + "".join(past) + inputs + "\n" + assistant_name.rstrip()
|
| 131 |
# truncate total_inputs
|
| 132 |
+
#total_inputs = total_inputs[-1000:]
|
| 133 |
|
| 134 |
partial_words = ""
|
| 135 |
|