Overview
The xAI provider is not implemented. Only model definitions exist (`grok-code-fast-1`, `grok-4-0709`, `grok-3`, `grok-3-mini`), but there is no provider implementation to invoke these models.
Current State
- ✅ Model definitions exist for all supported Grok models
- ✅ Pricing and capabilities defined
- ❌ No XAIProvider struct implementation
- ❌ No InvokeModel method
- ❌ No message transformation
- ❌ No tool/function calling support
- ❌ No tests
What Needs to be Done
Implement a complete xAI provider following the established patterns from OpenAI and Gemini providers.
Implementation Requirements
-
Provider Structure
- Create `XAIProvider` struct with xAI client
- Implement proper initialization with API key validation
- Add configuration options support
-
Core Functionality
- Implement `InvokeModel` method with streaming support
- Handle request/response transformation
- Implement proper error handling and logging
-
Message Handling
- Transform internal Message format to xAI API format
- Support user, assistant, and tool messages
- Handle system prompts appropriately
-
Tool/Function Calling
- Transform tools to xAI format
- Handle tool calling responses
- Support multiple tool calls
-
Streaming Support
- Implement streaming chunk handling
- Accumulate streamed responses
- Handle stream errors gracefully
-
Token Usage Tracking
- Track input and output tokens
- Calculate and report token metrics
- Handle cache tokens if supported
Files to Modify/Create
- `backend/model/xai.go` - Implement XAIProvider
- `backend/model/xai_test.go` - Create comprehensive test file
Implementation Pattern
Follow the patterns established in:
- `backend/model/openai_completion.go`
- `backend/model/gemini.go`
References
- xAI API Documentation
- OpenAI Provider: `backend/model/openai_completion.go`
- Gemini Provider: `backend/model/gemini.go`
- Provider interface: `backend/model/provider.go`
Overview
The xAI provider is not implemented. Only model definitions exist (`grok-code-fast-1`, `grok-4-0709`, `grok-3`, `grok-3-mini`), but there is no provider implementation to invoke these models.
Current State
What Needs to be Done
Implement a complete xAI provider following the established patterns from OpenAI and Gemini providers.
Implementation Requirements
Provider Structure
Core Functionality
Message Handling
Tool/Function Calling
Streaming Support
Token Usage Tracking
Files to Modify/Create
Implementation Pattern
Follow the patterns established in:
References