Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -171,6 +171,39 @@ def respond_claude_qna(
|
|
171 |
except Exception as e:
|
172 |
return f"예상치 못한 오류가 발생했습니다: {str(e)}"
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
#############################
|
175 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
176 |
#############################
|
@@ -419,6 +452,53 @@ with gr.Blocks() as demo:
|
|
419 |
outputs=deepseek_answer_output
|
420 |
)
|
421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
#############################
|
423 |
# 메인 실행부
|
424 |
#############################
|
|
|
171 |
except Exception as e:
|
172 |
return f"예상치 못한 오류가 발생했습니다: {str(e)}"
|
173 |
|
174 |
+
def respond_o1mini_qna(
|
175 |
+
question: str,
|
176 |
+
system_message: str,
|
177 |
+
max_tokens: int,
|
178 |
+
temperature: float
|
179 |
+
):
|
180 |
+
"""
|
181 |
+
o1-mini 모델을 이용해 한 번의 질문(question)에 대한 답변을 반환하는 함수.
|
182 |
+
o1-mini에서는 advanced setting 중 top_p 옵션은 지원하지 않으므로, 해당 옵션은 제거함.
|
183 |
+
"""
|
184 |
+
openai_token = os.getenv("OPENAI_TOKEN")
|
185 |
+
if not openai_token:
|
186 |
+
return "OpenAI API 토큰이 필요합니다."
|
187 |
+
|
188 |
+
openai.api_key = openai_token
|
189 |
+
|
190 |
+
messages = [
|
191 |
+
{"role": "system", "content": system_message},
|
192 |
+
{"role": "user", "content": question}
|
193 |
+
]
|
194 |
+
|
195 |
+
try:
|
196 |
+
response = openai.ChatCompletion.create(
|
197 |
+
model="o1-mini",
|
198 |
+
messages=messages,
|
199 |
+
max_tokens=max_tokens,
|
200 |
+
temperature=temperature,
|
201 |
+
)
|
202 |
+
assistant_message = response.choices[0].message['content']
|
203 |
+
return assistant_message
|
204 |
+
except Exception as e:
|
205 |
+
return f"오류가 발생했습니다: {str(e)}"
|
206 |
+
|
207 |
#############################
|
208 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
209 |
#############################
|
|
|
452 |
outputs=deepseek_answer_output
|
453 |
)
|
454 |
|
455 |
+
#################
|
456 |
+
# o1-mini 탭
|
457 |
+
#################
|
458 |
+
with gr.Tab("o1-mini"):
|
459 |
+
o1mini_input1 = gr.Textbox(label="입력1", lines=1)
|
460 |
+
o1mini_input2 = gr.Textbox(label="입력2", lines=1)
|
461 |
+
o1mini_input3 = gr.Textbox(label="입력3", lines=1)
|
462 |
+
o1mini_input4 = gr.Textbox(label="입력4", lines=1)
|
463 |
+
o1mini_input5 = gr.Textbox(label="입력5", lines=1)
|
464 |
+
|
465 |
+
o1mini_answer_output = gr.Textbox(label="결과", lines=5, interactive=False)
|
466 |
+
|
467 |
+
with gr.Accordion("고급 설정 (o1-mini)", open=False):
|
468 |
+
o1mini_system_message = gr.Textbox(
|
469 |
+
value="""반드시 한글로 답변할 것.
|
470 |
+
너는 o1-mini, OpenAI에서 개발한 경량 언어 모델이다.
|
471 |
+
내가 요구하는 것을 최대한 자세하고 정확하게 답변하라.
|
472 |
+
""",
|
473 |
+
label="System Message",
|
474 |
+
lines=3
|
475 |
+
)
|
476 |
+
o1mini_max_tokens = gr.Slider(minimum=100, maximum=4000, value=2000, step=100, label="Max Tokens")
|
477 |
+
o1mini_temperature = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.05, label="Temperature")
|
478 |
+
# o1-mini는 top_p 지원이 없으므로 해당 옵션은 UI에서 제외함
|
479 |
+
|
480 |
+
o1mini_submit_button = gr.Button("전송")
|
481 |
+
|
482 |
+
def merge_and_call_o1mini(i1, i2, i3, i4, i5, sys_msg, mt, temp):
|
483 |
+
question = " ".join([i1, i2, i3, i4, i5])
|
484 |
+
return respond_o1mini_qna(
|
485 |
+
question=question,
|
486 |
+
system_message=sys_msg,
|
487 |
+
max_tokens=mt,
|
488 |
+
temperature=temp
|
489 |
+
)
|
490 |
+
|
491 |
+
o1mini_submit_button.click(
|
492 |
+
fn=merge_and_call_o1mini,
|
493 |
+
inputs=[
|
494 |
+
o1mini_input1, o1mini_input2, o1mini_input3, o1mini_input4, o1mini_input5,
|
495 |
+
o1mini_system_message,
|
496 |
+
o1mini_max_tokens,
|
497 |
+
o1mini_temperature
|
498 |
+
],
|
499 |
+
outputs=o1mini_answer_output
|
500 |
+
)
|
501 |
+
|
502 |
#############################
|
503 |
# 메인 실행부
|
504 |
#############################
|