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

A full-featured Dart client for TensorZero Gateway supporting both native inference and OpenAI-compatible APIs with streaming, tool calling, and multimodal capabilities.

example/tensorzero_example.dart

/// TensorZero Dart Client - Working Examples
///
/// This example demonstrates the current working components of the TensorZero client.
/// We're building up to the full enterprise-grade implementation.

import 'package:tensorzero/tensorzero.dart';

/// Example using the core infrastructure that works
void infrastructureExample() {
  print('šŸ—ļø Core Infrastructure Example');
  print('==============================');

  // Test Result types
  final success = ResultFactory.success<String, Exception>('Hello World');
  final failure = ResultFactory.failure<String, Exception>(
    Exception('Something went wrong'),
  );

  print('Success result: $success');
  print('Failure result: $failure');

  // Test ModelName validation
  try {
    final validModel = ModelName('tensorzero::function_name::chat_completion');
    print('āœ… Valid model name: $validModel');
  } catch (e) {
    print('āŒ Model name validation failed: $e');
  }

  // Test FunctionName validation
  try {
    final validFunction = FunctionName('chat_completion');
    print('āœ… Valid function name: $validFunction');
  } catch (e) {
    print('āŒ Function name validation failed: $e');
  }

  // Test CacheMode
  final cacheMode = CacheMode.writeOnly;
  print(
    'Cache mode: $cacheMode (can read: ${cacheMode.canRead}, can write: ${cacheMode.canWrite})',
  );
}

/// Example using the content block system
void contentBlockExample() {
  print('\nšŸ“¦ Content Block System Example');
  print('=================================');

  // Create different types of content blocks
  final textBlock = ContentBlock.text(text: 'Hello world!');
  final rawTextBlock = ContentBlock.rawText(value: 'Unprocessed text');
  final thoughtBlock = ContentBlock.thought(text: 'This is a reasoning step');

  print('Text block: ${textBlock.toJson()}');
  print('Raw text block: ${rawTextBlock.toJson()}');
  print('Thought block: ${thoughtBlock.toJson()}');

  // Test content block utilities
  final blocks = [textBlock, rawTextBlock, thoughtBlock];
  final tokenEstimate = ContentBlockUtils.estimateTokenCount(blocks);
  print('Estimated token count: $tokenEstimate');

  // Test text extraction
  final textRepresentation = ContentBlockUtils.toText(blocks);
  print('Text representation: "$textRepresentation"');
}

/// Example using validation
void validationExample() {
  print('\nāœ… Validation Example');
  print('======================');

  // Test model name validation
  final validModelResult = TensorZeroValidators.validModelName(
    'tensorzero::function_name::test',
  );
  print('Valid model name: $validModelResult');

  final invalidModelResult = TensorZeroValidators.validModelName(
    'invalid-model',
  );
  print('Invalid model name: $invalidModelResult');

  // Test function name validation
  final validFunctionResult = FunctionNameValidators.isValid(
    'valid_function_name',
  );
  print('Valid function name: $validFunctionResult');

  final invalidFunctionResult = FunctionNameValidators.isValid(
    'invalid function name!',
  );
  print('Invalid function name: $invalidFunctionResult');
}

/// Main function - run all examples
void main() {
  print('šŸš€ TensorZero Dart Client - Working Examples');
  print('==============================================');

  infrastructureExample();
  contentBlockExample();
  validationExample();

  print('\nāœ… All examples completed successfully!');
  print('\nšŸ“ˆ Next Steps:');
  print('- OpenAI-compatible client implementation');
  print('- Native TensorZero client');
  print('- Streaming support');
  print('- Tool calling system');
  print('- Full integration tests');
}
0
likes
120
points
74
downloads

Publisher

verified publisherzuzu.dev

Weekly Downloads

A full-featured Dart client for TensorZero Gateway supporting both native inference and OpenAI-compatible APIs with streaming, tool calling, and multimodal capabilities.

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

clock, collection, dartz, freezed_annotation, http, json_annotation, logging, meta, sse, uuid

More

Packages that depend on tensorzero