Spaces:
Sleeping
Sleeping
Commit
·
33ec9db
1
Parent(s):
c7a303b
openAI
Browse files
app.py
CHANGED
@@ -5,20 +5,25 @@ import openai
|
|
5 |
# openai.api_key = "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"
|
6 |
client = openai.OpenAI()
|
7 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
8 |
-
|
|
|
9 |
for u, b in history:
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
#input
|
14 |
resp = client.responses.create(
|
15 |
model="gpt-4.1-nano",
|
16 |
-
input=
|
17 |
temperature=temperature,
|
18 |
top_p=top_p,
|
19 |
max_output_tokens=max_tokens
|
20 |
)
|
21 |
reply = resp.output_text
|
|
|
22 |
history.append((message, reply))
|
23 |
|
24 |
return reply
|
|
|
5 |
# openai.api_key = "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"
|
6 |
client = openai.OpenAI()
|
7 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
8 |
+
|
9 |
+
messages = [{"role": "system", "content": system_message}]
|
10 |
for u, b in history:
|
11 |
+
if u:
|
12 |
+
messages.append({"role": "user", "content": u})
|
13 |
+
if b:
|
14 |
+
messages.append({"role": "assistant", "content": b})
|
15 |
+
messages.append({"role": "user", "content": message})
|
16 |
|
17 |
#input
|
18 |
resp = client.responses.create(
|
19 |
model="gpt-4.1-nano",
|
20 |
+
input=message,
|
21 |
temperature=temperature,
|
22 |
top_p=top_p,
|
23 |
max_output_tokens=max_tokens
|
24 |
)
|
25 |
reply = resp.output_text
|
26 |
+
|
27 |
history.append((message, reply))
|
28 |
|
29 |
return reply
|