Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,8 @@ import os
|
|
5 |
OPENAI_API_KEY = os.getenv("API_KEY")
|
6 |
API_URL = os.getenv("BASE_URL")
|
7 |
|
8 |
-
|
|
|
9 |
headers = {
|
10 |
'Content-Type': 'application/json',
|
11 |
'Authorization': f'Bearer {OPENAI_API_KEY}',
|
@@ -13,21 +14,23 @@ def generate_response(prompt):
|
|
13 |
|
14 |
data = {
|
15 |
'model': 'gpt-3.5-turbo',
|
16 |
-
'
|
17 |
'max_tokens': 150,
|
18 |
}
|
19 |
|
20 |
response = requests.post(API_URL, json=data, headers=headers)
|
21 |
response_data = response.json()
|
22 |
-
generated_text = response_data['choices'][0]['
|
23 |
|
24 |
return generated_text
|
25 |
|
26 |
iface = gr.Interface(
|
27 |
fn=generate_response,
|
28 |
-
inputs=gr.Textbox(),
|
29 |
outputs=gr.Textbox(),
|
30 |
live=True,
|
|
|
|
|
31 |
)
|
32 |
|
33 |
iface.launch()
|
|
|
5 |
OPENAI_API_KEY = os.getenv("API_KEY")
|
6 |
API_URL = os.getenv("BASE_URL")
|
7 |
|
8 |
+
# Функция для генерации ответов на основе диалога
|
9 |
+
def generate_response(dialog):
|
10 |
headers = {
|
11 |
'Content-Type': 'application/json',
|
12 |
'Authorization': f'Bearer {OPENAI_API_KEY}',
|
|
|
14 |
|
15 |
data = {
|
16 |
'model': 'gpt-3.5-turbo',
|
17 |
+
'messages': [{'role': 'system', 'content': 'You are a helpful assistant.'}] + dialog,
|
18 |
'max_tokens': 150,
|
19 |
}
|
20 |
|
21 |
response = requests.post(API_URL, json=data, headers=headers)
|
22 |
response_data = response.json()
|
23 |
+
generated_text = response_data['choices'][0]['message']['content'].strip()
|
24 |
|
25 |
return generated_text
|
26 |
|
27 |
iface = gr.Interface(
|
28 |
fn=generate_response,
|
29 |
+
inputs=gr.Textbox(prompt="You:"),
|
30 |
outputs=gr.Textbox(),
|
31 |
live=True,
|
32 |
+
title="Chat with GPT-3.5-turbo",
|
33 |
+
layout="vertical",
|
34 |
)
|
35 |
|
36 |
iface.launch()
|