ginipick commited on
Commit
2a0f996
ยท
verified ยท
1 Parent(s): 5dfb15d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -147,7 +147,7 @@ def summarize_code(app_content: str) -> str:
147
 
148
  def analyze_code(app_content: str) -> str:
149
  system_message = (
150
- "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ๋‹ค์Œ ํ•ญ๋ชฉ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n"
151
  "A. ๋ฐฐ๊ฒฝ ๋ฐ ํ•„์š”์„ฑ\n"
152
  "B. ๊ธฐ๋Šฅ์  ํšจ์šฉ์„ฑ ๋ฐ ๊ฐ€์น˜\n"
153
  "C. ํŠน์žฅ์ \n"
@@ -162,38 +162,49 @@ def analyze_code(app_content: str) -> str:
162
  return f"๋ถ„์„ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
163
 
164
  def explain_usage(app_content: str) -> str:
165
- system_message = "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."
166
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
167
  try:
168
  return gemini_chat_completion(system_message, user_message, max_tokens=800, temperature=0.7)
169
  except Exception as e:
170
  return f"์‚ฌ์šฉ๋ฒ• ์„ค๋ช… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
171
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  def convert_chat_history(messages: List[Any]) -> List[Tuple[str, str]]:
173
  """
174
  ๋ฉ”์‹œ์ง€ ๋ชฉ๋ก์˜ ๊ฐ ํ•ญ๋ชฉ์ด ChatMessage ๊ฐ์ฒด๋ผ๋ฉด (user, assistant) ํŠœํ”Œ๋กœ,
175
  ์ด๋ฏธ ํŠœํ”Œ์ธ ๊ฒฝ์šฐ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
176
  """
 
177
  conv = []
178
  i = 0
179
- while i < len(messages):
180
- # ๋งŒ์•ฝ ์ด๋ฏธ ํŠœํ”Œ์ด๋ฉด ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ
181
- if isinstance(messages[i], tuple):
182
- conv.append(messages[i])
183
  i += 1
184
- # ๋งŒ์•ฝ ChatMessage ๊ฐ์ฒด๋ผ๋ฉด
185
- elif hasattr(messages[i], "role"):
186
- if messages[i].role == "user":
187
- user_text = messages[i].content
188
  bot_text = ""
189
- if i + 1 < len(messages) and hasattr(messages[i+1], "role") and messages[i+1].role == "assistant":
190
- bot_text = messages[i+1].content
191
  i += 2
192
  else:
193
  i += 1
194
  conv.append((user_text, bot_text))
195
  else:
196
- conv.append(("", messages[i].content))
197
  i += 1
198
  else:
199
  i += 1
 
147
 
148
  def analyze_code(app_content: str) -> str:
149
  system_message = (
150
+ "You are a deep thinking AI. You may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. ๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์„œ๋น„์Šค์˜ ํšจ์šฉ์„ฑ๊ณผ ํ™œ์šฉ ์ธก๋ฉด์—์„œ ๋‹ค์Œ ํ•ญ๋ชฉ์— ๋Œ€ํ•ด ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n"
151
  "A. ๋ฐฐ๊ฒฝ ๋ฐ ํ•„์š”์„ฑ\n"
152
  "B. ๊ธฐ๋Šฅ์  ํšจ์šฉ์„ฑ ๋ฐ ๊ฐ€์น˜\n"
153
  "C. ํŠน์žฅ์ \n"
 
162
  return f"๋ถ„์„ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
163
 
164
  def explain_usage(app_content: str) -> str:
165
+ system_message = "You are a deep thinking AI. You may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. ๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."
166
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
167
  try:
168
  return gemini_chat_completion(system_message, user_message, max_tokens=800, temperature=0.7)
169
  except Exception as e:
170
  return f"์‚ฌ์šฉ๋ฒ• ์„ค๋ช… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
171
 
172
+ def flatten_messages(messages: List[Any]) -> List[Any]:
173
+ """
174
+ ์ค‘์ฒฉ๋œ ๋ฉ”์‹œ์ง€ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ‰ํƒ„ํ™”ํ•ฉ๋‹ˆ๋‹ค.
175
+ """
176
+ flat = []
177
+ for item in messages:
178
+ if isinstance(item, list):
179
+ flat.extend(flatten_messages(item))
180
+ else:
181
+ flat.append(item)
182
+ return flat
183
+
184
  def convert_chat_history(messages: List[Any]) -> List[Tuple[str, str]]:
185
  """
186
  ๋ฉ”์‹œ์ง€ ๋ชฉ๋ก์˜ ๊ฐ ํ•ญ๋ชฉ์ด ChatMessage ๊ฐ์ฒด๋ผ๋ฉด (user, assistant) ํŠœํ”Œ๋กœ,
187
  ์ด๋ฏธ ํŠœํ”Œ์ธ ๊ฒฝ์šฐ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
188
  """
189
+ flat_messages = flatten_messages(messages)
190
  conv = []
191
  i = 0
192
+ while i < len(flat_messages):
193
+ if isinstance(flat_messages[i], tuple):
194
+ conv.append(flat_messages[i])
 
195
  i += 1
196
+ elif hasattr(flat_messages[i], "role"):
197
+ if flat_messages[i].role == "user":
198
+ user_text = flat_messages[i].content
 
199
  bot_text = ""
200
+ if i + 1 < len(flat_messages) and hasattr(flat_messages[i+1], "role") and flat_messages[i+1].role == "assistant":
201
+ bot_text = flat_messages[i+1].content
202
  i += 2
203
  else:
204
  i += 1
205
  conv.append((user_text, bot_text))
206
  else:
207
+ conv.append(("", flat_messages[i].content))
208
  i += 1
209
  else:
210
  i += 1