benjamin5607 commited on
Commit
b9f41cf
ยท
verified ยท
1 Parent(s): b3f157b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  import io
9
 
10
  # ==========================================
11
- # ๐Ÿ› ๏ธ 1. ์„ค์ • ๋ฐ ์‹œํฌ๋ฆฟ
12
  # ==========================================
13
  st.set_page_config(page_title="Drunken Plane", page_icon="โœˆ๏ธ", layout="wide")
14
 
@@ -42,7 +42,7 @@ st.markdown("""
42
  """, unsafe_allow_html=True)
43
 
44
  # ==========================================
45
- # ๐Ÿ’พ 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ
46
  # ==========================================
47
  PLACE_DB = {}
48
  DUMMY_DATA = {
@@ -82,7 +82,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
82
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
83
 
84
  # ==========================================
85
- # ๐Ÿ–ฅ๏ธ 3. ํ†ตํ•ฉ ํ”„๋ก ํŠธ์—”๋“œ (413/400 ์—๋Ÿฌ ํ•ด๊ฒฐ์„ ์œ„ํ•œ ๋ชจ๋ธ ๊ต์ฒด)
86
  # ==========================================
87
  html_template = """
88
  <!DOCTYPE html>
@@ -260,12 +260,12 @@ html_template = """
260
  });
261
  }
262
 
263
- // [ํ•ต์‹ฌ] 413/400 ๋ฐฉ์ง€์šฉ ์ข€๋น„ ๋ชจ๋ธ ๋ฆฌ์ŠคํŠธ (์ปจํ…์ŠคํŠธ๊ฐ€ ํฐ ์ˆœ์„œ๋Œ€๋กœ)
264
  const ZOMBIE_MODELS = [
265
- "llama-3.3-70b-versatile", // 128k context (๊ฐ€์žฅ ํผ, 413 ๋ฐฉ์ง€์šฉ)
266
- "llama-3.1-70b-versatile", // 128k context
267
- "mixtral-8x7b-32768", // 32k context
268
- "llama-3.1-8b-instant" // 128k context (๊ฐ€๋ณ๊ณ  ๋น ๋ฆ„)
269
  ];
270
 
