@airbend3r/client v0.1.12
Yes, the README should be updated to reflect the changes made to the code, particularly the introduction of the onLogId
callback and the handling of asynchronous logging.
Here’s the updated README:
# Airbender Client
The Airbender Client provides a logging proxy around an OpenAI client and offers functionality for logging custom events and handling feedback. This package is designed to enhance the logging capabilities of your OpenAI interactions.
## Installation
To install the Airbender Client, use npm:
```bash
npm install @airbend3r/client
Usage
Basic Setup
Here's a basic example of how to use the Airbender Client to wrap an OpenAI instance and enable logging:
import { OpenAI } from 'openai';
import { newAirbenderInstance } from '@airbend3r/client';
// Create an OpenAI instance
const openai = new OpenAI();
// Create an Airbender instance with default logging configuration
const airbender = await newAirbenderInstance({ productKey: 'your-product-key' });
// Wrap the OpenAI instance with logging capabilities
const wrapped = airbender.wrap(openai, {
logInputs: true,
logOutputs: true,
});
// Use the wrapped instance for API calls
const { airbenderInstanceID, ...response } = await wrapped.chat.completions.create({
model: 'text-davinci-003',
prompt: 'Hello, world!',
});
Logger Configuration
The LoggerConfig
interface allows you to control logging behavior:
export interface LoggerConfig {
logInputs?: boolean; // Optional flag to log the parameters sent to OpenAI's create function
logOutputs?: boolean; // Optional flag to log the response received from the OpenAI create function
additionalInfo?: any; // Any additional information to be logged
onResponse?: (response: any) => void; // Optional callback to handle the response directly
onLogId?: (logId: string) => void; // Optional callback to handle the log ID directly
sessionID?: string; // Can optionally change the session ID to whatever you like
productKey: string; // Associates your logs with a product! Needs to be generated in the app
blockingConfig?: {
messageOnBlock: string; // Custom message to display when blocking
};
}
Sending Feedback
You can send feedback for a specific log using the feedback
method. Here's an example:
export const setRatingAndFeedback = async (logId: string, data: { rating?: number, message?: string, comment?: string, id?: string }) => {
const result = await airbender.feedback(logId, {
rating: data.rating || null,
comment: data.comment || data.message || '',
id: data.id || ''
});
const serverData = await result.json();
return serverData;
};
Sending Custom Log Events
You can log custom events using the logEvent
method. Here's how to do it:
const customEvent = {
type: 'custom-event',
input: 'Custom input data',
output: 'Custom output data',
flags: ['flag1', 'flag2'],
status: 'completed',
meta: 'Additional metadata',
model: 'text-davinci-003',
sessionId: 'your-session-id'
};
const logId = await airbender.logEvent(customEvent);
Configuration Options
When creating a new Airbender instance or wrapping an OpenAI instance, you can set various configurations:
const airbender = await newAirbenderInstance({
productKey: 'your-product-key',
logInputs: true,
logOutputs: true,
onResponse: (response) => {
console.log('Response received:', response);
},
onLogId: (logId) => {
console.log('Log ID:', logId);
},
sessionID: 'custom-session-id'
});
const wrapped = airbender.wrap(openai, {
logInputs: true,
logOutputs: true,
});
API Reference
newAirbenderInstance(defaultConfig: LoggerConfig)
Creates a new Airbender instance with the specified default logging configuration.
wrap(openaiInstance: OpenAI, config?: LoggerConfig)
Wraps an OpenAI instance with a proxy to provide enhanced logging capabilities.
logEvent(event: LogInput, logId?: string, sessionId?: string): Promise<string>
Logs a custom event and returns the log ID.
feedback(logId: string, feedback: { rating: number | null, comment: string, id?: string }, sessionId?: string): Promise<Response>
Associates feedback with a specific log.
License
This project is licensed under the MIT License.
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago