dpaul93 commited on
Commit
958773c
·
verified ·
1 Parent(s): d90579c

Create agents.py

Browse files
Files changed (1) hide show
  1. agents.py +62 -0
agents.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+
4
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
5
+ LLAMA_MODEL = "llama3-8b-8192"
6
+ SLM_MODEL = "slm-1b"
7
+
8
+ def call_groq(prompt, model=LLAMA_MODEL):
9
+ response = requests.post(
10
+ "https://api.groq.com/openai/v1/chat/completions",
11
+ headers={"Authorization": f"Bearer {GROQ_API_KEY}"},
12
+ json={
13
+ "model": model,
14
+ "messages": [{"role": "user", "content": prompt}],
15
+ "temperature": 0.7
16
+ }
17
+ )
18
+ return response.json()["choices"][0]["message"]["content"]
19
+
20
+ def get_prompt(entry, mood, mode):
21
+ if "Workplace" in mode:
22
+ return f"""
23
+ You are a workplace CBT/NLP counselor. Analyze this journal:
24
+
25
+ "{entry}"
26
+
27
+ Mood: {mood}
28
+
29
+ Return:
30
+ - Summary
31
+ - Workplace Stressors
32
+ - Cognitive Distortions
33
+ - Reframe
34
+ - Affirmation
35
+ """
36
+ else:
37
+ return f"""
38
+ You are a CBT/NLP journaling agent. Analyze the following:
39
+
40
+ "{entry}"
41
+
42
+ Mood: {mood}
43
+
44
+ Return:
45
+ - Summary
46
+ - Emotional Triggers
47
+ - Distortions
48
+ - CBT Reframe
49
+ - Daily Affirmation
50
+ """
51
+
52
+ def run_journaling_pipeline(mood, entry, mode):
53
+ if not entry.strip():
54
+ return {"error": "Empty entry."}
55
+ prompt = get_prompt(entry, mood, mode)
56
+ output = call_groq(prompt)
57
+ return {
58
+ "mood": mood,
59
+ "mode": mode,
60
+ "entry": entry,
61
+ "response": output
62
+ }