File size: 780 Bytes
a702d42
627f326
 
 
 
 
 
 
a702d42
 
 
627f326
 
a892696
627f326
a702d42
627f326
a702d42
 
627f326
a702d42
 
 
627f326
a702d42
627f326
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
import os
from groq import Groq

try:
    import streamlit as st
    GROQ_API_KEY = st.secrets.get("GROQ_API_KEY") or os.getenv("GROQ_API_KEY")
except Exception:
    GROQ_API_KEY = os.getenv("GROQ_API_KEY")

def query_model(prompt):
    try:
        client = Groq(api_key=GROQ_API_KEY)

        response = client.chat.completions.create(
            model="llama-3.1-8b-instant",  # Free, fast, powerful
            messages=[
                {"role": "system", "content": "You are a professional fitness trainer and nutritionist."},
                {"role": "user", "content": prompt}
            ],
            max_tokens=1000,
            temperature=0.7
        )
        return response.choices[0].message.content

    except Exception as e:
        return f"Error: {str(e)}"