genui_openrouter 0.1.0 copy "genui_openrouter: ^0.1.0" to clipboard
genui_openrouter: ^0.1.0 copied to clipboard

A GenUI transport client for OpenRouter, supporting streaming, fallbacks, and advanced LLM parameters.

GenUI OpenRouter #

A powerful, streaming-first OpenRouter client for the GenUI ecosystem.

Features #

  • Streaming Support: Native SSE streaming integration with GenUI Transport.
  • Model Fallbacks: Easily configure multiple models to ensure high availability.
  • GenUI Component Aware: Automatically handles system prompts based on your Catalog.
  • Advanced LLM Parameters: Full support for temperature, top_p, frequency penalty, etc.
  • Compliance: Built-in support for OpenRouter's recommended headers (HTTP-Referer, X-Title).

Getting Started #

Add the package to your pubspec.yaml:

dependencies:
  genui_openrouter: ^0.1.0

Usage #

1. Initialize the Client #

final config = OpenRouterConfig(
  apiKey: 'YOUR_API_KEY',
  siteUrl: 'https://myapp.com',
  siteName: 'My App',
  defaultModels: ['openai/gpt-3.5-turbo', 'google/palm-2-chat-bison'],
);

final client = GenUIOpenRouterClient(
  config: config,
  catalog: myCatalog,
  systemPromptFragments: ['You are a helpful assistant.'],
);

2. Connect to GenUI Transport #

final transport = A2uiTransportAdapter(
  onSend: (message) async {
    final stream = client.generateStream(
      message,
      params: OpenRouterParameters(temperature: 0.7),
    );
    
    await for (final chunk in stream) {
      transport.addChunk(chunk);
    }
  },
);

3. Dispose #

Remember to dispose of the client when no longer needed:

@override
void dispose() {
  client.dispose();
  super.dispose();
}

Advanced Parameters #

The OpenRouterParameters class allows you to control the LLM's behavior:

  • temperature: Controls randomness (0.0 to 2.0).
  • maxTokens: Maximum length of the generated response.
  • seed: For deterministic outputs.
  • stop: List of sequences that stop generation.

License #

MIT

1
likes
160
points
28
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A GenUI transport client for OpenRouter, supporting streaming, fallbacks, and advanced LLM parameters.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

genui, http

More

Packages that depend on genui_openrouter