Update app.py
Browse files
app.py
CHANGED
@@ -857,22 +857,27 @@ async def boost_prompt(prompt: str) -> str:
|
|
857 |
try:
|
858 |
# Claude API ์๋
|
859 |
try:
|
|
|
|
|
|
|
|
|
|
|
860 |
response = await claude_client.messages.create(
|
861 |
model="claude-3-5-sonnet-20241022",
|
862 |
max_tokens=2000,
|
863 |
system=boost_system_prompt,
|
864 |
-
messages=
|
865 |
-
"role": "user",
|
866 |
-
"content": f"๋ค์ ํ๋กฌํํธ๋ฅผ ๋ถ์ํ๊ณ ์ฆ๊ฐํ์์ค: {prompt}"
|
867 |
-
}]
|
868 |
)
|
869 |
-
|
|
|
|
|
|
|
870 |
|
871 |
except Exception as claude_error:
|
872 |
print(f"Claude API ์๋ฌ, OpenAI๋ก ์ ํ: {str(claude_error)}")
|
873 |
|
874 |
# OpenAI API ์๋
|
875 |
-
|
876 |
model="gpt-4",
|
877 |
messages=[
|
878 |
{"role": "system", "content": boost_system_prompt},
|
@@ -881,23 +886,26 @@ async def boost_prompt(prompt: str) -> str:
|
|
881 |
max_tokens=2000,
|
882 |
temperature=0.7
|
883 |
)
|
884 |
-
|
|
|
|
|
|
|
885 |
|
886 |
except Exception as e:
|
887 |
print(f"ํ๋กฌํํธ ์ฆ๊ฐ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
888 |
return prompt # ์ค๋ฅ ๋ฐ์์ ์๋ณธ ํ๋กฌํํธ ๋ฐํ
|
889 |
|
890 |
# Boost ๋ฒํผ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
891 |
-
|
892 |
try:
|
893 |
-
|
|
|
894 |
return boosted_prompt, gr.update(active_key="empty")
|
895 |
except Exception as e:
|
896 |
print(f"Boost ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
897 |
return prompt, gr.update(active_key="empty")
|
898 |
|
899 |
|
900 |
-
|
901 |
|
902 |
# Demo ์ธ์คํด์ค ์์ฑ
|
903 |
demo_instance = Demo()
|
@@ -1094,7 +1102,9 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
1094 |
fn=handle_boost,
|
1095 |
inputs=[input],
|
1096 |
outputs=[input, state_tab]
|
1097 |
-
)
|
|
|
|
|
1098 |
|
1099 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
1100 |
deploy_btn.click(
|
|
|
857 |
try:
|
858 |
# Claude API ์๋
|
859 |
try:
|
860 |
+
messages = [{
|
861 |
+
"role": "user",
|
862 |
+
"content": f"๋ค์ ํ๋กฌํํธ๋ฅผ ๋ถ์ํ๊ณ ์ฆ๊ฐํ์์ค: {prompt}"
|
863 |
+
}]
|
864 |
+
|
865 |
response = await claude_client.messages.create(
|
866 |
model="claude-3-5-sonnet-20241022",
|
867 |
max_tokens=2000,
|
868 |
system=boost_system_prompt,
|
869 |
+
messages=messages
|
|
|
|
|
|
|
870 |
)
|
871 |
+
|
872 |
+
if hasattr(response, 'content') and len(response.content) > 0:
|
873 |
+
return response.content[0].text
|
874 |
+
raise Exception("Claude API ์๋ต ํ์ ์ค๋ฅ")
|
875 |
|
876 |
except Exception as claude_error:
|
877 |
print(f"Claude API ์๋ฌ, OpenAI๋ก ์ ํ: {str(claude_error)}")
|
878 |
|
879 |
# OpenAI API ์๋
|
880 |
+
completion = await openai_client.chat.completions.create(
|
881 |
model="gpt-4",
|
882 |
messages=[
|
883 |
{"role": "system", "content": boost_system_prompt},
|
|
|
886 |
max_tokens=2000,
|
887 |
temperature=0.7
|
888 |
)
|
889 |
+
|
890 |
+
if completion.choices and len(completion.choices) > 0:
|
891 |
+
return completion.choices[0].message.content
|
892 |
+
raise Exception("OpenAI API ์๋ต ํ์ ์ค๋ฅ")
|
893 |
|
894 |
except Exception as e:
|
895 |
print(f"ํ๋กฌํํธ ์ฆ๊ฐ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
896 |
return prompt # ์ค๋ฅ ๋ฐ์์ ์๋ณธ ํ๋กฌํํธ ๋ฐํ
|
897 |
|
898 |
# Boost ๋ฒํผ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
899 |
+
def handle_boost(prompt: str):
|
900 |
try:
|
901 |
+
# asyncio.run()์ ์ฌ์ฉํ์ฌ ๋น๋๊ธฐ ํจ์ ์คํ
|
902 |
+
boosted_prompt = asyncio.run(boost_prompt(prompt))
|
903 |
return boosted_prompt, gr.update(active_key="empty")
|
904 |
except Exception as e:
|
905 |
print(f"Boost ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}")
|
906 |
return prompt, gr.update(active_key="empty")
|
907 |
|
908 |
|
|
|
909 |
|
910 |
# Demo ์ธ์คํด์ค ์์ฑ
|
911 |
demo_instance = Demo()
|
|
|
1102 |
fn=handle_boost,
|
1103 |
inputs=[input],
|
1104 |
outputs=[input, state_tab]
|
1105 |
+
)
|
1106 |
+
|
1107 |
+
|
1108 |
|
1109 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์์
|
1110 |
deploy_btn.click(
|