basic recommendation is working
Browse files- app.py +8 -0
- plan/recommend.py +58 -0
app.py
CHANGED
@@ -26,6 +26,14 @@ def train_products():
|
|
26 |
from train.products import train
|
27 |
return train();
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
#from train.faq import train
|
30 |
#train();
|
31 |
|
|
|
26 |
from train.products import train
|
27 |
return train();
|
28 |
|
29 |
+
@app.route("/plan/recommend", methods=['GET','POST'])
|
30 |
+
def recommend_plan_steps():
|
31 |
+
from plan.recommend import recommend
|
32 |
+
return recommend();
|
33 |
+
|
34 |
+
from plan.recommend import recommend
|
35 |
+
recommend();
|
36 |
+
|
37 |
#from train.faq import train
|
38 |
#train();
|
39 |
|
plan/recommend.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def recommend():
|
2 |
+
|
3 |
+
from typing import Optional, List
|
4 |
+
|
5 |
+
from langchain_core.pydantic_v1 import BaseModel, Field
|
6 |
+
|
7 |
+
class Goals(BaseModel):
|
8 |
+
"""Information about a suggested goal."""
|
9 |
+
|
10 |
+
goal: Optional[str] = Field(default=None, description="a SMART target for the user")
|
11 |
+
timeframe: Optional[str] = Field(default=None, description="whether the goal is short-term, medium-term, or long-term")
|
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 |
+
|
20 |
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
21 |
+
from langchain_core.pydantic_v1 import BaseModel, Field
|
22 |
+
from langchain_openai import ChatOpenAI
|
23 |
+
|
24 |
+
|
25 |
+
prompt = ChatPromptTemplate.from_messages(
|
26 |
+
[
|
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 tell you one of their ambitions - this might be a career aim, a personal aspiration, or something to do with their time at university.
|
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 |
+
You should recommend three short-term targets, two medium-term targets and one longer-term target.
|
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 |
+
The user is currently studying B.A Graphic Design. They are in their second year, and have two years left.
|
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=GoalList)
|
52 |
+
|
53 |
+
text = "Become a graphic designer"
|
54 |
+
response = runnable.invoke({"text": text})
|
55 |
+
|
56 |
+
print(response);
|
57 |
+
|
58 |
+
return "hello"
|