shotgun-sh 0.1.16.dev2__py3-none-any.whl → 0.2.1.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of shotgun-sh might be problematic. Click here for more details.
- shotgun/agents/common.py +4 -5
- shotgun/agents/config/constants.py +21 -5
- shotgun/agents/config/manager.py +149 -57
- shotgun/agents/config/models.py +65 -84
- shotgun/agents/config/provider.py +172 -84
- shotgun/agents/history/compaction.py +1 -1
- shotgun/agents/history/history_processors.py +18 -9
- shotgun/agents/history/token_counting/__init__.py +31 -0
- shotgun/agents/history/token_counting/anthropic.py +89 -0
- shotgun/agents/history/token_counting/base.py +67 -0
- shotgun/agents/history/token_counting/openai.py +80 -0
- shotgun/agents/history/token_counting/sentencepiece_counter.py +119 -0
- shotgun/agents/history/token_counting/tokenizer_cache.py +90 -0
- shotgun/agents/history/token_counting/utils.py +147 -0
- shotgun/agents/history/token_estimation.py +12 -12
- shotgun/agents/llm.py +62 -0
- shotgun/agents/models.py +2 -2
- shotgun/agents/tools/web_search/__init__.py +42 -15
- shotgun/agents/tools/web_search/anthropic.py +54 -50
- shotgun/agents/tools/web_search/gemini.py +31 -20
- shotgun/agents/tools/web_search/openai.py +4 -4
- shotgun/cli/config.py +14 -55
- shotgun/cli/models.py +2 -2
- shotgun/codebase/models.py +4 -4
- shotgun/llm_proxy/__init__.py +16 -0
- shotgun/llm_proxy/clients.py +39 -0
- shotgun/llm_proxy/constants.py +8 -0
- shotgun/main.py +6 -0
- shotgun/posthog_telemetry.py +5 -3
- shotgun/tui/app.py +2 -0
- shotgun/tui/screens/chat_screen/command_providers.py +20 -0
- shotgun/tui/screens/model_picker.py +215 -0
- shotgun/tui/screens/provider_config.py +39 -26
- {shotgun_sh-0.1.16.dev2.dist-info → shotgun_sh-0.2.1.dev2.dist-info}/METADATA +2 -2
- {shotgun_sh-0.1.16.dev2.dist-info → shotgun_sh-0.2.1.dev2.dist-info}/RECORD +38 -27
- shotgun/agents/history/token_counting.py +0 -429
- {shotgun_sh-0.1.16.dev2.dist-info → shotgun_sh-0.2.1.dev2.dist-info}/WHEEL +0 -0
- {shotgun_sh-0.1.16.dev2.dist-info → shotgun_sh-0.2.1.dev2.dist-info}/entry_points.txt +0 -0
- {shotgun_sh-0.1.16.dev2.dist-info → shotgun_sh-0.2.1.dev2.dist-info}/licenses/LICENSE +0 -0
shotgun/agents/common.py
CHANGED
|
@@ -18,7 +18,7 @@ from pydantic_ai.messages import (
|
|
|
18
18
|
ModelRequest,
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
from shotgun.agents.config import ProviderType,
|
|
21
|
+
from shotgun.agents.config import ProviderType, get_provider_model
|
|
22
22
|
from shotgun.agents.models import AgentType
|
|
23
23
|
from shotgun.logging_config import get_logger
|
|
24
24
|
from shotgun.prompts import PromptLoader
|
|
@@ -115,14 +115,13 @@ def create_base_agent(
|
|
|
115
115
|
"""
|
|
116
116
|
ensure_shotgun_directory_exists()
|
|
117
117
|
|
|
118
|
-
# Get configured model or fall back to
|
|
118
|
+
# Get configured model or fall back to first available provider
|
|
119
119
|
try:
|
|
120
120
|
model_config = get_provider_model(provider)
|
|
121
|
-
|
|
122
|
-
provider_name = provider or config_manager.load().default_provider
|
|
121
|
+
provider_name = model_config.provider
|
|
123
122
|
logger.debug(
|
|
124
123
|
"🤖 Creating agent with configured %s model: %s",
|
|
125
|
-
provider_name.upper(),
|
|
124
|
+
provider_name.value.upper(),
|
|
126
125
|
model_config.name,
|
|
127
126
|
)
|
|
128
127
|
# Use the Model instance directly (has API key baked in)
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
"""Configuration constants for Shotgun agents."""
|
|
2
2
|
|
|
3
|
+
from enum import StrEnum, auto
|
|
4
|
+
|
|
3
5
|
# Field names
|
|
4
6
|
API_KEY_FIELD = "api_key"
|
|
5
|
-
DEFAULT_PROVIDER_FIELD = "default_provider"
|
|
6
7
|
USER_ID_FIELD = "user_id"
|
|
7
8
|
CONFIG_VERSION_FIELD = "config_version"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
class ConfigSection(StrEnum):
|
|
12
|
+
"""Configuration file section names (JSON keys)."""
|
|
13
|
+
|
|
14
|
+
OPENAI = auto()
|
|
15
|
+
ANTHROPIC = auto()
|
|
16
|
+
GOOGLE = auto()
|
|
17
|
+
SHOTGUN = auto()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Backwards compatibility - deprecated
|
|
21
|
+
OPENAI_PROVIDER = ConfigSection.OPENAI.value
|
|
22
|
+
ANTHROPIC_PROVIDER = ConfigSection.ANTHROPIC.value
|
|
23
|
+
GOOGLE_PROVIDER = ConfigSection.GOOGLE.value
|
|
24
|
+
SHOTGUN_PROVIDER = ConfigSection.SHOTGUN.value
|
|
13
25
|
|
|
14
26
|
# Environment variable names
|
|
15
27
|
OPENAI_API_KEY_ENV = "OPENAI_API_KEY"
|
|
16
28
|
ANTHROPIC_API_KEY_ENV = "ANTHROPIC_API_KEY"
|
|
17
29
|
GEMINI_API_KEY_ENV = "GEMINI_API_KEY"
|
|
30
|
+
SHOTGUN_API_KEY_ENV = "SHOTGUN_API_KEY"
|
|
31
|
+
|
|
32
|
+
# Token limits
|
|
33
|
+
MEDIUM_TEXT_8K_TOKENS = 8192 # Default max_tokens for web search requests
|
shotgun/agents/config/manager.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Configuration manager for Shotgun CLI."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
import os
|
|
5
4
|
import uuid
|
|
6
5
|
from pathlib import Path
|
|
7
6
|
from typing import Any
|
|
@@ -12,18 +11,24 @@ from shotgun.logging_config import get_logger
|
|
|
12
11
|
from shotgun.utils import get_shotgun_home
|
|
13
12
|
|
|
14
13
|
from .constants import (
|
|
15
|
-
ANTHROPIC_API_KEY_ENV,
|
|
16
|
-
ANTHROPIC_PROVIDER,
|
|
17
14
|
API_KEY_FIELD,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
ConfigSection,
|
|
16
|
+
)
|
|
17
|
+
from .models import (
|
|
18
|
+
AnthropicConfig,
|
|
19
|
+
GoogleConfig,
|
|
20
|
+
ModelName,
|
|
21
|
+
OpenAIConfig,
|
|
22
|
+
ProviderType,
|
|
23
|
+
ShotgunAccountConfig,
|
|
24
|
+
ShotgunConfig,
|
|
22
25
|
)
|
|
23
|
-
from .models import ProviderType, ShotgunConfig
|
|
24
26
|
|
|
25
27
|
logger = get_logger(__name__)
|
|
26
28
|
|
|
29
|
+
# Type alias for provider configuration objects
|
|
30
|
+
ProviderConfig = OpenAIConfig | AnthropicConfig | GoogleConfig | ShotgunAccountConfig
|
|
31
|
+
|
|
27
32
|
|
|
28
33
|
class ConfigManager:
|
|
29
34
|
"""Manager for Shotgun configuration."""
|
|
@@ -69,20 +74,56 @@ class ConfigManager:
|
|
|
69
74
|
self._config = ShotgunConfig.model_validate(data)
|
|
70
75
|
logger.debug("Configuration loaded successfully from %s", self.config_path)
|
|
71
76
|
|
|
72
|
-
#
|
|
73
|
-
if not self.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
# Validate selected_model if in BYOK mode (no Shotgun key)
|
|
78
|
+
if not self._provider_has_api_key(self._config.shotgun):
|
|
79
|
+
should_save = False
|
|
80
|
+
|
|
81
|
+
# If selected_model is set, verify its provider has a key
|
|
82
|
+
if self._config.selected_model:
|
|
83
|
+
from .models import MODEL_SPECS
|
|
84
|
+
|
|
85
|
+
if self._config.selected_model in MODEL_SPECS:
|
|
86
|
+
spec = MODEL_SPECS[self._config.selected_model]
|
|
87
|
+
if not self.has_provider_key(spec.provider):
|
|
88
|
+
logger.info(
|
|
89
|
+
"Selected model %s provider has no API key, finding available model",
|
|
90
|
+
self._config.selected_model.value,
|
|
91
|
+
)
|
|
92
|
+
self._config.selected_model = None
|
|
93
|
+
should_save = True
|
|
94
|
+
else:
|
|
78
95
|
logger.info(
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
provider.value,
|
|
96
|
+
"Selected model %s not found in MODEL_SPECS, resetting",
|
|
97
|
+
self._config.selected_model.value,
|
|
82
98
|
)
|
|
83
|
-
self._config.
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
self._config.selected_model = None
|
|
100
|
+
should_save = True
|
|
101
|
+
|
|
102
|
+
# If no selected_model or it was invalid, find first available model
|
|
103
|
+
if not self._config.selected_model:
|
|
104
|
+
for provider in ProviderType:
|
|
105
|
+
if self.has_provider_key(provider):
|
|
106
|
+
# Set to that provider's default model
|
|
107
|
+
from .models import MODEL_SPECS, ModelName
|
|
108
|
+
|
|
109
|
+
# Find default model for this provider
|
|
110
|
+
provider_models = {
|
|
111
|
+
ProviderType.OPENAI: ModelName.GPT_5,
|
|
112
|
+
ProviderType.ANTHROPIC: ModelName.CLAUDE_OPUS_4_1,
|
|
113
|
+
ProviderType.GOOGLE: ModelName.GEMINI_2_5_PRO,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if provider in provider_models:
|
|
117
|
+
self._config.selected_model = provider_models[provider]
|
|
118
|
+
logger.info(
|
|
119
|
+
"Set selected_model to %s (first available provider)",
|
|
120
|
+
self._config.selected_model.value,
|
|
121
|
+
)
|
|
122
|
+
should_save = True
|
|
123
|
+
break
|
|
124
|
+
|
|
125
|
+
if should_save:
|
|
126
|
+
self.save(self._config)
|
|
86
127
|
|
|
87
128
|
return self._config
|
|
88
129
|
|
|
@@ -107,7 +148,6 @@ class ConfigManager:
|
|
|
107
148
|
# Create a new config with generated user_id
|
|
108
149
|
config = ShotgunConfig(
|
|
109
150
|
user_id=str(uuid.uuid4()),
|
|
110
|
-
config_version=1,
|
|
111
151
|
)
|
|
112
152
|
|
|
113
153
|
# Ensure directory exists
|
|
@@ -136,8 +176,13 @@ class ConfigManager:
|
|
|
136
176
|
**kwargs: Configuration fields to update (only api_key supported)
|
|
137
177
|
"""
|
|
138
178
|
config = self.load()
|
|
139
|
-
|
|
140
|
-
|
|
179
|
+
|
|
180
|
+
# Get provider config and check if it's shotgun
|
|
181
|
+
provider_config, is_shotgun = self._get_provider_config_and_type(
|
|
182
|
+
config, provider
|
|
183
|
+
)
|
|
184
|
+
# For non-shotgun providers, we need the enum for default provider logic
|
|
185
|
+
provider_enum = None if is_shotgun else self._ensure_provider_enum(provider)
|
|
141
186
|
|
|
142
187
|
# Only support api_key updates
|
|
143
188
|
if API_KEY_FIELD in kwargs:
|
|
@@ -152,50 +197,63 @@ class ConfigManager:
|
|
|
152
197
|
raise ValueError(f"Unsupported configuration fields: {unsupported_fields}")
|
|
153
198
|
|
|
154
199
|
# If no other providers have keys configured and we just added one,
|
|
155
|
-
# set
|
|
156
|
-
if API_KEY_FIELD in kwargs and api_key_value is not None:
|
|
200
|
+
# set selected_model to that provider's default model (only for LLM providers, not shotgun)
|
|
201
|
+
if not is_shotgun and API_KEY_FIELD in kwargs and api_key_value is not None:
|
|
202
|
+
# provider_enum is guaranteed to be non-None here since is_shotgun is False
|
|
203
|
+
if provider_enum is None:
|
|
204
|
+
raise RuntimeError("Provider enum should not be None for LLM providers")
|
|
157
205
|
other_providers = [p for p in ProviderType if p != provider_enum]
|
|
158
206
|
has_other_keys = any(self.has_provider_key(p) for p in other_providers)
|
|
159
207
|
if not has_other_keys:
|
|
160
|
-
|
|
208
|
+
# Set selected_model to this provider's default model
|
|
209
|
+
from .models import ModelName
|
|
210
|
+
|
|
211
|
+
provider_models = {
|
|
212
|
+
ProviderType.OPENAI: ModelName.GPT_5,
|
|
213
|
+
ProviderType.ANTHROPIC: ModelName.CLAUDE_OPUS_4_1,
|
|
214
|
+
ProviderType.GOOGLE: ModelName.GEMINI_2_5_PRO,
|
|
215
|
+
}
|
|
216
|
+
if provider_enum in provider_models:
|
|
217
|
+
config.selected_model = provider_models[provider_enum]
|
|
161
218
|
|
|
162
219
|
self.save(config)
|
|
163
220
|
|
|
164
221
|
def clear_provider_key(self, provider: ProviderType | str) -> None:
|
|
165
|
-
"""Remove the API key for the given provider."""
|
|
222
|
+
"""Remove the API key for the given provider (LLM provider or shotgun)."""
|
|
166
223
|
config = self.load()
|
|
167
|
-
|
|
168
|
-
|
|
224
|
+
|
|
225
|
+
# Get provider config (shotgun or LLM provider)
|
|
226
|
+
provider_config, _ = self._get_provider_config_and_type(config, provider)
|
|
227
|
+
|
|
169
228
|
provider_config.api_key = None
|
|
170
229
|
self.save(config)
|
|
171
230
|
|
|
231
|
+
def update_selected_model(self, model_name: "ModelName") -> None:
|
|
232
|
+
"""Update the selected model.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
model_name: Model to select
|
|
236
|
+
"""
|
|
237
|
+
config = self.load()
|
|
238
|
+
config.selected_model = model_name
|
|
239
|
+
self.save(config)
|
|
240
|
+
|
|
172
241
|
def has_provider_key(self, provider: ProviderType | str) -> bool:
|
|
173
242
|
"""Check if the given provider has a non-empty API key configured.
|
|
174
243
|
|
|
175
|
-
This checks
|
|
244
|
+
This checks only the configuration file.
|
|
176
245
|
"""
|
|
177
246
|
config = self.load()
|
|
178
247
|
provider_enum = self._ensure_provider_enum(provider)
|
|
179
248
|
provider_config = self._get_provider_config(config, provider_enum)
|
|
180
249
|
|
|
181
|
-
|
|
182
|
-
if self._provider_has_api_key(provider_config):
|
|
183
|
-
return True
|
|
184
|
-
|
|
185
|
-
# Check environment variable
|
|
186
|
-
if provider_enum == ProviderType.OPENAI:
|
|
187
|
-
return bool(os.getenv(OPENAI_API_KEY_ENV))
|
|
188
|
-
elif provider_enum == ProviderType.ANTHROPIC:
|
|
189
|
-
return bool(os.getenv(ANTHROPIC_API_KEY_ENV))
|
|
190
|
-
elif provider_enum == ProviderType.GOOGLE:
|
|
191
|
-
return bool(os.getenv(GEMINI_API_KEY_ENV))
|
|
192
|
-
|
|
193
|
-
return False
|
|
250
|
+
return self._provider_has_api_key(provider_config)
|
|
194
251
|
|
|
195
252
|
def has_any_provider_key(self) -> bool:
|
|
196
253
|
"""Determine whether any provider has a configured API key."""
|
|
197
254
|
config = self.load()
|
|
198
|
-
|
|
255
|
+
# Check LLM provider keys (BYOK)
|
|
256
|
+
has_llm_key = any(
|
|
199
257
|
self._provider_has_api_key(self._get_provider_config(config, provider))
|
|
200
258
|
for provider in (
|
|
201
259
|
ProviderType.OPENAI,
|
|
@@ -203,6 +261,9 @@ class ConfigManager:
|
|
|
203
261
|
ProviderType.GOOGLE,
|
|
204
262
|
)
|
|
205
263
|
)
|
|
264
|
+
# Also check Shotgun Account key
|
|
265
|
+
has_shotgun_key = self._provider_has_api_key(config.shotgun)
|
|
266
|
+
return has_llm_key or has_shotgun_key
|
|
206
267
|
|
|
207
268
|
def initialize(self) -> ShotgunConfig:
|
|
208
269
|
"""Initialize configuration with defaults and save to file.
|
|
@@ -213,7 +274,6 @@ class ConfigManager:
|
|
|
213
274
|
# Generate unique user ID for new config
|
|
214
275
|
config = ShotgunConfig(
|
|
215
276
|
user_id=str(uuid.uuid4()),
|
|
216
|
-
config_version=1,
|
|
217
277
|
)
|
|
218
278
|
self.save(config)
|
|
219
279
|
logger.info(
|
|
@@ -225,26 +285,26 @@ class ConfigManager:
|
|
|
225
285
|
|
|
226
286
|
def _convert_secrets_to_secretstr(self, data: dict[str, Any]) -> None:
|
|
227
287
|
"""Convert plain text secrets in data to SecretStr objects."""
|
|
228
|
-
for
|
|
229
|
-
if
|
|
288
|
+
for section in ConfigSection:
|
|
289
|
+
if section.value in data and isinstance(data[section.value], dict):
|
|
230
290
|
if (
|
|
231
|
-
API_KEY_FIELD in data[
|
|
232
|
-
and data[
|
|
291
|
+
API_KEY_FIELD in data[section.value]
|
|
292
|
+
and data[section.value][API_KEY_FIELD] is not None
|
|
233
293
|
):
|
|
234
|
-
data[
|
|
235
|
-
data[
|
|
294
|
+
data[section.value][API_KEY_FIELD] = SecretStr(
|
|
295
|
+
data[section.value][API_KEY_FIELD]
|
|
236
296
|
)
|
|
237
297
|
|
|
238
298
|
def _convert_secretstr_to_plain(self, data: dict[str, Any]) -> None:
|
|
239
299
|
"""Convert SecretStr objects in data to plain text for JSON serialization."""
|
|
240
|
-
for
|
|
241
|
-
if
|
|
300
|
+
for section in ConfigSection:
|
|
301
|
+
if section.value in data and isinstance(data[section.value], dict):
|
|
242
302
|
if (
|
|
243
|
-
API_KEY_FIELD in data[
|
|
244
|
-
and data[
|
|
303
|
+
API_KEY_FIELD in data[section.value]
|
|
304
|
+
and data[section.value][API_KEY_FIELD] is not None
|
|
245
305
|
):
|
|
246
|
-
if hasattr(data[
|
|
247
|
-
data[
|
|
306
|
+
if hasattr(data[section.value][API_KEY_FIELD], "get_secret_value"):
|
|
307
|
+
data[section.value][API_KEY_FIELD] = data[section.value][
|
|
248
308
|
API_KEY_FIELD
|
|
249
309
|
].get_secret_value()
|
|
250
310
|
|
|
@@ -279,6 +339,38 @@ class ConfigManager:
|
|
|
279
339
|
|
|
280
340
|
return bool(value.strip())
|
|
281
341
|
|
|
342
|
+
def _is_shotgun_provider(self, provider: ProviderType | str) -> bool:
|
|
343
|
+
"""Check if provider string represents Shotgun Account.
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
provider: Provider type or string
|
|
347
|
+
|
|
348
|
+
Returns:
|
|
349
|
+
True if provider is shotgun account
|
|
350
|
+
"""
|
|
351
|
+
return (
|
|
352
|
+
isinstance(provider, str)
|
|
353
|
+
and provider.lower() == ConfigSection.SHOTGUN.value
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
def _get_provider_config_and_type(
|
|
357
|
+
self, config: ShotgunConfig, provider: ProviderType | str
|
|
358
|
+
) -> tuple[ProviderConfig, bool]:
|
|
359
|
+
"""Get provider config, handling shotgun as special case.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
config: Shotgun configuration
|
|
363
|
+
provider: Provider type or string
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
Tuple of (provider_config, is_shotgun)
|
|
367
|
+
"""
|
|
368
|
+
if self._is_shotgun_provider(provider):
|
|
369
|
+
return (config.shotgun, True)
|
|
370
|
+
|
|
371
|
+
provider_enum = self._ensure_provider_enum(provider)
|
|
372
|
+
return (self._get_provider_config(config, provider_enum), False)
|
|
373
|
+
|
|
282
374
|
def get_user_id(self) -> str:
|
|
283
375
|
"""Get the user ID from configuration.
|
|
284
376
|
|
shotgun/agents/config/models.py
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"""Pydantic models for configuration."""
|
|
2
2
|
|
|
3
|
-
from enum import
|
|
4
|
-
from typing import Any
|
|
3
|
+
from enum import StrEnum
|
|
5
4
|
|
|
6
5
|
from pydantic import BaseModel, Field, PrivateAttr, SecretStr
|
|
7
|
-
from pydantic_ai.direct import model_request
|
|
8
|
-
from pydantic_ai.messages import ModelMessage, ModelResponse
|
|
9
6
|
from pydantic_ai.models import Model
|
|
10
|
-
from pydantic_ai.settings import ModelSettings
|
|
11
7
|
|
|
12
8
|
|
|
13
|
-
class ProviderType(
|
|
9
|
+
class ProviderType(StrEnum):
|
|
14
10
|
"""Provider types for AI services."""
|
|
15
11
|
|
|
16
12
|
OPENAI = "openai"
|
|
@@ -18,20 +14,42 @@ class ProviderType(str, Enum):
|
|
|
18
14
|
GOOGLE = "google"
|
|
19
15
|
|
|
20
16
|
|
|
17
|
+
class KeyProvider(StrEnum):
|
|
18
|
+
"""Authentication method for accessing AI models."""
|
|
19
|
+
|
|
20
|
+
BYOK = "byok" # Bring Your Own Key (individual provider keys)
|
|
21
|
+
SHOTGUN = "shotgun" # Shotgun Account (unified LiteLLM proxy)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ModelName(StrEnum):
|
|
25
|
+
"""Available AI model names."""
|
|
26
|
+
|
|
27
|
+
GPT_5 = "gpt-5"
|
|
28
|
+
GPT_5_MINI = "gpt-5-mini"
|
|
29
|
+
CLAUDE_OPUS_4_1 = "claude-opus-4-1"
|
|
30
|
+
CLAUDE_SONNET_4_5 = "claude-sonnet-4-5"
|
|
31
|
+
GEMINI_2_5_PRO = "gemini-2.5-pro"
|
|
32
|
+
GEMINI_2_5_FLASH = "gemini-2.5-flash"
|
|
33
|
+
|
|
34
|
+
|
|
21
35
|
class ModelSpec(BaseModel):
|
|
22
36
|
"""Static specification for a model - just metadata."""
|
|
23
37
|
|
|
24
|
-
name:
|
|
38
|
+
name: ModelName # Model identifier
|
|
25
39
|
provider: ProviderType
|
|
26
40
|
max_input_tokens: int
|
|
27
41
|
max_output_tokens: int
|
|
42
|
+
litellm_proxy_model_name: (
|
|
43
|
+
str # LiteLLM format (e.g., "openai/gpt-5", "gemini/gemini-2-pro")
|
|
44
|
+
)
|
|
28
45
|
|
|
29
46
|
|
|
30
47
|
class ModelConfig(BaseModel):
|
|
31
48
|
"""A fully configured model with API key and settings."""
|
|
32
49
|
|
|
33
|
-
name:
|
|
34
|
-
provider: ProviderType
|
|
50
|
+
name: ModelName # Model identifier
|
|
51
|
+
provider: ProviderType # Actual LLM provider (openai, anthropic, google)
|
|
52
|
+
key_provider: KeyProvider # Authentication method (byok or shotgun)
|
|
35
53
|
max_input_tokens: int
|
|
36
54
|
max_output_tokens: int
|
|
37
55
|
api_key: str
|
|
@@ -47,7 +65,7 @@ class ModelConfig(BaseModel):
|
|
|
47
65
|
from .provider import get_or_create_model
|
|
48
66
|
|
|
49
67
|
self._model_instance = get_or_create_model(
|
|
50
|
-
self.provider, self.name, self.api_key
|
|
68
|
+
self.provider, self.key_provider, self.name, self.api_key
|
|
51
69
|
)
|
|
52
70
|
return self._model_instance
|
|
53
71
|
|
|
@@ -61,54 +79,50 @@ class ModelConfig(BaseModel):
|
|
|
61
79
|
}
|
|
62
80
|
return f"{provider_prefix[self.provider]}:{self.name}"
|
|
63
81
|
|
|
64
|
-
def get_model_settings(self, max_tokens: int | None = None) -> ModelSettings:
|
|
65
|
-
"""Get ModelSettings with optional token override.
|
|
66
|
-
|
|
67
|
-
This provides flexibility for specific use cases that need different
|
|
68
|
-
token limits while defaulting to maximum utilization.
|
|
69
|
-
|
|
70
|
-
Args:
|
|
71
|
-
max_tokens: Optional override for max_tokens. If None, uses max_output_tokens
|
|
72
|
-
|
|
73
|
-
Returns:
|
|
74
|
-
ModelSettings configured with specified or maximum tokens
|
|
75
|
-
"""
|
|
76
|
-
return ModelSettings(
|
|
77
|
-
max_tokens=max_tokens if max_tokens is not None else self.max_output_tokens
|
|
78
|
-
)
|
|
79
|
-
|
|
80
82
|
|
|
81
83
|
# Model specifications registry (static metadata)
|
|
82
|
-
MODEL_SPECS: dict[
|
|
83
|
-
|
|
84
|
-
name=
|
|
84
|
+
MODEL_SPECS: dict[ModelName, ModelSpec] = {
|
|
85
|
+
ModelName.GPT_5: ModelSpec(
|
|
86
|
+
name=ModelName.GPT_5,
|
|
85
87
|
provider=ProviderType.OPENAI,
|
|
86
88
|
max_input_tokens=400_000,
|
|
87
89
|
max_output_tokens=128_000,
|
|
90
|
+
litellm_proxy_model_name="openai/gpt-5",
|
|
88
91
|
),
|
|
89
|
-
|
|
90
|
-
name=
|
|
92
|
+
ModelName.GPT_5_MINI: ModelSpec(
|
|
93
|
+
name=ModelName.GPT_5_MINI,
|
|
91
94
|
provider=ProviderType.OPENAI,
|
|
92
|
-
max_input_tokens=
|
|
93
|
-
max_output_tokens=
|
|
95
|
+
max_input_tokens=400_000,
|
|
96
|
+
max_output_tokens=128_000,
|
|
97
|
+
litellm_proxy_model_name="openai/gpt-5-mini",
|
|
94
98
|
),
|
|
95
|
-
|
|
96
|
-
name=
|
|
99
|
+
ModelName.CLAUDE_OPUS_4_1: ModelSpec(
|
|
100
|
+
name=ModelName.CLAUDE_OPUS_4_1,
|
|
97
101
|
provider=ProviderType.ANTHROPIC,
|
|
98
102
|
max_input_tokens=200_000,
|
|
99
103
|
max_output_tokens=32_000,
|
|
104
|
+
litellm_proxy_model_name="anthropic/claude-opus-4-1",
|
|
100
105
|
),
|
|
101
|
-
|
|
102
|
-
name=
|
|
106
|
+
ModelName.CLAUDE_SONNET_4_5: ModelSpec(
|
|
107
|
+
name=ModelName.CLAUDE_SONNET_4_5,
|
|
103
108
|
provider=ProviderType.ANTHROPIC,
|
|
104
109
|
max_input_tokens=200_000,
|
|
105
|
-
max_output_tokens=
|
|
110
|
+
max_output_tokens=16_000,
|
|
111
|
+
litellm_proxy_model_name="anthropic/claude-sonnet-4-5",
|
|
112
|
+
),
|
|
113
|
+
ModelName.GEMINI_2_5_PRO: ModelSpec(
|
|
114
|
+
name=ModelName.GEMINI_2_5_PRO,
|
|
115
|
+
provider=ProviderType.GOOGLE,
|
|
116
|
+
max_input_tokens=1_000_000,
|
|
117
|
+
max_output_tokens=64_000,
|
|
118
|
+
litellm_proxy_model_name="gemini/gemini-2.5-pro",
|
|
106
119
|
),
|
|
107
|
-
|
|
108
|
-
name=
|
|
120
|
+
ModelName.GEMINI_2_5_FLASH: ModelSpec(
|
|
121
|
+
name=ModelName.GEMINI_2_5_FLASH,
|
|
109
122
|
provider=ProviderType.GOOGLE,
|
|
110
123
|
max_input_tokens=1_000_000,
|
|
111
124
|
max_output_tokens=64_000,
|
|
125
|
+
litellm_proxy_model_name="gemini/gemini-2.5-flash",
|
|
112
126
|
),
|
|
113
127
|
}
|
|
114
128
|
|
|
@@ -131,55 +145,22 @@ class GoogleConfig(BaseModel):
|
|
|
131
145
|
api_key: SecretStr | None = None
|
|
132
146
|
|
|
133
147
|
|
|
148
|
+
class ShotgunAccountConfig(BaseModel):
|
|
149
|
+
"""Configuration for Shotgun Account (LiteLLM proxy)."""
|
|
150
|
+
|
|
151
|
+
api_key: SecretStr | None = None
|
|
152
|
+
|
|
153
|
+
|
|
134
154
|
class ShotgunConfig(BaseModel):
|
|
135
155
|
"""Main configuration for Shotgun CLI."""
|
|
136
156
|
|
|
137
157
|
openai: OpenAIConfig = Field(default_factory=OpenAIConfig)
|
|
138
158
|
anthropic: AnthropicConfig = Field(default_factory=AnthropicConfig)
|
|
139
159
|
google: GoogleConfig = Field(default_factory=GoogleConfig)
|
|
140
|
-
|
|
141
|
-
|
|
160
|
+
shotgun: ShotgunAccountConfig = Field(default_factory=ShotgunAccountConfig)
|
|
161
|
+
selected_model: ModelName | None = Field(
|
|
162
|
+
default=None,
|
|
163
|
+
description="User-selected model",
|
|
142
164
|
)
|
|
143
165
|
user_id: str = Field(description="Unique anonymous user identifier")
|
|
144
|
-
config_version: int = Field(default=
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
async def shotgun_model_request(
|
|
148
|
-
model_config: ModelConfig,
|
|
149
|
-
messages: list[ModelMessage],
|
|
150
|
-
max_tokens: int | None = None,
|
|
151
|
-
**kwargs: Any,
|
|
152
|
-
) -> ModelResponse:
|
|
153
|
-
"""Model request wrapper that uses full token capacity by default.
|
|
154
|
-
|
|
155
|
-
This wrapper ensures all LLM calls in Shotgun use the maximum available
|
|
156
|
-
token capacity of each model, improving response quality and completeness.
|
|
157
|
-
The most common issue this fixes is truncated summaries that were cut off
|
|
158
|
-
at default token limits (e.g., 4096 for Claude models).
|
|
159
|
-
|
|
160
|
-
Args:
|
|
161
|
-
model_config: ModelConfig instance with model settings and API key
|
|
162
|
-
messages: Messages to send to the model
|
|
163
|
-
max_tokens: Optional override for max_tokens. If None, uses model's max_output_tokens
|
|
164
|
-
**kwargs: Additional arguments passed to model_request
|
|
165
|
-
|
|
166
|
-
Returns:
|
|
167
|
-
ModelResponse from the model
|
|
168
|
-
|
|
169
|
-
Example:
|
|
170
|
-
# Uses full token capacity (e.g., 4096 for Claude, 128k for GPT-5)
|
|
171
|
-
response = await shotgun_model_request(model_config, messages)
|
|
172
|
-
|
|
173
|
-
# Override for specific use case
|
|
174
|
-
response = await shotgun_model_request(model_config, messages, max_tokens=1000)
|
|
175
|
-
"""
|
|
176
|
-
# Get properly configured ModelSettings with maximum or overridden token limit
|
|
177
|
-
model_settings = model_config.get_model_settings(max_tokens)
|
|
178
|
-
|
|
179
|
-
# Make the model request with full token utilization
|
|
180
|
-
return await model_request(
|
|
181
|
-
model=model_config.model_instance,
|
|
182
|
-
messages=messages,
|
|
183
|
-
model_settings=model_settings,
|
|
184
|
-
**kwargs,
|
|
185
|
-
)
|
|
166
|
+
config_version: int = Field(default=2, description="Configuration schema version")
|