Skip to content

Raxcore-dev/rax-ai-flutter-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rax AI Flutter SDK

Official Flutter SDK for the Rax AI Platform - OpenAI-compatible AI API client.

Features

  • βœ… OpenAI-compatible API
  • βœ… Simple, intuitive API
  • βœ… Full Dart/Flutter support
  • βœ… Comprehensive error handling
  • βœ… Lightweight and fast

Installation

Add this to your pubspec.yaml:

dependencies:
  rax_ai: ^1.0.0

Then run:

flutter pub get

Usage

Basic Example

import 'package:rax_ai/rax_ai.dart';

void main() async {
  final client = RaxAI(
    apiKey: 'your-api-key-here',
    baseUrl: 'https://your-rax-ai-instance.com/api/v1', // Optional
  );

  try {
    final completion = await client.createChatCompletion(
      model: 'rax-4.0',
      messages: [
        Message.user('Hello, how are you?'),
      ],
    );

    print(completion.choices.first.message.content);
  } catch (e) {
    print('Error: $e');
  } finally {
    client.dispose();
  }
}

Flutter Widget Example

import 'package:flutter/material.dart';
import 'package:rax_ai/rax_ai.dart';

class ChatWidget extends StatefulWidget {
  @override
  _ChatWidgetState createState() => _ChatWidgetState();
}

class _ChatWidgetState extends State<ChatWidget> {
  final RaxAI _client = RaxAI(apiKey: 'your-api-key');
  final TextEditingController _controller = TextEditingController();
  String _response = '';
  bool _loading = false;

  Future<void> _sendMessage() async {
    if (_controller.text.isEmpty) return;

    setState(() {
      _loading = true;
    });

    try {
      final completion = await _client.createChatCompletion(
        model: 'rax-4.0',
        messages: [Message.user(_controller.text)],
      );

      setState(() {
        _response = completion.choices.first.message.content;
        _loading = false;
      });
    } catch (e) {
      setState(() {
        _response = 'Error: $e';
        _loading = false;
      });
    }

    _controller.clear();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TextField(
          controller: _controller,
          decoration: InputDecoration(
            hintText: 'Enter your message...',
            suffixIcon: IconButton(
              onPressed: _loading ? null : _sendMessage,
              icon: Icon(Icons.send),
            ),
          ),
        ),
        SizedBox(height: 16),
        if (_loading)
          CircularProgressIndicator()
        else
          Text(_response),
      ],
    );
  }

  @override
  void dispose() {
    _client.dispose();
    _controller.dispose();
    super.dispose();
  }
}

API Reference

RaxAI

Main client class for interacting with the Rax AI API.

Constructor

RaxAI({
  required String apiKey,
  String baseUrl = 'https://api.raxai.com/v1',
  http.Client? httpClient,
})

Methods

createChatCompletion
Future<ChatCompletion> createChatCompletion({
  required String model,
  required List<Message> messages,
  double? temperature,
  int? maxTokens,
})

Message

Represents a chat message.

Constructors

Message.user(String content)
Message.assistant(String content)
Message.system(String content)

Models

  • ChatCompletion - Response from chat completion API
  • Choice - Individual choice in completion response
  • Usage - Token usage information
  • RaxAIException - SDK-specific exceptions

Error Handling

The SDK throws RaxAIException for API errors:

try {
  final completion = await client.createChatCompletion(
    model: 'rax-4.0',
    messages: [Message.user('Hello')],
  );
} on RaxAIException catch (e) {
  print('Rax AI Error: ${e.message}');
} catch (e) {
  print('Other error: $e');
}

License

MIT License - see LICENSE file for details.

About

πŸš€ Official Flutter SDK for Rax AI Platform - OpenAI-compatible AI API client for Flutter/Dart applications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages