<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Deep Research System - LLM Settings</title>
    <link rel="stylesheet" href="{{ url_for('research.serve_static', path='css/styles.css') }}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body>
    <div class="app-container">
        <!-- Sidebar -->
        <aside class="sidebar">
            <!-- Sidebar content (keep as is) -->
        </aside>

        <!-- Main Content -->
        <main class="main-content">
            <div class="page active" id="llm-settings">
                <div class="page-header">
                    <div class="results-header">
                        <h1>Language Model Configuration</h1>
                        <div class="results-actions">
                            <a href="{{ url_for('research.settings_page') }}" class="btn btn-outline">
                                <i class="fas fa-arrow-left"></i> Back to Settings
                            </a>
                        </div>
                    </div>
                </div>

                <div class="card">
                    <div class="card-content">
                        <h2>LLM Configuration File</h2>
                        <p>To edit your LLM configuration, open this file with your preferred text editor:</p>
                        <div class="file-path">{{ llm_file_path }}</div>
                        
                        <button onclick="openFileLocation('{{ llm_file_path }}')" class="btn btn-primary">
                            <i class="fas fa-folder-open"></i> Open Containing Folder
                        </button>
                        
                        <h3 class="mt-4">Default Configuration Example</h3>
                        <pre class="config-example">
"""
LLM configuration for Local Deep Research.

This file is loaded as a Python module, allowing for complex
customization of LLM behavior.
"""

# Default model settings
DEFAULT_MODEL = "mistral"
DEFAULT_MODEL_TYPE = "ollama"  # Options: ollama, openai, anthropic
DEFAULT_TEMPERATURE = 0.7
MAX_TOKENS = 30000

# API keys and endpoints (consider using environment variables instead)
USE_OPENAI_ENDPOINT = False
OPENAI_ENDPOINT_URL = "https://openrouter.ai/api/v1"
OPENAI_ENDPOINT_REQUIRES_MODEL = True

# Custom model loading function
def get_llm(model_name=None, model_type=None, temperature=None, **kwargs):
    """
    Get a language model instance.
    
    Args:
        model_name: Name of the model to use
        model_type: Type of model provider 
        temperature: Model temperature
        **kwargs: Additional parameters
        
    Returns:
        A LangChain language model instance
    """
    # Use defaults if not provided
    model_name = model_name or DEFAULT_MODEL
    model_type = model_type or DEFAULT_MODEL_TYPE
    temperature = temperature or DEFAULT_TEMPERATURE
    
    # If using Ollama
    if model_type == "ollama":
        from langchain_ollama import ChatOllama
        return ChatOllama(
            model=model_name,
            temperature=temperature,
            **kwargs
        )
    
    # Default fallback
    from langchain_ollama import ChatOllama
    return ChatOllama(
        model="mistral",
        temperature=0.7,
        **kwargs
    )
                        </pre>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <script>
        function openFileLocation(path) {
            fetch('/research/open_file_location', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: 'file_path=' + encodeURIComponent(path)
            })
            .then(response => {
                // Handle response
            })
            .catch(error => console.error('Error:', error));
        }
    </script>
</body>
</html>