File size: 1,175 Bytes
f71f174
509ca73
 
 
88e7405
10928c5
 
 
509ca73
 
 
 
 
 
 
 
 
 
10928c5
509ca73
 
 
 
 
 
 
 
 
 
 
10928c5
 
 
 
 
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

from flask import Flask, request, jsonify

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

from ctransformers import AutoModelForCausalLM

llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7b-Chat-GGUF", model_file="llama-2-7b-chat.q4_K_M.gguf", model_type="llama", gpu_layers=0)




@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 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)})

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