Kims12 commited on
Commit
d4b4692
·
verified ·
1 Parent(s): 8a5592c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -1
app.py CHANGED
@@ -171,6 +171,42 @@ def respond_claude_qna(
171
  except Exception as e:
172
  return f"예상치 못한 오류가 발생했습니다: {str(e)}"
173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  #############################
175
  # [기본코드] UI 부분 - 수정/삭제 불가
176
  #############################
@@ -276,6 +312,58 @@ with gr.Blocks() as demo:
276
  outputs=chatgpt_answer_output
277
  )
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  #################
280
  # Claude 탭
281
  #################
@@ -288,7 +376,7 @@ with gr.Blocks() as demo:
288
  "claude-3-5-sonnet-20241022"
289
  ],
290
  label="모델 선택",
291
- value="claude-3-5-haiku-20241022" # 기본값 설정
292
  )
293
 
294
  claude_input1 = gr.Textbox(label="입력1", lines=1)
 
171
  except Exception as e:
172
  return f"예상치 못한 오류가 발생했습니다: {str(e)}"
173
 
174
+ def respond_o3mini_qna(
175
+ question: str,
176
+ system_message: str,
177
+ max_tokens: int,
178
+ temperature: float,
179
+ top_p: float,
180
+ reasoning_effort: str # 추가된 파라미터
181
+ ):
182
+ """
183
+ o3-mini 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
184
+ """
185
+ openai_token = os.getenv("OPENAI_TOKEN")
186
+ if not openai_token:
187
+ return "OpenAI API 토큰이 필요합니다."
188
+
189
+ openai.api_key = openai_token
190
+
191
+ messages = [
192
+ {"role": "system", "content": system_message},
193
+ {"role": "user", "content": question}
194
+ ]
195
+
196
+ try:
197
+ response = openai.ChatCompletion.create(
198
+ model="o3-mini",
199
+ reasoning_effort=reasoning_effort,
200
+ messages=messages,
201
+ max_tokens=max_tokens,
202
+ temperature=temperature,
203
+ top_p=top_p,
204
+ )
205
+ assistant_message = response.choices[0].message['content']
206
+ return assistant_message
207
+ except Exception as e:
208
+ return f"오류가 발생했습니다: {str(e)}"
209
+
210
  #############################
211
  # [기본코드] UI 부분 - 수정/삭제 불가
212
  #############################
 
312
  outputs=chatgpt_answer_output
313
  )
314
 
315
+ #################
316
+ # o3-mini 탭
317
+ #################
318
+ with gr.Tab("o3-mini"):
319
+ o3mini_input1 = gr.Textbox(label="입력1", lines=1)
320
+ o3mini_input2 = gr.Textbox(label="입력2", lines=1)
321
+ o3mini_input3 = gr.Textbox(label="입력3", lines=1)
322
+ o3mini_input4 = gr.Textbox(label="입력4", lines=1)
323
+ o3mini_input5 = gr.Textbox(label="입력5", lines=1)
324
+
325
+ o3mini_answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
326
+
327
+ with gr.Accordion("고급 설정 (o3-mini)", open=False):
328
+ o3mini_system_message = gr.Textbox(
329
+ value="""반드시 한글로 답변할 것.
330
+ 너는 o3-mini 모델이다.
331
+ 내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
332
+ """,
333
+ label="System Message",
334
+ lines=3
335
+ )
336
+ o3mini_max_tokens = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
337
+ o3mini_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
338
+ o3mini_top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P")
339
+ o3mini_reasoning_effort = gr.Radio(choices=["low", "medium", "high"], label="Reasoning Effort", value="medium")
340
+
341
+ o3mini_submit_button = gr.Button("전송")
342
+
343
+ def merge_and_call_o3mini(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_, reasoning_effort):
344
+ question = " ".join([i1, i2, i3, i4, i5])
345
+ return respond_o3mini_qna(
346
+ question=question,
347
+ system_message=sys_msg,
348
+ max_tokens=mt,
349
+ temperature=temp,
350
+ top_p=top_p_,
351
+ reasoning_effort=reasoning_effort
352
+ )
353
+
354
+ o3mini_submit_button.click(
355
+ fn=merge_and_call_o3mini,
356
+ inputs=[
357
+ o3mini_input1, o3mini_input2, o3mini_input3, o3mini_input4, o3mini_input5,
358
+ o3mini_system_message,
359
+ o3mini_max_tokens,
360
+ o3mini_temperature,
361
+ o3mini_top_p,
362
+ o3mini_reasoning_effort
363
+ ],
364
+ outputs=o3mini_answer_output
365
+ )
366
+
367
  #################
368
  # Claude 탭
369
  #################
 
376
  "claude-3-5-sonnet-20241022"
377
  ],
378
  label="모델 선택",
379
+ value="claude-3-5-sonnet-20241022" # 기본값 설정
380
  )
381
 
382
  claude_input1 = gr.Textbox(label="입력1", lines=1)