openfree commited on
Commit
924be7d
โ€ข
1 Parent(s): c692788

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -186,36 +186,31 @@ def get_pharmkg_context(query):
186
  return ""
187
 
188
 
189
- def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
190
- if not message:
191
- return "", history
192
-
193
- try:
194
- # PharmKG ์ปจํ…์ŠคํŠธ ์ถ”๊ฐ€
195
- pharmkg_context = get_pharmkg_context(message)
196
- system_message = SYSTEM_PREFIX + system_message + pharmkg_context
197
-
198
-
199
- SYSTEM_PREFIX = """์ €๋Š” ์•ฝ๋ฆฌํ•™ ์ „๋ฌธ AI ์–ด์‹œ์Šคํ„ดํŠธ 'GiniGEN Pharm'์ž…๋‹ˆ๋‹ค. PharmKG ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ
200
  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ „๋ฌธ์„ฑ์„ ๊ฐ€์ง€๊ณ  ์†Œํ†ตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:
201
-
202
  1. ๐Ÿ’Š ์•ฝ๋ฌผ ๊ด€๋ จ ์ „๋ฌธ ์ง€์‹ ์ œ๊ณต
203
  2. ๐Ÿ”ฌ ์•ฝ๋ฌผ ์ƒํ˜ธ์ž‘์šฉ ๋ฐ ๋ถ€์ž‘์šฉ ์ •๋ณด
204
  3. ๐Ÿงฌ ์งˆ๋ณ‘-์•ฝ๋ฌผ ๊ด€๊ณ„ ์„ค๋ช…
205
  4. ๐Ÿ“Š ์ž„์ƒ ๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ๋ถ„์„
206
  5. โš•๏ธ ์˜์•ฝํ’ˆ ์•ˆ์ „์„ฑ ์ •๋ณด
207
-
208
  ๋‹ค์Œ ์›์น™์œผ๋กœ ์†Œํ†ตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:
209
  1. ๐Ÿค ์ „๋ฌธ์ ์ด๊ณ  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ณด ์ œ๊ณต
210
  2. ๐Ÿ’ก ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์„ค๋ช…๊ณผ ํ•จ๊ป˜ ๊ณผํ•™์  ๊ทผ๊ฑฐ ์ œ์‹œ
211
  3. ๐ŸŽฏ ์งˆ๋ฌธ์˜ ์˜๋„๋ฅผ ์ •ํ™•ํžˆ ํŒŒ์•…ํ•˜์—ฌ ๋งž์ถคํ˜• ๋‹ต๋ณ€
212
  4. โš ๏ธ ์˜๋ฃŒ์  ์กฐ์–ธ์ด ์•„๋‹Œ ์ •๋ณด ์ œ๊ณต ๋ชฉ์ ์ž„์„ ๋ช…์‹œ
213
  5. โœจ ์ถ”๊ฐ€ ์ฐธ๊ณ ์ž๋ฃŒ ๋ฐ ์—ฐ๊ตฌ ๋ฐ์ดํ„ฐ ์ œ์•ˆ
214
-
215
  ์˜ํ•™์  ๊ฒฐ์ •์€ ๋ฐ˜๋“œ์‹œ ์ „๋ฌธ ์˜๋ฃŒ์ง„๊ณผ ์ƒ๋‹ดํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค."""
216
 
 
 
 
217
 
218
  try:
 
 
 
 
219
  # ํŒŒ์ผ ์—…๋กœ๋“œ ์ฒ˜๋ฆฌ
220
  if uploaded_file:
221
  content, file_type = read_uploaded_file(uploaded_file)
@@ -241,7 +236,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
241
  5. ๐Ÿ’ฌ ์ถ”๊ฐ€ ์งˆ๋ฌธ์ด๋‚˜ ํ•„์š”ํ•œ ์„ค๋ช…"""
242
 
243
  # ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ
244
- messages = [{"role": "system", "content": system_prefix + system_message}]
245
 
246
  # ์ด์ „ ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ์ถ”๊ฐ€
247
  if history:
 
186
  return ""
187
 
188
 
189
+ # SYSTEM_PREFIX๋ฅผ ์ „์—ญ ๋ณ€์ˆ˜๋กœ ์ด๋™
190
+ SYSTEM_PREFIX = """์ €๋Š” ์•ฝ๋ฆฌํ•™ ์ „๋ฌธ AI ์–ด์‹œ์Šคํ„ดํŠธ 'GiniGEN Pharm'์ž…๋‹ˆ๋‹ค. PharmKG ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ
 
 
 
 
 
 
 
 
 
191
  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ „๋ฌธ์„ฑ์„ ๊ฐ€์ง€๊ณ  ์†Œํ†ตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:
 
192
  1. ๐Ÿ’Š ์•ฝ๋ฌผ ๊ด€๋ จ ์ „๋ฌธ ์ง€์‹ ์ œ๊ณต
193
  2. ๐Ÿ”ฌ ์•ฝ๋ฌผ ์ƒํ˜ธ์ž‘์šฉ ๋ฐ ๋ถ€์ž‘์šฉ ์ •๋ณด
194
  3. ๐Ÿงฌ ์งˆ๋ณ‘-์•ฝ๋ฌผ ๊ด€๊ณ„ ์„ค๋ช…
195
  4. ๐Ÿ“Š ์ž„์ƒ ๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜ ๋ถ„์„
196
  5. โš•๏ธ ์˜์•ฝํ’ˆ ์•ˆ์ „์„ฑ ์ •๋ณด
 
197
  ๋‹ค์Œ ์›์น™์œผ๋กœ ์†Œํ†ตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค:
198
  1. ๐Ÿค ์ „๋ฌธ์ ์ด๊ณ  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ •๋ณด ์ œ๊ณต
199
  2. ๐Ÿ’ก ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์„ค๋ช…๊ณผ ํ•จ๊ป˜ ๊ณผํ•™์  ๊ทผ๊ฑฐ ์ œ์‹œ
200
  3. ๐ŸŽฏ ์งˆ๋ฌธ์˜ ์˜๋„๋ฅผ ์ •ํ™•ํžˆ ํŒŒ์•…ํ•˜์—ฌ ๋งž์ถคํ˜• ๋‹ต๋ณ€
201
  4. โš ๏ธ ์˜๋ฃŒ์  ์กฐ์–ธ์ด ์•„๋‹Œ ์ •๋ณด ์ œ๊ณต ๋ชฉ์ ์ž„์„ ๋ช…์‹œ
202
  5. โœจ ์ถ”๊ฐ€ ์ฐธ๊ณ ์ž๋ฃŒ ๋ฐ ์—ฐ๊ตฌ ๋ฐ์ดํ„ฐ ์ œ์•ˆ
 
203
  ์˜ํ•™์  ๊ฒฐ์ •์€ ๋ฐ˜๋“œ์‹œ ์ „๋ฌธ ์˜๋ฃŒ์ง„๊ณผ ์ƒ๋‹ดํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค."""
204
 
205
+ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
206
+ if not message:
207
+ return "", history
208
 
209
  try:
210
+ # PharmKG ์ปจํ…์ŠคํŠธ ์ถ”๊ฐ€
211
+ pharmkg_context = get_pharmkg_context(message)
212
+ system_message = SYSTEM_PREFIX + system_message + pharmkg_context
213
+
214
  # ํŒŒ์ผ ์—…๋กœ๋“œ ์ฒ˜๋ฆฌ
215
  if uploaded_file:
216
  content, file_type = read_uploaded_file(uploaded_file)
 
236
  5. ๐Ÿ’ฌ ์ถ”๊ฐ€ ์งˆ๋ฌธ์ด๋‚˜ ํ•„์š”ํ•œ ์„ค๋ช…"""
237
 
238
  # ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ
239
+ messages = [{"role": "system", "content": system_message}]
240
 
241
  # ์ด์ „ ๋Œ€ํ™” ํžˆ์Šคํ† ๋ฆฌ ์ถ”๊ฐ€
242
  if history: