forked from RichardAtCT/claude-code-openai-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel_utils.py
More file actions
103 lines (78 loc) · 3.67 KB
/
model_utils.py
File metadata and controls
103 lines (78 loc) · 3.67 KB
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
"""
Model name utilities for handling chat mode and progress markers via model suffix.
This module provides utilities for parsing model names to determine
whether chat mode should be activated and whether progress markers
should be shown based on model suffixes.
"""
from typing import Tuple
import logging
logger = logging.getLogger(__name__)
class ModelUtils:
"""Utilities for handling model names and mode detection."""
CHAT_SUFFIX = "-chat"
CHAT_PROGRESS_SUFFIX = "-chat-progress"
@classmethod
def parse_model_and_mode(cls, model_name: str) -> Tuple[str, bool, bool]:
"""
Parse model name to extract base model, chat mode, and progress markers.
Args:
model_name: The full model name, potentially with suffixes
Returns:
tuple: (base_model_name, is_chat_mode, show_progress_markers)
Examples:
>>> ModelUtils.parse_model_and_mode("claude-3-5-sonnet-20241022")
("claude-3-5-sonnet-20241022", False, False)
>>> ModelUtils.parse_model_and_mode("claude-3-5-sonnet-20241022-chat")
("claude-3-5-sonnet-20241022", True, False)
>>> ModelUtils.parse_model_and_mode("claude-3-5-sonnet-20241022-chat-progress")
("claude-3-5-sonnet-20241022", True, True)
"""
# Check for -chat-progress suffix first (it's more specific)
if model_name.endswith(cls.CHAT_PROGRESS_SUFFIX):
base_model = model_name[:-len(cls.CHAT_PROGRESS_SUFFIX)]
logger.debug(f"Detected chat mode with progress markers: {model_name} -> base: {base_model}")
return base_model, True, True
# Check for -chat suffix
if model_name.endswith(cls.CHAT_SUFFIX):
base_model = model_name[:-len(cls.CHAT_SUFFIX)]
logger.debug(f"Detected chat mode model: {model_name} -> base: {base_model}")
return base_model, True, False
# Standard model - no chat mode, no progress markers
logger.debug(f"Standard model detected: {model_name}")
return model_name, False, False
@classmethod
def create_chat_variant(cls, base_model: str) -> str:
"""
Create chat mode variant name for a base model.
Args:
base_model: The base model name without suffix
Returns:
str: The chat mode variant with -chat suffix
Example:
>>> ModelUtils.create_chat_variant("claude-3-5-sonnet-20241022")
"claude-3-5-sonnet-20241022-chat"
"""
return f"{base_model}{cls.CHAT_SUFFIX}"
@classmethod
def create_chat_progress_variant(cls, base_model: str) -> str:
"""
Create chat mode with progress markers variant name for a base model.
Args:
base_model: The base model name without suffix
Returns:
str: The chat mode variant with -chat-progress suffix
Example:
>>> ModelUtils.create_chat_progress_variant("claude-3-5-sonnet-20241022")
"claude-3-5-sonnet-20241022-chat-progress"
"""
return f"{base_model}{cls.CHAT_PROGRESS_SUFFIX}"
@classmethod
def is_chat_mode_model(cls, model_name: str) -> bool:
"""
Quick check if a model name indicates chat mode.
Args:
model_name: The model name to check
Returns:
bool: True if model name ends with -chat or -chat-progress suffix
"""
return model_name.endswith(cls.CHAT_SUFFIX) or model_name.endswith(cls.CHAT_PROGRESS_SUFFIX)