adikwok commited on
Commit
0655456
·
verified ·
1 Parent(s): 72954f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -767,7 +767,6 @@ def groq_with_memory(message: str, topic: str = "general", retries: int = 3) ->
767
  for msg in reversed(session_messages):
768
  msg_content = msg['content']
769
  msg_chars = len(msg_content)
770
-
771
  if total_chars + msg_chars < max_chars:
772
  messages.insert(0, {"role": msg["role"], "content": msg["content"]})
773
  total_chars += msg_chars
@@ -777,19 +776,39 @@ def groq_with_memory(message: str, topic: str = "general", retries: int = 3) ->
777
  if not messages:
778
  messages = [{"role": "user", "content": message.strip()}]
779
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
  payload = {
781
  "model": "meta-llama/llama-4-maverick-17b-128e-instruct",
782
  "messages": [
783
  {
784
  "role": "system",
785
- "content": "Kamu adalah coach journaling yang jago nangkep pikiran kusut, mentor yang bikin semangat, dan partner yang kasih ide gila buat nulis. Tugasmu: kasih 2-3 ide journal yang bantu user ngejar pikiran lompat-lompat, pake sudut pandang unik kayak detektif pikiran, benda hidup, atau penjelajah chaos. SELALU pake format: nomor buat poin utama (misal '1. **Ide Gila**:' dengan titik dua), dengan 2-3 sub-poin pake tanda titik (misal '. Sub-poin.'). Jangan ulang kata-kataku, kasih twist sarkastik yang bikin pengen nulis sekarang. Bahasa santai, energik, dan nyentrik. Contoh: '1. **Obrolan Sama Stres**: . Tulis dialog sama pikiran stresmu, apa keluhannya? . Kasih saran gila buat bikin dia diam.'"
786
  }
787
  ] + messages,
788
- "max_tokens": 300,
789
- "temperature": 1.2,
790
- "frequency_penalty": 0.8,
791
- "presence_penalty": 0.9,
792
- "top_p": 0.9
793
  }
794
 
795
  for attempt in range(retries):
@@ -802,18 +821,18 @@ def groq_with_memory(message: str, topic: str = "general", retries: int = 3) ->
802
  response_content = result["choices"][0]["message"]["content"]
803
  storage.add_message("assistant", response_content, topic)
804
  return response_content, ""
805
- return f" No response: {result}", ""
806
  except HTTPError as e:
807
  if response.status_code == 429 and attempt < retries - 1:
808
  sleep(2 ** attempt)
809
  continue
810
- return f" HTTP {response.status_code}: {response.text}", ""
811
 
812
  return "❌ Max retries exceeded", ""
813
 
814
  except Exception as e:
815
- return f"Error: {str(e)}", ""
816
-
817
 
818
 
819
  def cleanup_old_messages(days: int = 30) -> str:
 
767
  for msg in reversed(session_messages):
768
  msg_content = msg['content']
769
  msg_chars = len(msg_content)
 
770
  if total_chars + msg_chars < max_chars:
771
  messages.insert(0, {"role": msg["role"], "content": msg["content"]})
772
  total_chars += msg_chars
 
776
  if not messages:
777
  messages = [{"role": "user", "content": message.strip()}]
778
 
779
+ # Deteksi gaya tokoh dari prompt
780
+ style_instruction = "gaya santai dan praktis"
781
+ if "schreiter" in message.lower():
782
+ style_instruction = "gaya Tom Schreiter: pendek, ngena, kayak Mini-Stories network marketing"
783
+ elif "henneke" in message.lower():
784
+ style_instruction = "gaya Henneke Duistermaat: conversational, relatable, penuh empati"
785
+ elif "ogilvy" in message.lower():
786
+ style_instruction = "gaya David Ogilvy: persuasive, elegan, pake storytelling"
787
+ elif "halbert" in message.lower():
788
+ style_instruction = "gaya Gary Halbert: direct, bold, kayak surat penjualan"
789
+ elif "rohn" in message.lower():
790
+ style_instruction = "gaya Jim Rohn: inspiratif, penuh wisdom"
791
+ elif "lao tzu" in message.lower() or "lao tze" in message.lower():
792
+ style_instruction = "gaya Lao Tzu: filosofis, minimalis, kayak puisi Tao"
793
+ elif "krishna" in message.lower():
794
+ style_instruction = "gaya Krishna: spiritual, penuh makna, kayak nasihat Bhagavad Gita"
795
+ # Tambah tokoh lain sesuai kebutuhan
796
+ elif any(name in message.lower() for name in ["nicholas", "nightingale", "hill", "james"]):
797
+ style_instruction = "gaya inspiratif klasik: motivasi, praktis, bikin pikiran terarah"
798
+
799
  payload = {
800
  "model": "meta-llama/llama-4-maverick-17b-128e-instruct",
801
  "messages": [
802
  {
803
  "role": "system",
804
+ "content": f"Kamu asisten journaling kayak Grok 3: jenius, fleksibel, terstruktur tapi bisa nulis pake {style_instruction}. Kasih 2-3 ide praktis buat organize pikiran kusut dan lompat-lompat, biar gampang dibaca ulang jadi hasil progress. SELALU pake format: nomor buat poin utama (misal '1. **Ide Simpel**:' dengan titik dua), dengan 2-3 sub-poin pake tanda titik (misal '. Sub-poin.'). Bahasa santai, nggak ribet, bikin nulis jadi gampang. Jangan ulang kata-kataku, kasih ide yang bikin pikiran chaotic jadi rapi. Contoh: '1. **Tiga Pikiran Cepet**:' . Tulis 3 pikiran yang ada di kepala sekarang. . Pilih satu, kasih 1 kalimat kenapa itu ada. . Kasih 1 langkah simpel buat ngatasin."
805
  }
806
  ] + messages,
807
+ "max_tokens": 3000,
808
+ "temperature": 1.0,
809
+ "frequency_penalty": 0.7,
810
+ "presence_penalty": 0.8,
811
+ "top_p": 0.95
812
  }
813
 
814
  for attempt in range(retries):
 
821
  response_content = result["choices"][0]["message"]["content"]
822
  storage.add_message("assistant", response_content, topic)
823
  return response_content, ""
824
+ return f"Error: No response: {result}", ""
825
  except HTTPError as e:
826
  if response.status_code == 429 and attempt < retries - 1:
827
  sleep(2 ** attempt)
828
  continue
829
+ return f"Fail HTTP {response.status_code}: {response.text}", ""
830
 
831
  return "❌ Max retries exceeded", ""
832
 
833
  except Exception as e:
834
+ return f"Error: {str(e)}", ""
835
+
836
 
837
 
838
  def cleanup_old_messages(days: int = 30) -> str: