| | 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", |
| | 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)}" |