#
# Copyright (c) 2025, mstoeck3
# All rights reserved.
#
# This source code is licensed under the BSD-3-Clause license found in the
# LICENSE file in the root directory of this source tree.
#

import dotenv
import openai

class LLMInterface():
    """
    provide a custom interface along with special methods relevant with the semeion application
    """
    
    def __init__(self):
        openai.api_key = dotenv.get_key(".env", "LLM_API_KEY")
        openai.base_url = dotenv.get_key(".env", "LLM_API_BASE")
        print("CLNT:LLMCLIENT INITIALIZED:", dotenv.get_key(".env", "LLM_MODEL"), "@", dotenv.get_key(".env", "LLM_API_BASE"))

    def simple_query(self, prompt: str):
        try:
            print("CLNT:LLMCLIENT CALL LLM", prompt)
            if dotenv.get_key(".env", "LLM_MODEL") is None:
                raise ValueError("CLNT:LLMCLIENT ERR: LLM MODEL not set")
            else:
                model = dotenv.get_key(".env", "LLM_MODEL")
            
            response = openai.chat.completions.create(
                model=str(model),
                messages=[
                    {
                        "role": "user",
                        "content": prompt
                    },
                    {
                        "role": "assistant",
                        "content": "Hello! How are you doing today? Is there something I can help you with?"
                    }
                ],
                timeout=30
            )
            return response
        except Exception as e:
            print(f"CLNT:LLMCLIENT ERR: {e}")
            raise