PYAE1994 commited on
Commit
316caac
·
verified ·
1 Parent(s): 598819e

Create planner.py

Browse files
Files changed (1) hide show
  1. app/agent/planner.py +49 -0
app/agent/planner.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ from config import Config
4
+
5
+
6
+ def create_plan(goal: str):
7
+ """
8
+ Break goal into steps
9
+ """
10
+
11
+ prompt = f"""
12
+ You are a planning agent.
13
+
14
+ Break this goal into steps:
15
+
16
+ GOAL:
17
+ {goal}
18
+
19
+ Return ONLY JSON like:
20
+ {{
21
+ "steps": [
22
+ "step 1",
23
+ "step 2",
24
+ "step 3"
25
+ ]
26
+ }}
27
+ """
28
+
29
+ res = requests.post(
30
+ Config.LLM_API_URL,
31
+ headers={
32
+ "Authorization": f"Bearer {Config.LLM_API_KEY}",
33
+ "Content-Type": "application/json"
34
+ },
35
+ json={
36
+ "model": Config.MODEL,
37
+ "messages": [
38
+ {"role": "user", "content": prompt}
39
+ ],
40
+ "temperature": 0.2
41
+ }
42
+ )
43
+
44
+ content = res.json()["choices"][0]["message"]["content"]
45
+
46
+ try:
47
+ return json.loads(content)
48
+ except:
49
+ return {"steps": [goal]}