Skip to content

Implement xAI (Grok) Model Provider #70

@Furisto

Description

@Furisto

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

  1. Provider Structure

    • Create `XAIProvider` struct with xAI client
    • Implement proper initialization with API key validation
    • Add configuration options support
  2. Core Functionality

    • Implement `InvokeModel` method with streaming support
    • Handle request/response transformation
    • Implement proper error handling and logging
  3. Message Handling

    • Transform internal Message format to xAI API format
    • Support user, assistant, and tool messages
    • Handle system prompts appropriately
  4. Tool/Function Calling

    • Transform tools to xAI format
    • Handle tool calling responses
    • Support multiple tool calls
  5. Streaming Support

    • Implement streaming chunk handling
    • Accumulate streamed responses
    • Handle stream errors gracefully
  6. 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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions