Spaces:
Running
Running
Update app.py
Browse files
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(
|
180 |
-
|
181 |
-
|
182 |
-
conv.append(messages[i])
|
183 |
i += 1
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
user_text = messages[i].content
|
188 |
bot_text = ""
|
189 |
-
if i + 1 < len(
|
190 |
-
bot_text =
|
191 |
i += 2
|
192 |
else:
|
193 |
i += 1
|
194 |
conv.append((user_text, bot_text))
|
195 |
else:
|
196 |
-
conv.append(("",
|
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
|