File size: 3,490 Bytes
09801ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# AI Models Configuration
"""
Configuration for external AI models available in the chat interface.
These models are accessed via OpenRouter/LiteLLM.
"""

from dataclasses import dataclass
from typing import Dict, Optional
from enum import Enum


class AIModelProvider(Enum):
    """AI model providers"""
    GROQ = "groq"
    OPENROUTER = "openrouter"
    TOGETHER = "together"


@dataclass
class AIModelConfig:
    """Configuration for an AI model"""
    id: str                     # Frontend mode id (e.g., "deepseek-chat")
    name: str                   # Display name
    model_path: str             # LiteLLM model path
    provider: AIModelProvider
    max_tokens: int
    temperature: float
    description: str
    best_for: str               # What this model excels at
    speed: str                  # "fast", "medium", "slow"


# ============================================================================
# AI MODEL CONFIGURATIONS - FREE OPENROUTER MODELS ONLY
# Updated: Dec 2024 - Only verified working models
# Note: DeepSeek, OpenAI, Gemma removed due to errors
# ============================================================================

AI_MODELS: Dict[str, AIModelConfig] = {
    "mistral-7b": AIModelConfig(
        id="mistral-7b",
        name="Mistral Small",
        model_path="openrouter/mistralai/mistral-small-3.1-24b-instruct:free",
        provider=AIModelProvider.OPENROUTER,
        max_tokens=4000,
        temperature=0.7,
        description="FREE - Fast model for quick decision analysis",
        best_for="Quick analysis, summaries, decisions",
        speed="fast",
    ),
    
    "llama-70b": AIModelConfig(
        id="llama-70b",
        name="Llama 3.3 70B",
        model_path="openrouter/meta-llama/llama-3.3-70b-instruct:free",
        provider=AIModelProvider.OPENROUTER,
        max_tokens=4000,
        temperature=0.7,
        description="FREE - Meta's flagship model for comprehensive analysis",
        best_for="Deep analysis, complex reasoning, detailed reports",
        speed="medium",
    ),
}


def get_ai_model_config(mode_id: str) -> Optional[AIModelConfig]:
    """Get AI model configuration by mode ID"""
    return AI_MODELS.get(mode_id)


def is_ai_model_mode(mode: str) -> bool:
    """Check if the mode is an AI model (not RAG/Graph)"""
    return mode in AI_MODELS


def get_model_path(mode_id: str) -> str:
    """Get LiteLLM model path for a mode"""
    config = get_ai_model_config(mode_id)
    if config:
        return config.model_path
    return None


def get_all_ai_models() -> list:
    """Get list of all AI model configs"""
    return list(AI_MODELS.values())


# ============================================================================
# AI MODEL SYSTEM PROMPTS
# ============================================================================

AI_MODEL_SYSTEM_PROMPT = """You are an AI Business Analyst. Answer business questions accurately and concisely.

RULES:
1. Be direct and data-driven
2. Use tables for structured data
3. Use the user's preferred currency
4. If data is not provided, say "I don't have access to your data for this query"
5. Never invent numbers or statistics

For business queries, provide:
1. **One-line answer** (bolded)
2. Supporting details or table
3. Brief insight if applicable

Be professional, confident, and concise."""


def get_ai_model_system_prompt(model_id: str = None) -> str:
    """Get system prompt for AI model mode"""
    return AI_MODEL_SYSTEM_PROMPT