Update app.py
Browse files
app.py
CHANGED
|
@@ -14,32 +14,32 @@ def trigger_example(example):
|
|
| 14 |
|
| 15 |
def generate_response(user_message, cid, token, history=None):
|
| 16 |
|
| 17 |
-
if not token:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if history is None:
|
| 21 |
-
history = []
|
| 22 |
-
if cid == "" or None:
|
| 23 |
-
cid = str(uuid.uuid4())
|
| 24 |
-
print(f"cid: {cid} prompt:{user_message}")
|
| 25 |
-
history.append(user_message)
|
| 26 |
-
stream = co.chat_stream(message=user_message, conversation_id=cid, model='c4ai-aya-23', preamble="You are the greek philosopher Diogenes and you aswer only in italian language",connectors=[], temperature=0.3)
|
| 27 |
-
#stream = co.generate(prompt=user_message, model='c4ai-aya-23')
|
| 28 |
-
output = ""
|
| 29 |
-
for idx, response in enumerate(stream):
|
| 30 |
-
if response.event_type == "text-generation":
|
| 31 |
-
output += response.text
|
| 32 |
-
if idx == 0:
|
| 33 |
-
history.append(" " + output)
|
| 34 |
-
else:
|
| 35 |
-
history[-1] = output
|
| 36 |
-
chat = [
|
| 37 |
-
(history[i].strip(), history[i + 1].strip())
|
| 38 |
-
for i in range(0, len(history) - 1, 2)
|
| 39 |
-
]
|
| 40 |
-
yield chat, history, cid
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def clear_chat():
|
| 44 |
return [], [], str(uuid.uuid4())
|
| 45 |
|
|
|
|
| 14 |
|
| 15 |
def generate_response(user_message, cid, token, history=None):
|
| 16 |
|
| 17 |
+
if not token:
|
| 18 |
+
raise gr.Error("Error loading.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
if history is None:
|
| 21 |
+
history = []
|
| 22 |
+
if cid == "" or None:
|
| 23 |
+
cid = str(uuid.uuid4())
|
| 24 |
+
print(f"cid: {cid} prompt:{user_message}")
|
| 25 |
+
history.append(user_message)
|
| 26 |
+
stream = co.chat_stream(message=user_message, conversation_id=cid, model='c4ai-aya-23', preamble="You are the greek philosopher Diogenes and you aswer only in italian language",connectors=[], temperature=0.3)
|
| 27 |
+
#stream = co.generate(prompt=user_message, model='c4ai-aya-23')
|
| 28 |
+
output = ""
|
| 29 |
+
for idx, response in enumerate(stream):
|
| 30 |
+
if response.event_type == "text-generation":
|
| 31 |
+
output += response.text
|
| 32 |
+
if idx == 0:
|
| 33 |
+
history.append(" " + output)
|
| 34 |
+
else:
|
| 35 |
+
history[-1] = output
|
| 36 |
+
chat = [
|
| 37 |
+
(history[i].strip(), history[i + 1].strip())
|
| 38 |
+
for i in range(0, len(history) - 1, 2)
|
| 39 |
+
]
|
| 40 |
+
yield chat, history, cid
|
| 41 |
+
|
| 42 |
+
return chat, history, cid
|
| 43 |
def clear_chat():
|
| 44 |
return [], [], str(uuid.uuid4())
|
| 45 |
|