|
import os |
|
from flask import Flask, request, jsonify |
|
|
|
from groq import Groq |
|
from dotenv import load_dotenv |
|
load_dotenv() |
|
|
|
groq_api_key = os.getenv("GROQ_API_KEY") |
|
|
|
app = Flask(__name__) |
|
|
|
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'] |
|
|
|
chat_completion = groq.chat.completions.create( |
|
model= "llama2-70b-4096", |
|
messages=[{"role": "user", "content": message}] |
|
) |
|
|
|
return jsonify({"completion": chat_completion.choices[0].message.content}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True, port=8001) |