import os
import requests

def chat_completion(model_params):
    api_key = os.environ.get('SIGIQ_API_KEY')
    url = "http://35.247.56.152/call-gpt/"

    headers = {
        'Content-Type': 'application/json',
    }
    payload = {
        "api_key": api_key,
        "model_params": model_params,
    }

    response = requests.get(url, json=payload, headers=headers)
    return response

def get_stats(user=None):
    api_key = os.environ.get('SIGIQ_API_KEY')
    url = "http://35.247.56.152/get-stats/"
    
    headers = {
        'Content-Type': 'application/json',
    }
    payload = {
        "api_key": api_key,
    }
    if user:
        payload['user'] = user

    response = requests.get(url, json=payload, headers=headers)
    if response.status_code == 200:
        return response.json()
    else:
        error_message = response.text
        return f"Request failed with status code {response.status_code}: {error_message}"
