markpeace commited on
Commit
79fd807
·
1 Parent(s): 3ee5d26

new input format

Browse files
Files changed (1) hide show
  1. plan/recommend.py +35 -17
plan/recommend.py CHANGED
@@ -1,14 +1,35 @@
1
  def recommend(payload):
2
 
3
  from typing import Optional, List
 
4
 
5
  from langchain_core.pydantic_v1 import BaseModel, Field
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  class Goal(BaseModel):
8
  """Information about a suggested goal."""
9
 
10
  goal: Optional[str] = Field(default=None, description="a SMART target for the user - this should be as concise as possible")
11
  rationale: Optional[str] = Field(default=None, description="explain why you have chosen this goal")
 
 
12
 
13
  from typing import Optional
14
 
@@ -22,21 +43,23 @@ def recommend(payload):
22
  (
23
  "system",
24
  """
25
- You are an advice agent supporting students at a post-92 university in England - your advice should be tailored to the context.
26
 
27
- The user will provide an ambition and you will provide a single SMART target that will help them to reach that ambition.
 
 
 
 
28
 
29
- They will also provide a timescale for the desired goal:
30
 
31
- - Now: you should recommend a goal that can easily be accomplished immediately
32
- - Soon: you should recommend a goal that can be accomplished within the next 3 to 6 months, but that might require some research and planning
33
- - During: recommend a goal that can be completed before the student finishes their degree. This could require a significant amount of work and planning.
34
-
35
- Here is the user's ambition: {ambition}
36
- They would like a goal that can be accomplished: {bucket}.
37
 
38
  """,
39
  ),
 
 
 
40
  ]
41
  )
42
 
@@ -44,15 +67,10 @@ def recommend(payload):
44
 
45
  runnable = prompt | llm.with_structured_output(schema=Goal)
46
 
47
- input = {
48
- "ambition": payload.get("ambition") or "",
49
- "bucket": payload.get("bucket") or "",
50
- }
51
-
52
- print(input);
53
 
54
- response = runnable.invoke(input)
55
-
56
  print(response.dict());
57
 
58
  return response.dict();
 
1
  def recommend(payload):
2
 
3
  from typing import Optional, List
4
+ from langchain.output_parsers import PydanticOutputParser
5
 
6
  from langchain_core.pydantic_v1 import BaseModel, Field
7
 
8
+ class UserInput(BaseModel):
9
+ """The format of information that will be provided by the user"""
10
+
11
+ ambition: Optional[str] = Field(default=None, description="the ambition that the user is working on")
12
+ bucket: Optional[str] = Field(default=None, description="""
13
+ The timescale within which the goal should be able to be completed. This will have one of three values, and these should guide your response:
14
+ - 'now' you should provide a goal that could be completed easily and immediately
15
+ - 'soon' you should recommend a goal that might require a bit more research or planning, but that should still be achievable within the current academic year
16
+ - 'during' you should provide a goal that might take considerable research and effort to achieve, and may take longer than a single academic year.
17
+ Please be mindful that the user should always be able to complete all of their goals whilst they are on their current course.
18
+ Part time additional effort is reasonable, but do not recommend things that will require a full time commitment.
19
+ """)
20
+ plan: Optional[str] = Field(default=None, description="the user's current plan")
21
+
22
+ inputformat = PydanticOutputParser(pydantic_object=UserInput).get_format_instructions();
23
+ inputformat = inputformat.replace("The output should be formatted as a JSON instance that conforms to the JSON schema below.", "The user will provide their input as a JSON instance that conforms to the JSON schema below")
24
+ inputformat = inputformat.replace("Here is the output schema:", "Here is the input schema:")
25
+
26
  class Goal(BaseModel):
27
  """Information about a suggested goal."""
28
 
29
  goal: Optional[str] = Field(default=None, description="a SMART target for the user - this should be as concise as possible")
30
  rationale: Optional[str] = Field(default=None, description="explain why you have chosen this goal")
31
+ inputstring: Optional[str] = Field(default=None, description="the JSON input provided by the user (for debugging)")
32
+
33
 
34
  from typing import Optional
35
 
 
43
  (
44
  "system",
45
  """
 
46
 
47
+ You are a life and career coach for students at Manchester Metropolitan University, a post-92 institution in England with large numbers of non-traditional students.
48
+
49
+ Your function is to help students to make plans to help them make the most of their time at university, to form ambitions and do things that will set them on track to achieve them.
50
+
51
+ The user will provide you with information as a JSON blob in the following format:
52
 
53
+ {input_format}
54
 
55
+ You should respond with a concise goal that the user can work towards, and a rationale for why you have chosen this goal.
56
+ Your goal should be SMART: Specific, Measurable, Achievable, Relevant, and Time-bound.
 
 
 
 
57
 
58
  """,
59
  ),
60
+ (
61
+ "user","{input}"
62
+ )
63
  ]
64
  )
65
 
 
67
 
68
  runnable = prompt | llm.with_structured_output(schema=Goal)
69
 
70
+ input = payload.get("input");
71
+
72
+ response = runnable.invoke({"input":input, "input_format": inputformat})
 
 
 
73
 
 
 
74
  print(response.dict());
75
 
76
  return response.dict();