Grok-4 support
This commit is contained in:
@@ -202,7 +202,7 @@ class ModelProvider(ABC):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
**kwargs,
|
||||
) -> ModelResponse:
|
||||
|
||||
@@ -236,7 +236,7 @@ class CustomProvider(OpenAICompatibleProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
**kwargs,
|
||||
) -> ModelResponse:
|
||||
|
||||
@@ -375,7 +375,7 @@ class DIALModelProvider(OpenAICompatibleProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
images: Optional[list[str]] = None,
|
||||
**kwargs,
|
||||
|
||||
@@ -155,7 +155,7 @@ class GeminiModelProvider(ModelProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
thinking_mode: str = "medium",
|
||||
images: Optional[list[str]] = None,
|
||||
|
||||
@@ -389,7 +389,7 @@ class OpenAICompatibleProvider(ModelProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
images: Optional[list[str]] = None,
|
||||
**kwargs,
|
||||
|
||||
@@ -221,7 +221,7 @@ class OpenAIModelProvider(OpenAICompatibleProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
**kwargs,
|
||||
) -> ModelResponse:
|
||||
|
||||
@@ -158,7 +158,7 @@ class OpenRouterProvider(OpenAICompatibleProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
**kwargs,
|
||||
) -> ModelResponse:
|
||||
|
||||
@@ -24,6 +24,24 @@ class XAIModelProvider(OpenAICompatibleProvider):
|
||||
|
||||
# Model configurations using ModelCapabilities objects
|
||||
SUPPORTED_MODELS = {
|
||||
"grok-4": ModelCapabilities(
|
||||
provider=ProviderType.XAI,
|
||||
model_name="grok-4",
|
||||
friendly_name="X.AI (Grok 4)",
|
||||
context_window=256_000, # 256K tokens
|
||||
max_output_tokens=256_000, # 256K tokens max output
|
||||
supports_extended_thinking=True, # Grok-4 supports reasoning mode
|
||||
supports_system_prompts=True,
|
||||
supports_streaming=True,
|
||||
supports_function_calling=True, # Function calling supported
|
||||
supports_json_mode=True, # Structured outputs supported
|
||||
supports_images=True, # Multimodal capabilities
|
||||
max_image_size_mb=20.0, # Standard image size limit
|
||||
supports_temperature=True,
|
||||
temperature_constraint=create_temperature_constraint("range"),
|
||||
description="GROK-4 (256K context) - Frontier multimodal reasoning model with advanced capabilities",
|
||||
aliases=["grok", "grok4", "grok-4"],
|
||||
),
|
||||
"grok-3": ModelCapabilities(
|
||||
provider=ProviderType.XAI,
|
||||
model_name="grok-3",
|
||||
@@ -40,7 +58,7 @@ class XAIModelProvider(OpenAICompatibleProvider):
|
||||
supports_temperature=True,
|
||||
temperature_constraint=create_temperature_constraint("range"),
|
||||
description="GROK-3 (131K context) - Advanced reasoning model from X.AI, excellent for complex analysis",
|
||||
aliases=["grok", "grok3"],
|
||||
aliases=["grok3"],
|
||||
),
|
||||
"grok-3-fast": ModelCapabilities(
|
||||
provider=ProviderType.XAI,
|
||||
@@ -113,7 +131,7 @@ class XAIModelProvider(OpenAICompatibleProvider):
|
||||
prompt: str,
|
||||
model_name: str,
|
||||
system_prompt: Optional[str] = None,
|
||||
temperature: float = 0.7,
|
||||
temperature: float = 0.3,
|
||||
max_output_tokens: Optional[int] = None,
|
||||
**kwargs,
|
||||
) -> ModelResponse:
|
||||
@@ -133,8 +151,10 @@ class XAIModelProvider(OpenAICompatibleProvider):
|
||||
|
||||
def supports_thinking_mode(self, model_name: str) -> bool:
|
||||
"""Check if the model supports extended thinking mode."""
|
||||
# Currently GROK models do not support extended thinking
|
||||
# This may change with future GROK model releases
|
||||
resolved_name = self._resolve_model_name(model_name)
|
||||
capabilities = self.SUPPORTED_MODELS.get(resolved_name)
|
||||
if capabilities:
|
||||
return capabilities.supports_extended_thinking
|
||||
return False
|
||||
|
||||
def get_preferred_model(self, category: "ToolModelCategory", allowed_models: list[str]) -> Optional[str]:
|
||||
@@ -153,22 +173,28 @@ class XAIModelProvider(OpenAICompatibleProvider):
|
||||
return None
|
||||
|
||||
if category == ToolModelCategory.EXTENDED_REASONING:
|
||||
# Prefer GROK-3 for reasoning
|
||||
if "grok-3" in allowed_models:
|
||||
# Prefer GROK-4 for advanced reasoning with thinking mode
|
||||
if "grok-4" in allowed_models:
|
||||
return "grok-4"
|
||||
elif "grok-3" in allowed_models:
|
||||
return "grok-3"
|
||||
# Fall back to any available model
|
||||
return allowed_models[0]
|
||||
|
||||
elif category == ToolModelCategory.FAST_RESPONSE:
|
||||
# Prefer GROK-3-Fast for speed
|
||||
# Prefer GROK-3-Fast for speed, then GROK-4
|
||||
if "grok-3-fast" in allowed_models:
|
||||
return "grok-3-fast"
|
||||
elif "grok-4" in allowed_models:
|
||||
return "grok-4"
|
||||
# Fall back to any available model
|
||||
return allowed_models[0]
|
||||
|
||||
else: # BALANCED or default
|
||||
# Prefer standard GROK-3 for balanced use
|
||||
if "grok-3" in allowed_models:
|
||||
# Prefer GROK-4 for balanced use (best overall capabilities)
|
||||
if "grok-4" in allowed_models:
|
||||
return "grok-4"
|
||||
elif "grok-3" in allowed_models:
|
||||
return "grok-3"
|
||||
elif "grok-3-fast" in allowed_models:
|
||||
return "grok-3-fast"
|
||||
|
||||
Reference in New Issue
Block a user