Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -181,7 +181,7 @@ def explain_usage(app_content: str):
|
|
181 |
"You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. "
|
182 |
"๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ๋ง์น ํ๋ฉด์ ๋ณด๋ ๊ฒ์ฒ๋ผ ์ฌ์ฉ๋ฒ์ ์์ธํ ์ค๋ช
ํด์ฃผ์ธ์. Markdown ํ์์ผ๋ก ์ถ๋ ฅํ์ธ์."
|
183 |
)
|
184 |
-
user_msg = f"๋ค์ Python
|
185 |
try:
|
186 |
return gemini_chat_completion(system_msg, user_msg, max_tokens=800, temperature=0.7)
|
187 |
except Exception as e:
|
@@ -189,12 +189,19 @@ def explain_usage(app_content: str):
|
|
189 |
|
190 |
def stream_gemini_response(user_message: str, conversation_state: List[ChatMessage]) -> Iterator[List[ChatMessage]]:
|
191 |
"""
|
192 |
-
Gemini์ ์คํธ๋ฆฌ๋ฐ ์์ฒญ.
|
193 |
-
user_message๊ฐ ๋น์ด ์์ผ๋ฉด,
|
194 |
"""
|
195 |
if not user_message.strip():
|
196 |
-
#
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
|
199 |
print(f"\n=== New Request ===\nUser message: {user_message}")
|
200 |
chat_history = format_chat_history(conversation_state)
|
@@ -266,7 +273,7 @@ def stream_gemini_response(user_message: str, conversation_state: List[ChatMessa
|
|
266 |
|
267 |
def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, str]]:
|
268 |
"""
|
269 |
-
ChatMessage ๋ฆฌ์คํธ -> [{"role":"
|
270 |
"""
|
271 |
output = []
|
272 |
for msg in messages:
|
@@ -275,7 +282,6 @@ def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, s
|
|
275 |
|
276 |
def user_submit_message(msg: str, conversation_state: List[ChatMessage]):
|
277 |
conversation_state.append(ChatMessage(role="user", content=msg))
|
278 |
-
# ์
๋ ฅ์ฐฝ ๋น์
|
279 |
return "", conversation_state
|
280 |
|
281 |
def respond_wrapper(message: str, conversation_state: List[ChatMessage], max_tokens, temperature, top_p):
|
@@ -321,10 +327,11 @@ def create_ui():
|
|
321 |
with gr.TabItem("AI ์ฝ๋์ฑ"):
|
322 |
gr.Markdown("## ์์ ๋ฅผ ์
๋ ฅ ๋๋ ์์ค ์ฝ๋๋ฅผ ๋ถ์ฌ๋ฃ๊ณ ์ง๋ฌธํ์ธ์")
|
323 |
|
|
|
324 |
chatbot = gr.Chatbot(
|
325 |
label="๋ํ",
|
326 |
height=400,
|
327 |
-
type="messages"
|
328 |
)
|
329 |
|
330 |
msg = gr.Textbox(
|
|
|
181 |
"You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. "
|
182 |
"๋น์ ์ Python ์ฝ๋๋ฅผ ๋ถ์ํ์ฌ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํ๋ AI ์กฐ์์
๋๋ค. ์ฃผ์ด์ง ์ฝ๋๋ฅผ ๋ฐํ์ผ๋ก ๋ง์น ํ๋ฉด์ ๋ณด๋ ๊ฒ์ฒ๋ผ ์ฌ์ฉ๋ฒ์ ์์ธํ ์ค๋ช
ํด์ฃผ์ธ์. Markdown ํ์์ผ๋ก ์ถ๋ ฅํ์ธ์."
|
183 |
)
|
184 |
+
user_msg = f"๋ค์ Python ์ฝ๋๋ฅผ ์ฌ์ฉ๋ฒ์ ์ค๋ช
ํด์ฃผ์ธ์:\n\n{app_content}"
|
185 |
try:
|
186 |
return gemini_chat_completion(system_msg, user_msg, max_tokens=800, temperature=0.7)
|
187 |
except Exception as e:
|
|
|
189 |
|
190 |
def stream_gemini_response(user_message: str, conversation_state: List[ChatMessage]) -> Iterator[List[ChatMessage]]:
|
191 |
"""
|
192 |
+
Gemini์ ์คํธ๋ฆฌ๋ฐ ์์ฒญ.
|
193 |
+
- user_message๊ฐ ๋น์ด ์์ผ๋ฉด, ์ต์ํ์ ์๋ด ๋ฉ์์ง๋ฅผ assistant๋ก ์ถ๊ฐํ๊ณ yield ํ ์ข
๋ฃ
|
194 |
"""
|
195 |
if not user_message.strip():
|
196 |
+
# ๋น ์
๋ ฅ ์ฒ๋ฆฌ: ์๋ด ๋ฉ์์ง ํ์
|
197 |
+
conversation_state.append(
|
198 |
+
ChatMessage(
|
199 |
+
role="assistant",
|
200 |
+
content="์
๋ ฅ์ด ์์ต๋๋ค. ์ง๋ฌธ์ ์์ฑํด์ฃผ์ธ์!"
|
201 |
+
)
|
202 |
+
)
|
203 |
+
yield conversation_state
|
204 |
+
return
|
205 |
|
206 |
print(f"\n=== New Request ===\nUser message: {user_message}")
|
207 |
chat_history = format_chat_history(conversation_state)
|
|
|
273 |
|
274 |
def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, str]]:
|
275 |
"""
|
276 |
+
ChatMessage ๋ฆฌ์คํธ -> [{"role":"assistant"/"user", "content":"..."}]
|
277 |
"""
|
278 |
output = []
|
279 |
for msg in messages:
|
|
|
282 |
|
283 |
def user_submit_message(msg: str, conversation_state: List[ChatMessage]):
|
284 |
conversation_state.append(ChatMessage(role="user", content=msg))
|
|
|
285 |
return "", conversation_state
|
286 |
|
287 |
def respond_wrapper(message: str, conversation_state: List[ChatMessage], max_tokens, temperature, top_p):
|
|
|
327 |
with gr.TabItem("AI ์ฝ๋์ฑ"):
|
328 |
gr.Markdown("## ์์ ๋ฅผ ์
๋ ฅ ๋๋ ์์ค ์ฝ๋๋ฅผ ๋ถ์ฌ๋ฃ๊ณ ์ง๋ฌธํ์ธ์")
|
329 |
|
330 |
+
# Chatbot: type="messages"
|
331 |
chatbot = gr.Chatbot(
|
332 |
label="๋ํ",
|
333 |
height=400,
|
334 |
+
type="messages"
|
335 |
)
|
336 |
|
337 |
msg = gr.Textbox(
|