seawolf2357 commited on
Commit
b38c52a
Β·
verified Β·
1 Parent(s): af1856c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
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=[]): #repetition_penalty, top_k
 
 
 
13
 
14
  payload = {
15
- "model": "gpt-4-1106-preview",
16
- "messages": [{"role": "user", "content": f"{inputs}"}],
17
- "temperature" : 1.0,
18
- "top_p":1.0,
19
- "n" : 1,
20
- "stream": True,
21
- "presence_penalty":0,
22
- "frequency_penalty":0,
 
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">Lisa Chatbot</h1>"""
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>