File size: 2,205 Bytes
f71f174
509ca73
 
 
88e7405
10928c5
 
d0f802a
509ca73
6d8186b
509ca73
7497699
 
 
 
509ca73
 
 
 
 
 
10928c5
24c6700
509ca73
 
 
 
 
 
 
 
 
 
10928c5
 
 
 
 
509ca73
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

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__)

@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 = """
    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}{user.replace('{prompt}', prompt)}{suffix}"
    return jsonify({"ans":llm(prompt)})


@app.route('/get_mentor', methods=['POST'])
def recommendation():
    content = request.json
    user_degree = content.get('degree')
    user_stream = content.get('stream')
    user_semester = content.get('semester')
    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}


    Based on above details recommend the mentor that realtes to above details 
    Note: Output should bevalid 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}{user.replace('{prompt}', prompt)}{suffix}"
    return jsonify({"ans":llm(prompt)})

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