File size: 865 Bytes
51a45e9
2b330e8
17aa59f
 
 
caa5775
51a45e9
17aa59f
 
 
caa5775
 
17aa59f
2b330e8
 
 
17aa59f
 
2b330e8
 
17aa59f
2b330e8
 
17aa59f
 
 
 
 
 
 
 
 
 
 
 
 
 
2b330e8
17aa59f
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
from flask import Flask
from flask import request
from groq import Groq

import os

app = Flask(__name__)
client = Groq(
    api_key=os.environ.get("GROQ_API_KEY")
)


@app.route("/api/generate", methods=['POST'])
def completion():
    """
    {
        "model": "llama3-70b-8192",
        "prompt": "why is the sky blue?"
    }
    """

    message = request.get_json()
    
    model = message['model']
    prompt = message['prompt']

    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "user",
                "content": prompt,
            }
        ],
        model=model,
    )

    return chat_completion.choices[0].message.content 

# curl -v -X POST 'http://127.0.0.1:8000/api/generate' --header 'Content-Type: application/json' --data '{"model": "llama3-70b-8192", "prompt": "why is sky blue?"}'