Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,19 +9,24 @@ API_URL = "https://api.openai.com/v1/chat/completions" #os.getenv("API_URL") + "
|
|
9 |
#Testing with my Open AI Key
|
10 |
OPENAI_API_KEY = os.getenv("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")
|
11 |
|
12 |
-
def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]):
|
|
|
|
|
|
|
13 |
|
14 |
payload = {
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
}
|
24 |
|
|
|
25 |
headers = {
|
26 |
"Content-Type": "application/json",
|
27 |
"Authorization": f"Bearer {openai_api_key}"
|
@@ -71,6 +76,9 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
71 |
if counter == 0:
|
72 |
counter+=1
|
73 |
continue
|
|
|
|
|
|
|
74 |
#counter+=1
|
75 |
# check whether each line is non-empty
|
76 |
if chunk.decode() :
|
@@ -87,12 +95,15 @@ def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[]
|
|
87 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
88 |
token_counter+=1
|
89 |
yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
|
90 |
-
|
|
|
|
|
|
|
91 |
|
92 |
def reset_textbox():
|
93 |
return gr.update(value='')
|
94 |
|
95 |
-
title = """<h1 align="center"
|
96 |
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
97 |
```
|
98 |
User: <utterance>
|
|
|
9 |
#Testing with my Open AI Key
|
10 |
OPENAI_API_KEY = os.getenv("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")
|
11 |
|
12 |
+
def predict(inputs, top_p, temperature, openai_api_key, chat_counter, chatbot=[], history=[]):
|
13 |
+
|
14 |
+
# μ¬μ©μμ μ
λ ₯μ λλ μ΄μ
μ€νμΌμ ν둬ννΈλ‘ λ³ν
|
15 |
+
narration_prompt = f"λμμμ μ¬μ©ν μ λ¬Έμ μΈ λλ μ΄μ
μ μμ±νμΈμ. μ
λ ₯: '{inputs}'"
|
16 |
|
17 |
payload = {
|
18 |
+
"model": "gpt-4-1106-preview",
|
19 |
+
"messages": [{"role": "system", "content": narration_prompt}],
|
20 |
+
"temperature": temperature,
|
21 |
+
"top_p": top_p,
|
22 |
+
"n": 1,
|
23 |
+
"stream": True,
|
24 |
+
"presence_penalty": 0,
|
25 |
+
"frequency_penalty": 0,
|
26 |
+
"max_tokens": 1000 # λλ μ΄μ
μ κΈΈμ΄λ₯Ό μ ν
|
27 |
}
|
28 |
|
29 |
+
|
30 |
headers = {
|
31 |
"Content-Type": "application/json",
|
32 |
"Authorization": f"Bearer {openai_api_key}"
|
|
|
76 |
if counter == 0:
|
77 |
counter+=1
|
78 |
continue
|
79 |
+
# λλ μ΄μ
μ κΈΈμ΄λ₯Ό 8μ€λ‘ μ ν
|
80 |
+
if len(history) >= 8:
|
81 |
+
break
|
82 |
#counter+=1
|
83 |
# check whether each line is non-empty
|
84 |
if chunk.decode() :
|
|
|
95 |
chat = [(history[i], history[i + 1]) for i in range(0, len(history) - 1, 2) ] # convert to tuples of list
|
96 |
token_counter+=1
|
97 |
yield chat, history, chat_counter # resembles {chatbot: chat, state: history}
|
98 |
+
|
99 |
+
|
100 |
+
return chat, history, chat_counter
|
101 |
+
|
102 |
|
103 |
def reset_textbox():
|
104 |
return gr.update(value='')
|
105 |
|
106 |
+
title = """<h1 align="center">κΈ μμ±</h1>"""
|
107 |
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
108 |
```
|
109 |
User: <utterance>
|