seawolf2357 commited on
Commit
25d9b00
ยท
verified ยท
1 Parent(s): cc53f2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -835,7 +835,7 @@ def deploy_to_vercel(code: str):
835
 
836
 
837
  # ํ”„๋กฌํ”„ํŠธ ์ฆ๊ฐ• ํ•จ์ˆ˜ ์ˆ˜์ •
838
- async def boost_prompt(prompt: str) -> str:
839
  if not prompt:
840
  return ""
841
 
@@ -857,16 +857,13 @@ async def boost_prompt(prompt: str) -> str:
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:
@@ -877,7 +874,7 @@ async def boost_prompt(prompt: str) -> str:
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},
@@ -895,17 +892,15 @@ async def boost_prompt(prompt: str) -> str:
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()
 
835
 
836
 
837
  # ํ”„๋กฌํ”„ํŠธ ์ฆ๊ฐ• ํ•จ์ˆ˜ ์ˆ˜์ •
838
+ def boost_prompt(prompt: str) -> str:
839
  if not prompt:
840
  return ""
841
 
 
857
  try:
858
  # Claude API ์‹œ๋„
859
  try:
860
+ response = claude_client.messages.create(
 
 
 
 
 
861
  model="claude-3-5-sonnet-20241022",
862
  max_tokens=2000,
863
+ messages=[{
864
+ "role": "user",
865
+ "content": f"๋‹ค์Œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ถ„์„ํ•˜๊ณ  ์ฆ๊ฐ•ํ•˜์‹œ์˜ค: {prompt}"
866
+ }]
867
  )
868
 
869
  if hasattr(response, 'content') and len(response.content) > 0:
 
874
  print(f"Claude API ์—๋Ÿฌ, OpenAI๋กœ ์ „ํ™˜: {str(claude_error)}")
875
 
876
  # OpenAI API ์‹œ๋„
877
+ completion = openai_client.chat.completions.create(
878
  model="gpt-4",
879
  messages=[
880
  {"role": "system", "content": boost_system_prompt},
 
892
  print(f"ํ”„๋กฌํ”„ํŠธ ์ฆ๊ฐ• ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
893
  return prompt # ์˜ค๋ฅ˜ ๋ฐœ์ƒ์‹œ ์›๋ณธ ํ”„๋กฌํ”„ํŠธ ๋ฐ˜ํ™˜
894
 
895
+ # Boost ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
896
  def handle_boost(prompt: str):
897
  try:
898
+ boosted_prompt = boost_prompt(prompt)
 
899
  return boosted_prompt, gr.update(active_key="empty")
900
  except Exception as e:
901
  print(f"Boost ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜: {str(e)}")
902
  return prompt, gr.update(active_key="empty")
903
 
 
904
 
905
  # Demo ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
906
  demo_instance = Demo()