can now recommend a single goal
Browse files- app.py +1 -1
- plan/recommend.py +23 -25
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def recommend_plan_steps():
|
|
| 32 |
return recommend(request.values);
|
| 33 |
|
| 34 |
#from plan.recommend import recommend
|
| 35 |
-
#recommend();
|
| 36 |
|
| 37 |
#from train.faq import train
|
| 38 |
#train();
|
|
|
|
| 32 |
return recommend(request.values);
|
| 33 |
|
| 34 |
#from plan.recommend import recommend
|
| 35 |
+
#recommend({});
|
| 36 |
|
| 37 |
#from train.faq import train
|
| 38 |
#train();
|
plan/recommend.py
CHANGED
|
@@ -4,16 +4,11 @@ def recommend(payload):
|
|
| 4 |
|
| 5 |
from langchain_core.pydantic_v1 import BaseModel, Field
|
| 6 |
|
| 7 |
-
class
|
| 8 |
"""Information about a suggested goal."""
|
| 9 |
|
| 10 |
-
goal: Optional[str] = Field(default=None, description="a SMART target for the user")
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
class GoalList(BaseModel):
|
| 14 |
-
"""A list of goals the user should accomplish to achieve an ambition."""
|
| 15 |
-
|
| 16 |
-
response: List[Goals] = Field(description="A list of goals the user should accomplish to achieve an ambition")
|
| 17 |
|
| 18 |
from typing import Optional
|
| 19 |
|
|
@@ -27,34 +22,37 @@ def recommend(payload):
|
|
| 27 |
(
|
| 28 |
"system",
|
| 29 |
"""
|
| 30 |
-
You are an advice agent supporting students at a post-92 university in England.
|
| 31 |
-
Your advice should be tailored to the context
|
| 32 |
|
| 33 |
-
The user will
|
| 34 |
-
You should provide a list of six things that they could do to help them to achieve that ambition.
|
| 35 |
-
These should take the form of SMART targets.
|
| 36 |
|
| 37 |
-
|
| 38 |
-
They should be achievable before they graduate.
|
| 39 |
-
You should not recommend that they graduate with a degree other than the one they are doing
|
| 40 |
-
But you can suggest follow on courses, such as Masters degrees or professional qualifications.
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
""",
|
| 44 |
),
|
| 45 |
-
("human", "{text}"),
|
| 46 |
]
|
| 47 |
)
|
| 48 |
|
| 49 |
llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.5);
|
| 50 |
|
| 51 |
-
runnable = prompt | llm.with_structured_output(schema=
|
| 52 |
|
| 53 |
-
input =
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
print(input)
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
return response.dict()
|
|
|
|
| 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 |
(
|
| 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 |
|
| 43 |
llm = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0.5);
|
| 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();
|