ubc-genai-toolkit-core
v0.1.0
Published
Core module for the UBC GenAI Toolkit, providing common interfaces and utilities.
Readme
UBC GenAI Toolkit - Core Module
The ubc-genai-toolkit-core package is the foundational library for the UBC GenAI Toolkit. It provides a set of common interfaces, error handling patterns, and configuration standards that are shared across all other modules in the toolkit.
This module ensures that different components of the toolkit work together seamlessly and provides a consistent development experience for anyone building on top of them.
Installation
You can install the core module from npm:
npm install ubc-genai-toolkit-coreCore Concepts
This module exports several key interfaces that establish the common patterns used throughout the UBC GenAI Toolkit. Other toolkit modules will expect implementations of these interfaces for functionalities like logging and configuration.
Configuration (ModuleConfig)
The ModuleConfig interface defines a standard structure for passing configuration to any toolkit module.
// From: src/config.ts
export interface ModuleConfig {
logger?: LoggerInterface;
debug?: boolean;
[key: string]: any;
}logger: An optional logger instance that conforms to theLoggerInterface.debug: An optional boolean flag to enable or disable debug mode.- Module-specific options can be added as additional properties.
Logging (LoggerInterface)
The LoggerInterface provides a standardized way for modules to handle logging, allowing consuming applications to integrate their own logging solutions.
// From: src/logger.ts
export interface LoggerInterface {
debug(message: string, metadata?: object): void;
info(message: string, metadata?: object): void;
warn(message: string, metadata?: object): void;
error(message: string, metadata?: object): void;
}If no logger is provided to a module's configuration, a minimal ConsoleLogger (also exported from this module) will be used by default.
Error Handling (ToolkitError)
The ToolkitError class provides a consistent structure for errors thrown by any module in the toolkit. This makes it easier for applications to handle errors reliably.
// From: src/error.ts
export class ToolkitError extends Error {
public readonly code: number;
public readonly details?: any;
public readonly timestamp: string;
constructor(message: string, code = 500, details?: any) {
super(message);
this.name = 'ToolkitError';
this.code = code;
this.details = details;
this.timestamp = new Date().toISOString();
}
}message: A human-readable error message.code: A numeric error code (often corresponding to an HTTP status code).details: Any additional data that might be useful for debugging.timestamp: An ISO string representing when the error occurred.
Specialized error classes like ConfigurationError and APIError are also available for more specific scenarios.
Usage
This module is primarily a dependency for other ubc-genai-toolkit-* packages. You typically won't interact with it directly, but you will use the interfaces it provides when configuring other modules.
For example, when setting up the ubc-genai-toolkit-llm module, you might pass a configuration object that uses interfaces from this core package:
import { LLMModule, LLMConfig } from 'ubc-genai-toolkit-llm';
import { ConsoleLogger } from 'ubc-genai-toolkit-core'; // From this package
const config: LLMConfig = {
provider: 'openai',
apiKey: 'YOUR_API_KEY',
defaultModel: 'gpt-4o',
logger: new ConsoleLogger(), // Using the logger from core
debug: true,
};
const llmModule = new LLMModule(config);