juejin-units
v1.0.0
Published
A TypeScript package for AI service integration
Readme
juejin-units
A TypeScript package for AI service integration.
Installation
npm install juejin-unitsUsage
import { AIClient, AIMessage, AICallback } from 'juejin-units';
// Create an AI client instance
const aiClient = new AIClient({
api: 'YOUR_API_ENDPOINT',
apiKey: 'YOUR_API_KEY',
model: 'YOUR_MODEL_NAME',
systemContent: 'YOUR_SYSTEM_CONTENT'
});
// Create a message
const message: AIMessage = {
role: 'user',
content: 'Hello, AI!'
};
// Define a callback function
const callback: AICallback = (content, isDone) => {
if (content) {
console.log(content);
}
if (isDone) {
console.log('Stream completed');
}
};
// Send message to AI
await aiClient.sendToAI(message, callback);API Reference
AIClient
The main class for interacting with the AI service.
Constructor
constructor(aiConfig: {
api: string;
apiKey: string;
model: string;
systemContent: string;
})Methods
sendToAI(message: AIMessage, callback: AICallback): Promise<void>
Types
AIMessage
interface AIMessage {
role: string;
content: string;
}AICallback
type AICallback = (content: string | null, isDone: boolean) => void;License
MIT
