Update app.py
Browse files
app.py
CHANGED
@@ -138,9 +138,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
138 |
if not message:
|
139 |
return "", history
|
140 |
|
141 |
-
|
142 |
system_prefix = """μ λ μ¬λ¬λΆμ μΉκ·Όνκ³ μ§μ μΈ AI μ΄μμ€ν΄νΈ 'GiniGEN'μ
λλ€.. λ€μκ³Ό κ°μ μμΉμΌλ‘ μν΅νκ² μ΅λλ€:
|
143 |
-
|
144 |
1. π€ μΉκ·Όνκ³ κ³΅κ°μ μΈ νλλ‘ λν
|
145 |
2. π‘ λͺ
ννκ³ μ΄ν΄νκΈ° μ¬μ΄ μ€λͺ
μ 곡
|
146 |
3. π― μ§λ¬Έμ μλλ₯Ό μ νν νμ
νμ¬ λ§μΆ€ν λ΅λ³
|
@@ -151,6 +149,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
151 |
μ΄ν΄λ₯Ό λκ² μ΅λλ€."""
|
152 |
|
153 |
try:
|
|
|
154 |
if uploaded_file:
|
155 |
content, file_type = read_uploaded_file(uploaded_file)
|
156 |
if file_type == "error":
|
@@ -167,7 +166,6 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
167 |
|
168 |
if message == "νμΌ λΆμμ μμν©λλ€...":
|
169 |
message = f"""[νμΌ κ΅¬μ‘° λΆμ] {file_summary}
|
170 |
-
|
171 |
λ€μ κ΄μ μμ λμμ λλ¦¬κ² μ΅λλ€:
|
172 |
1. π μ λ°μ μΈ λ΄μ© νμ
|
173 |
2. π‘ μ£Όμ νΉμ§ μ€λͺ
|
@@ -175,10 +173,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
175 |
4. β¨ κ°μ μ μ
|
176 |
5. π¬ μΆκ° μ§λ¬Έμ΄λ νμν μ€λͺ
"""
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
try:
|
181 |
-
# μμ€ν
λ©μμ§ μ€μ
|
182 |
messages = [{"role": "system", "content": system_prefix + system_message}]
|
183 |
|
184 |
# μ΄μ λν νμ€ν 리 μΆκ°
|
@@ -189,6 +184,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
189 |
|
190 |
messages.append({"role": "user", "content": message})
|
191 |
|
|
|
192 |
client = get_client()
|
193 |
partial_message = ""
|
194 |
|
@@ -202,7 +198,6 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
202 |
token = msg.choices[0].delta.get('content', None)
|
203 |
if token:
|
204 |
partial_message += token
|
205 |
-
# Gradio Chatbot νμμΌλ‘ νμ€ν 리 μ
λ°μ΄νΈ
|
206 |
current_history = history + [[message, partial_message]]
|
207 |
yield "", current_history
|
208 |
|
|
|
138 |
if not message:
|
139 |
return "", history
|
140 |
|
|
|
141 |
system_prefix = """μ λ μ¬λ¬λΆμ μΉκ·Όνκ³ μ§μ μΈ AI μ΄μμ€ν΄νΈ 'GiniGEN'μ
λλ€.. λ€μκ³Ό κ°μ μμΉμΌλ‘ μν΅νκ² μ΅λλ€:
|
|
|
142 |
1. π€ μΉκ·Όνκ³ κ³΅κ°μ μΈ νλλ‘ λν
|
143 |
2. π‘ λͺ
ννκ³ μ΄ν΄νκΈ° μ¬μ΄ μ€λͺ
μ 곡
|
144 |
3. π― μ§λ¬Έμ μλλ₯Ό μ νν νμ
νμ¬ λ§μΆ€ν λ΅λ³
|
|
|
149 |
μ΄ν΄λ₯Ό λκ² μ΅λλ€."""
|
150 |
|
151 |
try:
|
152 |
+
# νμΌ μ
λ‘λ μ²λ¦¬
|
153 |
if uploaded_file:
|
154 |
content, file_type = read_uploaded_file(uploaded_file)
|
155 |
if file_type == "error":
|
|
|
166 |
|
167 |
if message == "νμΌ λΆμμ μμν©λλ€...":
|
168 |
message = f"""[νμΌ κ΅¬μ‘° λΆμ] {file_summary}
|
|
|
169 |
λ€μ κ΄μ μμ λμμ λλ¦¬κ² μ΅λλ€:
|
170 |
1. π μ λ°μ μΈ λ΄μ© νμ
|
171 |
2. π‘ μ£Όμ νΉμ§ μ€λͺ
|
|
|
173 |
4. β¨ κ°μ μ μ
|
174 |
5. π¬ μΆκ° μ§λ¬Έμ΄λ νμν μ€λͺ
"""
|
175 |
|
176 |
+
# λ©μμ§ μ²λ¦¬
|
|
|
|
|
|
|
177 |
messages = [{"role": "system", "content": system_prefix + system_message}]
|
178 |
|
179 |
# μ΄μ λν νμ€ν 리 μΆκ°
|
|
|
184 |
|
185 |
messages.append({"role": "user", "content": message})
|
186 |
|
187 |
+
# API νΈμΆ λ° μλ΅ μ²λ¦¬
|
188 |
client = get_client()
|
189 |
partial_message = ""
|
190 |
|
|
|
198 |
token = msg.choices[0].delta.get('content', None)
|
199 |
if token:
|
200 |
partial_message += token
|
|
|
201 |
current_history = history + [[message, partial_message]]
|
202 |
yield "", current_history
|
203 |
|