Grok
Grok integration is implemented using the OpenAI SDK with a custom base URL, supporting the 'grok-2-latest' model and function calling capabilities.
Implementation
Provider Setup
class GrokProvider implements LLMProvider {
private client: OpenAI;
constructor() {
this.client = new OpenAI({
apiKey: process.env.XAI_API_KEY,
baseURL: 'https://api.x.ai/v1',
});
}
}Message Generation
async generateResponse(
messages: Array<{ role: string; content: string }>,
cleanContent: string
): Promise<LLMResponse> {
const formattedMessages = messages.map(msg => ({
role: msg.role as 'user' | 'assistant' | 'system',
content: msg.content
}));
const response = await this.client.chat.completions.create({
model: 'grok-2-latest',
messages: formattedMessages,
tools: [/* function definitions */]
});
}Features
Supported Capabilities
Function Tools
Configuration
Environment Setup
API Configuration
Best Practices
Setup
Message Processing
Related Documentation
Last updated