Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,26 +4,23 @@ from openai import OpenAI
|
|
4 |
BASE_URL = "https://w0xtwbf2fdxe1q-8000.proxy.runpod.net/v1"
|
5 |
API_KEY="SOMEHOW"
|
6 |
|
7 |
-
|
8 |
# Create an OpenAI client to interact with the API server
|
9 |
client = OpenAI(
|
10 |
base_url=BASE_URL,
|
11 |
api_key=API_KEY
|
12 |
)
|
13 |
|
14 |
-
|
15 |
def predict(message, history):
|
16 |
# Convert chat history to OpenAI format
|
17 |
history_openai_format = [{
|
18 |
"role": "system",
|
19 |
"content": "Tu es un excellent assistant IA développé par WAY2CALL pour faire des évaluations en JSON des audios transcrits."
|
20 |
}]
|
21 |
-
for human, assistant in history:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
"content": assistant
|
26 |
-
})
|
27 |
history_openai_format.append({"role": "user", "content": message})
|
28 |
|
29 |
# Create a chat completion request and send it to the API server
|
@@ -40,6 +37,5 @@ def predict(message, history):
|
|
40 |
partial_message += (chunk.choices[0].delta.content or "")
|
41 |
yield partial_message
|
42 |
|
43 |
-
|
44 |
# Create and launch a chat interface with Gradio
|
45 |
gr.ChatInterface(predict).queue().launch()
|
|
|
4 |
BASE_URL = "https://w0xtwbf2fdxe1q-8000.proxy.runpod.net/v1"
|
5 |
API_KEY="SOMEHOW"
|
6 |
|
|
|
7 |
# Create an OpenAI client to interact with the API server
|
8 |
client = OpenAI(
|
9 |
base_url=BASE_URL,
|
10 |
api_key=API_KEY
|
11 |
)
|
12 |
|
|
|
13 |
def predict(message, history):
|
14 |
# Convert chat history to OpenAI format
|
15 |
history_openai_format = [{
|
16 |
"role": "system",
|
17 |
"content": "Tu es un excellent assistant IA développé par WAY2CALL pour faire des évaluations en JSON des audios transcrits."
|
18 |
}]
|
19 |
+
for i, (human, assistant) in enumerate(history):
|
20 |
+
if i % 2 == 0:
|
21 |
+
history_openai_format.append({"role": "user", "content": human})
|
22 |
+
else:
|
23 |
+
history_openai_format.append({"role": "assistant", "content": assistant})
|
|
|
24 |
history_openai_format.append({"role": "user", "content": message})
|
25 |
|
26 |
# Create a chat completion request and send it to the API server
|
|
|
37 |
partial_message += (chunk.choices[0].delta.content or "")
|
38 |
yield partial_message
|
39 |
|
|
|
40 |
# Create and launch a chat interface with Gradio
|
41 |
gr.ChatInterface(predict).queue().launch()
|