Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,11 @@ client = OpenAI(
|
|
| 9 |
)
|
| 10 |
|
| 11 |
def generate_response(message, history):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
history_openai_format
|
|
|
|
| 16 |
history_openai_format.append({"role": "user", "content": message})
|
| 17 |
|
| 18 |
completion = client.chat.completions.create(
|
|
@@ -23,12 +24,14 @@ def generate_response(message, history):
|
|
| 23 |
max_tokens=1024,
|
| 24 |
stream=True
|
| 25 |
)
|
| 26 |
-
|
| 27 |
response = ""
|
| 28 |
for chunk in completion:
|
| 29 |
if chunk.choices[0].delta.content is not None:
|
| 30 |
response += chunk.choices[0].delta.content
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
iface = gr.ChatInterface(
|
| 34 |
generate_response,
|
|
@@ -39,7 +42,8 @@ iface = gr.ChatInterface(
|
|
| 39 |
"Yapay zeka ve etik arasındaki ilişkiyi açıklayabilir misin?",
|
| 40 |
"Kuantum bilgisayarların geleceği hakkında ne düşünüyorsun?"
|
| 41 |
],
|
| 42 |
-
cache_examples=False
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
iface.launch()
|
|
|
|
| 9 |
)
|
| 10 |
|
| 11 |
def generate_response(message, history):
|
| 12 |
+
if history:
|
| 13 |
+
history_openai_format = history
|
| 14 |
+
else:
|
| 15 |
+
history_openai_format = []
|
| 16 |
+
|
| 17 |
history_openai_format.append({"role": "user", "content": message})
|
| 18 |
|
| 19 |
completion = client.chat.completions.create(
|
|
|
|
| 24 |
max_tokens=1024,
|
| 25 |
stream=True
|
| 26 |
)
|
| 27 |
+
|
| 28 |
response = ""
|
| 29 |
for chunk in completion:
|
| 30 |
if chunk.choices[0].delta.content is not None:
|
| 31 |
response += chunk.choices[0].delta.content
|
| 32 |
+
|
| 33 |
+
history_openai_format.append({"role": "assistant", "content": response})
|
| 34 |
+
return response, history_openai_format
|
| 35 |
|
| 36 |
iface = gr.ChatInterface(
|
| 37 |
generate_response,
|
|
|
|
| 42 |
"Yapay zeka ve etik arasındaki ilişkiyi açıklayabilir misin?",
|
| 43 |
"Kuantum bilgisayarların geleceği hakkında ne düşünüyorsun?"
|
| 44 |
],
|
| 45 |
+
cache_examples=False,
|
| 46 |
+
type='messages'
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|