271
  async function callGroq(msgs) {
@@ -283,13 +283,11 @@ html_template = """
283
  if (r.ok) {
284
  const d = await r.json(); return d.choices[0].message.content;
285
  }
286
- // 413(์šฉ๋Ÿ‰์ดˆ๊ณผ), 400(์š”์ฒญ์˜ค๋ฅ˜)๊ฐ€ ๋œจ๋ฉด ๋‹ค์Œ ๋ชจ๋ธ๋กœ ๋„˜์–ด๊ฐ
287
- // 401(ํ‚ค ์˜ค๋ฅ˜)๋ฉด ์ฆ‰์‹œ ๋ฉˆ์ถค
288
  if (r.status === 401) return "Error 401: Invalid API Key.";
289
-
290
  } catch(e) { continue; }
291
  }
292
- return "Emily is overloaded (Too much data). Try fewer requests.";
293
  }
294
 
295
  async function sendChat() {
@@ -297,10 +295,13 @@ html_template = """
297
  addChatMessage(msg, 'user'); inp.value = "";
298
  chatHistory.push({ role: "user", content: msg });
299
 
300
- // [์ด์›ํ™” ๋กœ์ง ์œ ์ง€]
301
- let fullDbContext = "Here is the FULL MENU of places:\\n";
 
 
 
302
  for(let c in PLACE_DB) {
303
- // ๋ฐ์ดํ„ฐ ์–‘์„ ์ค„์ด๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ •๋ณด๋งŒ ์ตœ์†Œํ™”ํ•˜์—ฌ ์ „์†ก (413 ๋ฐฉ์ง€)
304
  let pNames = PLACE_DB[c].map(p => p.name).join(", ");
305
  fullDbContext += "- " + c + ": " + pNames + "\\n";
306
  }
@@ -316,7 +317,7 @@ html_template = """
316
  }
317
  });
318
  }
319
- if(nearbyPlaces.length > 0) gpsContext = "User GPS: " + userLat + "," + userLon + ". Nearby(20km): " + nearbyPlaces.join(", ");
320
  }
321
 
322
  const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
@@ -324,15 +325,16 @@ html_template = """
324
  [GLOBAL DATA]
325
  ${fullDbContext}
326
 
327
- [USER LOCATION]
328
  ${gpsContext}
329
 
330
  [RULES]
331
  1. User asks for specific city? Use [GLOBAL DATA].
332
- 2. User asks for 'nearby'? Use [USER LOCATION].
333
  3. ALWAYS format recommendations as [Place Name].`;
334
 
335
- const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...chatHistory]);
 
336
 
337
  let finalHtml = botMsg;
338
  const regex = /\[(.*?)\]/g;
 
8
  import io
9
 
10
  # ==========================================
11
+ # ๐Ÿ› ๏ธ 1. ์„ค์ • ๋ฐ ์‹œํฌ๋ฆฟ (๊ทธ๋Œ€๋กœ ์œ ์ง€)
12
  # ==========================================
13
  st.set_page_config(page_title="Drunken Plane", page_icon="โœˆ๏ธ", layout="wide")
14
 
 
42
  """, unsafe_allow_html=True)
43
 
44
  # ==========================================
45
+ # ๐Ÿ’พ 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ (๊ทธ๋Œ€๋กœ ์œ ์ง€)
46
  # ==========================================
47
  PLACE_DB = {}
48
  DUMMY_DATA = {
 
82
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
83
 
84
  # ==========================================
85
+ # ๐Ÿ–ฅ๏ธ 3. ํ†ตํ•ฉ ํ”„๋ก ํŠธ์—”๋“œ (413 ์—๋Ÿฌ ํŒจ์น˜ ์ ์šฉ)
86
  # ==========================================
87
  html_template = """
88
  <!DOCTYPE html>
 
260
  });
261
  }
262
 
263
+ // 413 ์—๋Ÿฌ ๋ฐฉ์ง€์šฉ ์ข€๋น„ ๋ชจ๋ธ (์ปจํ…์ŠคํŠธ ํฐ ์ˆœ์„œ)
264
  const ZOMBIE_MODELS = [
265
+ "llama-3.3-70b-versatile",
266
+ "llama-3.1-70b-versatile",
267
+ "mixtral-8x7b-32768",
268
+ "llama-3.1-8b-instant"
269
  ];
270
 
271
  async function callGroq(msgs) {
 
283
  if (r.ok) {
284
  const d = await r.json(); return d.choices[0].message.content;
285
  }
 
 
286
  if (r.status === 401) return "Error 401: Invalid API Key.";
287
+ // 413, 400 ๋“ฑ์€ ๋‹ค์Œ ๋ชจ๋ธ ์‹œ๋„
288
  } catch(e) { continue; }
289
  }
290
+ return "Emily is unavailable (Server overload). Try again later.";
291
  }
292
 
293
  async function sendChat() {
 
295
  addChatMessage(msg, 'user'); inp.value = "";
296
  chatHistory.push({ role: "user", content: msg });
297
 
298
+ // [ํ•ต์‹ฌ ํŒจ์น˜] 413 ์—๋Ÿฌ ๋ฐฉ์ง€: ๋Œ€ํ™” ๊ธฐ๋ก์ด ๋„ˆ๋ฌด ๊ธธ์–ด์ง€๋ฉด ์ตœ๊ทผ 6๊ฐœ(3ํ„ด)๋งŒ ์ž๋ฅธ๋‹ค.
299
+ const MAX_HISTORY = 6;
300
+ const recentHistory = chatHistory.slice(-MAX_HISTORY);
301
+
302
+ let fullDbContext = "MENU:\\n";
303
  for(let c in PLACE_DB) {
304
+ // ๋ฐ์ดํ„ฐ ์–‘์„ ์ค„์ด๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ์ •๋ณด๋งŒ ์ตœ์†Œํ™”
305
  let pNames = PLACE_DB[c].map(p => p.name).join(", ");
306
  fullDbContext += "- " + c + ": " + pNames + "\\n";
307
  }
 
317
  }
318
  });
319
  }
320
+ if(nearbyPlaces.length > 0) gpsContext = "GPS User Loc: " + userLat + "," + userLon + ". Nearby(20km): " + nearbyPlaces.join(", ");
321
  }
322
 
323
  const sysPrompt = `You are Emily, a bartender. Speak ONLY in ${TRANSLATIONS[currentLang].ai}.
 
325
  [GLOBAL DATA]
326
  ${fullDbContext}
327
 
328
+ [USER GPS]
329
  ${gpsContext}
330
 
331
  [RULES]
332
  1. User asks for specific city? Use [GLOBAL DATA].
333
+ 2. User asks for 'nearby'? Use [USER GPS].
334
  3. ALWAYS format recommendations as [Place Name].`;
335
 
336
+ // [ํŒจ์น˜] ์ „์ฒด ๊ธฐ๋ก ๋Œ€์‹  ์ตœ๊ทผ ๊ธฐ๋ก๋งŒ ์ „์†ก
337
+ const botMsg = await callGroq([{ role: "system", content: sysPrompt }, ...recentHistory]);
338
 
339
  let finalHtml = botMsg;
340
  const regex = /\[(.*?)\]/g;