File size: 967 Bytes
1a25ebd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from flask import Flask, request, jsonify
#from flask_wtf.csrf import CSRFProtect
from groq import Groq
from dotenv import load_dotenv
load_dotenv()

groq_api_key = os.getenv("GROQ_API_KEY")

app = Flask(__name__)
#csrf = CSRFProtect(app)
groq = Groq(api_key=groq_api_key)


@app.route('/')
def index():
    return "Llama Helper"

@app.route('/get_chat_completion', methods=['POST'])
def get_chat_completion():
    data = request.json
    message = data['message']
        # Use the Groq SDK to get chat completion
    chat_completion = groq.chat.completions.create(
        model= "llama2-70b-4096",
        messages=[{"role": "user", "content": message}]
    )

    return jsonify({"completion": chat_completion.choices[0].message.content})

#    except ValueError as e:
#        return jsonify({"error": str(e)}), 400
#   except Exception as e:
#       return jsonify({"error": str(e)}), 500

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