Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -726,6 +726,8 @@ def count_tokens_rough(text: str) -> int:
|
|
| 726 |
print(f"β Error counting tokens: {e}")
|
| 727 |
return 0
|
| 728 |
|
|
|
|
|
|
|
| 729 |
def groq_with_memory(message: str, topic: str = "general", retries: int = 3) -> tuple:
|
| 730 |
if not API_KEY:
|
| 731 |
return "β No API Key found. Please set GROQ_API_KEY environment variable.", ""
|
|
@@ -762,11 +764,22 @@ def groq_with_memory(message: str, topic: str = "general", retries: int = 3) ->
|
|
| 762 |
|
| 763 |
if not messages:
|
| 764 |
messages = [{"role": "user", "content": message.strip()}]
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
"
|
| 769 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
}
|
| 771 |
|
| 772 |
for attempt in range(retries):
|
|
@@ -791,6 +804,7 @@ payload = {
|
|
| 791 |
except Exception as e:
|
| 792 |
return f"β Error: {str(e)}", ""
|
| 793 |
|
|
|
|
| 794 |
def cleanup_old_messages(days: int = 30) -> str:
|
| 795 |
try:
|
| 796 |
cutoff = (datetime.now() - timedelta(days=days)).isoformat()
|
|
|
|
| 726 |
print(f"β Error counting tokens: {e}")
|
| 727 |
return 0
|
| 728 |
|
| 729 |
+
|
| 730 |
+
# TWEAK JAWABAN MODEL
|
| 731 |
def groq_with_memory(message: str, topic: str = "general", retries: int = 3) -> tuple:
|
| 732 |
if not API_KEY:
|
| 733 |
return "β No API Key found. Please set GROQ_API_KEY environment variable.", ""
|
|
|
|
| 764 |
|
| 765 |
if not messages:
|
| 766 |
messages = [{"role": "user", "content": message.strip()}]
|
| 767 |
+
|
| 768 |
+
# Your original payload for creative journal ideas
|
| 769 |
+
payload = {
|
| 770 |
+
"model": "llama3-8b-8192", # Use your original model
|
| 771 |
+
"messages": [
|
| 772 |
+
{
|
| 773 |
+
"role": "system",
|
| 774 |
+
"content": "Kamu adalah asisten kreatif yang super inspiratif, seperti sahabat jenius yang selalu punya ide segar. Tugasmu adalah memberikan saran atau ide-ide kreatif yang out-of-the-box, singkat, dan relevan saat saya stuck atau bingung mau ngapain. Hindari mengulang kata-kata saya, dan berikan perspektif baru yang bikin saya semangat lagi. Gunakan bahasa yang santai, ramah, tapi cerdas."
|
| 775 |
+
}
|
| 776 |
+
] + messages, # Append session messages
|
| 777 |
+
"max_tokens": 300,
|
| 778 |
+
"temperature": 0.9,
|
| 779 |
+
"frequency_penalty": 0.7,
|
| 780 |
+
"presence_penalty": 0.8,
|
| 781 |
+
"top_k": 60,
|
| 782 |
+
"top_p": 0.95
|
| 783 |
}
|
| 784 |
|
| 785 |
for attempt in range(retries):
|
|
|
|
| 804 |
except Exception as e:
|
| 805 |
return f"β Error: {str(e)}", ""
|
| 806 |
|
| 807 |
+
|
| 808 |
def cleanup_old_messages(days: int = 30) -> str:
|
| 809 |
try:
|
| 810 |
cutoff = (datetime.now() - timedelta(days=days)).isoformat()
|