Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -171,40 +171,6 @@ def respond_claude_qna(
|
|
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 |
-
):
|
181 |
-
"""
|
182 |
-
o3-mini 모델 대신, OpenAI의 새로운 API 클라이언트를 이용하여
|
183 |
-
"o1-preview" 모델로 한 번의 질문(question)에 대한 답변을 반환하는 함수.
|
184 |
-
"""
|
185 |
-
openai_token = os.getenv("OPENAI_TOKEN")
|
186 |
-
if not openai_token:
|
187 |
-
return "OpenAI API 토큰이 필요합니다."
|
188 |
-
|
189 |
-
try:
|
190 |
-
# 새 OpenAI 클라이언트를 사용
|
191 |
-
from openai import OpenAI
|
192 |
-
client = OpenAI(api_key=openai_token)
|
193 |
-
messages = [
|
194 |
-
{"role": "system", "content": system_message},
|
195 |
-
{"role": "user", "content": question}
|
196 |
-
]
|
197 |
-
completion = client.chat.completions.create(
|
198 |
-
model="o1-mini",
|
199 |
-
messages=messages,
|
200 |
-
max_tokens=max_tokens,
|
201 |
-
temperature=temperature,
|
202 |
-
top_p=top_p,
|
203 |
-
)
|
204 |
-
return completion.choices[0].message.content
|
205 |
-
except Exception as e:
|
206 |
-
return f"오류가 발생했습니다: {str(e)}"
|
207 |
-
|
208 |
#############################
|
209 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
210 |
#############################
|
@@ -310,55 +276,6 @@ with gr.Blocks() as demo:
|
|
310 |
outputs=chatgpt_answer_output
|
311 |
)
|
312 |
|
313 |
-
#################
|
314 |
-
# o3-mini 탭
|
315 |
-
#################
|
316 |
-
with gr.Tab("o3-mini"):
|
317 |
-
o3mini_input1 = gr.Textbox(label="입력1", lines=1)
|
318 |
-
o3mini_input2 = gr.Textbox(label="입력2", lines=1)
|
319 |
-
o3mini_input3 = gr.Textbox(label="입력3", lines=1)
|
320 |
-
o3mini_input4 = gr.Textbox(label="입력4", lines=1)
|
321 |
-
o3mini_input5 = gr.Textbox(label="입력5", lines=1)
|
322 |
-
|
323 |
-
o3mini_answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
|
324 |
-
|
325 |
-
with gr.Accordion("고급 설정 (o3-mini)", open=False):
|
326 |
-
o3mini_system_message = gr.Textbox(
|
327 |
-
value="""반드시 한글로 답변할 것.
|
328 |
-
너는 o3-mini 모델이다.
|
329 |
-
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
330 |
-
""",
|
331 |
-
label="System Message",
|
332 |
-
lines=3
|
333 |
-
)
|
334 |
-
o3mini_max_tokens = gr.Slider(minimum=100, maximum=4000, value=1500, step=100, label="Max Tokens")
|
335 |
-
o3mini_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.8, step=0.05, label="Temperature")
|
336 |
-
o3mini_top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-P")
|
337 |
-
|
338 |
-
o3mini_submit_button = gr.Button("전송")
|
339 |
-
|
340 |
-
def merge_and_call_o3mini(i1, i2, i3, i4, i5, sys_msg, mt, temp, top_p_):
|
341 |
-
question = " ".join([i1, i2, i3, i4, i5])
|
342 |
-
return respond_o3mini_qna(
|
343 |
-
question=question,
|
344 |
-
system_message=sys_msg,
|
345 |
-
max_tokens=mt,
|
346 |
-
temperature=temp,
|
347 |
-
top_p=top_p_
|
348 |
-
)
|
349 |
-
|
350 |
-
o3mini_submit_button.click(
|
351 |
-
fn=merge_and_call_o3mini,
|
352 |
-
inputs=[
|
353 |
-
o3mini_input1, o3mini_input2, o3mini_input3, o3mini_input4, o3mini_input5,
|
354 |
-
o3mini_system_message,
|
355 |
-
o3mini_max_tokens,
|
356 |
-
o3mini_temperature,
|
357 |
-
o3mini_top_p
|
358 |
-
],
|
359 |
-
outputs=o3mini_answer_output
|
360 |
-
)
|
361 |
-
|
362 |
#################
|
363 |
# Claude 탭
|
364 |
#################
|
|
|
171 |
except Exception as e:
|
172 |
return f"예상치 못한 오류가 발생했습니다: {str(e)}"
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
#############################
|
175 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
176 |
#############################
|
|
|
276 |
outputs=chatgpt_answer_output
|
277 |
)
|
278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
#################
|
280 |
# Claude 탭
|
281 |
#################
|