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

recommendations working

Browse files
Files changed (1) hide show
  1. plan/recommend.py +44 -9
plan/recommend.py CHANGED
@@ -5,6 +5,33 @@ def recommend(payload):
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
 
@@ -15,21 +42,28 @@ def recommend(payload):
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
 
@@ -52,9 +86,7 @@ def recommend(payload):
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
  (
@@ -64,6 +96,7 @@ def recommend(payload):
64
  )
65
 
66
  llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.5);
 
67
 
68
  runnable = prompt | llm.with_structured_output(schema=Goal)
69
 
@@ -71,6 +104,8 @@ def recommend(payload):
71
 
72
  response = runnable.invoke({"input":input, "input_format": inputformat})
73
 
 
 
74
  print(response.dict());
75
 
76
  return response.dict();
 
5
 
6
  from langchain_core.pydantic_v1 import BaseModel, Field
7
 
8
+ class InputGoals(BaseModel):
9
+ """
10
+ The existing goals that the user has associated with this particular ambition.
11
+ You should pay close attention to this, and avoid repetition.
12
+ You might build on goals that the user has already resolved, or that have been accepted.
13
+ You should pay attention to goals that the user has rejected, and avoid recommending similar goals.
14
+ """
15
+
16
+ goal: str = Field(description="the goal itself in a clear format")
17
+ bucket: str = Field(description="""
18
+ The timescale within which the goal is currently scheduled to be completed. This will have one of three values:
19
+ - 'now' a goal that could be completed immediately with ease
20
+ - 'soon' a goal that requires a bit more planning or research, but that should be achievable within the current academic year
21
+ - 'during' a goal that might take considerable research and effort to achieve, and may take longer than a single academic year.
22
+ In making your recommendations, you should consider how they fit in with these other goals
23
+ """)
24
+ status: str = Field(description="""
25
+ indicates the origin and current progress towards the goal.
26
+ This will have one of three values, and these should guide your response:
27
+ - 'user_provided' the user has provided this goal themselves.
28
+ - 'suggestion' you have suggested this goal previously, and the user has not yet accepted or rejected it.
29
+ - 'accepted' you have suggested this goal previously, and the user has accepted it.
30
+ - 'rejected' you have suggested this goal previously, and the user has rejected it.
31
+ - 'resolved' the user has completed this goal.
32
+ - 'removed' the user has removed this goal.
33
+ """)
34
+
35
  class UserInput(BaseModel):
36
  """The format of information that will be provided by the user"""
37
 
 
42
  - '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
43
  - 'during' you should provide a goal that might take considerable research and effort to achieve, and may take longer than a single academic year.
44
  Please be mindful that the user should always be able to complete all of their goals whilst they are on their current course.
45
+ Whilst you can and should recommend small standalone courses, and applying for other full time or substantial courses after the current course is completed, you should NEVER suggest that the user should take on a full time course whilst they are already studying.
46
  Part time additional effort is reasonable, but do not recommend things that will require a full time commitment.
47
  """)
48
+ plan: List[InputGoals] = Field(description="The existing goals that the user has associated with this particular ambition.")
49
 
50
  inputformat = PydanticOutputParser(pydantic_object=UserInput).get_format_instructions();
51
  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")
52
  inputformat = inputformat.replace("Here is the output schema:", "Here is the input schema:")
53
 
54
  class Goal(BaseModel):
55
+ """
56
+ Your suggestion for a suggested goal.
57
+ In forming this you should ALWAYS pay attention to the information provided in the user input, and the guidance provided in the JSON schema for it
58
+ Where possible, avoid recommending that the user 'researches' something, as this is a very vague goal
59
+ And avoid referring to the careers service or advisers.
60
+ """
61
+
62
+ goal: Optional[str] = Field(default=None, description="a target for the user - this should be as concise as possible")
63
  rationale: Optional[str] = Field(default=None, description="explain why you have chosen this goal")
64
+ guidance: Optional[str] = Field(default=None, description="provide any additional guidance that the user might need to achieve this goal")
65
+ #inputstring: Optional[str] = Field(default=None, description="the previous goals that have been provided by the user")
66
+ count_reject: Optional[int] = Field(default=0, description="the number of times that the user has rejected a goal")
67
 
68
  from typing import Optional
69
 
 
86
 
87
  {input_format}
88
 
89
+ You should respond in the formal provided
 
 
90
  """,
91
  ),
92
  (
 
96
  )
97
 
98
  llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.5);
99
+ #llm=ChatOpenAI(model="gpt-4", temperature=0)
100
 
101
  runnable = prompt | llm.with_structured_output(schema=Goal)
102
 
 
104
 
105
  response = runnable.invoke({"input":input, "input_format": inputformat})
106
 
107
+ #print(input);
108
+
109
  print(response.dict());
110
 
111
  return response.dict();