Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
-
from gradio.components import ChatMessage
|
| 5 |
-
|
| 6 |
|
| 7 |
client = OpenAI(
|
| 8 |
base_url="https://integrate.api.nvidia.com/v1",
|
|
@@ -10,11 +8,11 @@ client = OpenAI(
|
|
| 10 |
)
|
| 11 |
|
| 12 |
def generate_response(message, history):
|
| 13 |
-
history_openai_format = []
|
| 14 |
if history:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
history_openai_format.append({"role": "user", "content": message})
|
| 19 |
|
| 20 |
completion = client.chat.completions.create(
|
|
@@ -32,8 +30,7 @@ def generate_response(message, history):
|
|
| 32 |
response += chunk.choices[0].delta.content
|
| 33 |
|
| 34 |
history_openai_format.append({"role": "assistant", "content": response})
|
| 35 |
-
|
| 36 |
-
return response, chat_history
|
| 37 |
|
| 38 |
iface = gr.ChatInterface(
|
| 39 |
generate_response,
|
|
@@ -45,7 +42,7 @@ iface = gr.ChatInterface(
|
|
| 45 |
"Kuantum bilgisayarların geleceği hakkında ne düşünüyorsun?"
|
| 46 |
],
|
| 47 |
cache_examples=False,
|
| 48 |
-
type='
|
| 49 |
)
|
| 50 |
|
| 51 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from openai import OpenAI
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
client = OpenAI(
|
| 6 |
base_url="https://integrate.api.nvidia.com/v1",
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
def generate_response(message, history):
|
|
|
|
| 11 |
if history:
|
| 12 |
+
history_openai_format = history
|
| 13 |
+
else:
|
| 14 |
+
history_openai_format = []
|
| 15 |
+
|
| 16 |
history_openai_format.append({"role": "user", "content": message})
|
| 17 |
|
| 18 |
completion = client.chat.completions.create(
|
|
|
|
| 30 |
response += chunk.choices[0].delta.content
|
| 31 |
|
| 32 |
history_openai_format.append({"role": "assistant", "content": response})
|
| 33 |
+
return response, history_openai_format
|
|
|
|
| 34 |
|
| 35 |
iface = gr.ChatInterface(
|
| 36 |
generate_response,
|
|
|
|
| 42 |
"Kuantum bilgisayarların geleceği hakkında ne düşünüyorsun?"
|
| 43 |
],
|
| 44 |
cache_examples=False,
|
| 45 |
+
type='messages'
|
| 46 |
)
|
| 47 |
|
| 48 |
iface.launch()
|