File size: 2,347 Bytes
f71f174
509ca73
 
 
88e7405
10928c5
 
d0f802a
509ca73
6d8186b
509ca73
25f7cba
 
 
 
7497699
 
 
 
509ca73
 
 
 
 
 
c34d039
24c6700
509ca73
 
 
 
 
 
 
 
 
 
10928c5
 
 
c34d039
10928c5
509ca73
24c6700
 
c8c3002
24c6700
 
 
 
25f7cba
c34d039
24c6700
 
 
 
 
25f7cba
24c6700
25f7cba
24c6700
ef1e39e
24c6700
 
 
 
c34d039
24c6700
 
509ca73
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

from flask import Flask, request, jsonify

device = "cuda" # the device to load the model onto

from ctransformers import AutoModelForCausalLM

llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-v0.1-GGUF", model_file="mistral-7b-v0.1.Q4_K_M.gguf", model_type="mistral", gpu_layers=00)

app = Flask(__name__)

file_path = "mentor.txt"
with open(file_path, "r") as file:
    mentors_data = file.read()

@app.route('/')
def home():
    return jsonify({"message": "Welcome to the Recommendation API!"})

@app.route('/recommend', methods=['POST'])
def recommendation():
    content = request.json
    user_degree = content.get('degree')
    user_stream = content.get('stream')
    user_semester = content.get('semester')
    prompt = """ prompt: 
    You need to act like as recommendataion engine for course recommendation for student based on below details.

    Degree: {user_degree}
    Stream: {user_stream}
    Current Semester: {user_semester}


    Based on above details recommend the courses that realtes to above details 
    Note: Output should bevalid json format in below format:
    {{"course1:ABC,course2:DEF,course3:XYZ,...}}
    
    """
    suffix="[/INST]"
    prefix="[INST] <<SYS>> You are a helpful assistant <</SYS>>"
    prompt = f"{prefix}{prompt}{suffix}"
    return jsonify({"ans":llm(prompt)})


@app.route('/get_mentor', methods=['POST'])
def mentor():
    content = request.json
    user_degree = content.get('degree')
    user_stream = content.get('stream')
    user_semester = content.get('semester')
    courses = content.get('courses')
    prompt = f""" prompt:
    You need to act like as recommendataion engine for mentor recommendation for student based on below details also the list of mentors with their experience is attached.

    Degree: {user_degree}
    Stream: {user_stream}
    Current Semester: {user_semester}
    courses opted:{courses}

    Mentor list= {mentors_data}
    Based on above details recommend the mentor that realtes to above details 
    Note: Output should be valid json format in below format:
    {{"mentor1:ABC,mentor2:DEF,mentor3:XYZ,...}}
    """
    suffix="[/INST]"
    prefix="[INST] <<SYS>> You are a helpful assistant <</SYS>>"
    prompt = f"{prefix}{prompt}{suffix}"
    return jsonify({"ans":llm(prompt)})

if __name__ == '__main__':
    app.run(debug=True)