Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
| 4 |
# Getting responses using the OpenAI API
|
| 5 |
-
def answer_chatgpt(api_key, message, history):
|
| 6 |
history = history or []
|
| 7 |
lista = list(sum(history, ()))
|
| 8 |
lista.append(message)
|
|
|
|
|
|
|
| 9 |
# OPENAI API KEY
|
| 10 |
openai.api_key = api_key
|
| 11 |
-
prompt = f"{message}"
|
| 12 |
response = openai.ChatCompletion.create(
|
| 13 |
-
model=
|
| 14 |
-
messages=
|
| 15 |
-
{"role": "user", "content": f"{prompt}"},
|
| 16 |
-
]
|
| 17 |
)
|
| 18 |
# Displaying the answer on the screen
|
| 19 |
answer = response["choices"][0]["message"]["content"]
|
| 20 |
history.append((message, answer))
|
|
|
|
| 21 |
return history, history
|
| 22 |
|
| 23 |
# User input
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
model_id = "gpt-3.5-turbo"
|
| 5 |
+
|
| 6 |
# Getting responses using the OpenAI API
|
| 7 |
+
def answer_chatgpt(api_key, message, history, conversation=[]):
|
| 8 |
history = history or []
|
| 9 |
lista = list(sum(history, ()))
|
| 10 |
lista.append(message)
|
| 11 |
+
prompt = f"{message}"
|
| 12 |
+
conversation.append({"role": "user", "content": f"{prompt}"})
|
| 13 |
# OPENAI API KEY
|
| 14 |
openai.api_key = api_key
|
|
|
|
| 15 |
response = openai.ChatCompletion.create(
|
| 16 |
+
model=model_id,
|
| 17 |
+
messages=conversation
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
# Displaying the answer on the screen
|
| 20 |
answer = response["choices"][0]["message"]["content"]
|
| 21 |
history.append((message, answer))
|
| 22 |
+
conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
|
| 23 |
return history, history
|
| 24 |
|
| 25 |
# User input
|