@wasserstoff/aitutor
v1.0.0
Published
TypeScript SDK for AI Learning API
Readme
@wasserstoff/aitutor
A TypeScript SDK for interacting with the AI Learning API. This SDK provides a clean, type-safe interface for creating and managing learning sessions.
Installation
npm install @wasserstoff/aitutorConfiguration
To use the AITutor SDK, you need an API token. You can generate a new token by visiting the AITutor platform.
Once you have your token, you can set it using the setToken method as shown in the Usage section below.
Usage
First, import the tutorAI SDK instance and set your authentication token.
import { tutorAI } from '@wasserstoff/aitutor';
// Set your auth token
tutorAI.setToken('YOUR_AUTH_TOKEN');
// Create a new learning session
const createSession = async () => {
try {
const session = await tutorAI.createSession('devops', {
experience: 'beginner',
learning_style: 'visual'
});
console.log('Session created:', session);
return session;
} catch (error) {
console.error('Error creating session:', error);
}
};
// Submit an answer
const submitAnswer = async (sessionId: string, answer: string) => {
try {
const response = await tutorAI.submitAnswer(sessionId, answer);
console.log('Answer feedback:', response);
// If the answer is incorrect, get learning resources
if (response.correctness === 'incorrect' && response.needs_resources) {
const resources = await tutorAI.getResources(
sessionId,
response.question,
answer
);
console.log('Learning resources:', resources);
}
} catch (error) {
console.error('Error submitting answer:', error);
}
};
// Get session personas
const getPersonas = async (sessionId: string) => {
try {
const personas = await tutorAI.getPersonas(sessionId);
console.log('Session personas:', personas);
} catch (error) {
console.error('Error getting personas:', error);
}
};Development
To run the SDK locally for development:
- Clone the repository
- Install dependencies:
npm install- Start the development server with hot-reload:
npm run devThis will run the test script (src/test.ts) which demonstrates all SDK functionality:
- Creating a session
- Submitting answers
- Getting learning resources
- Retrieving session personas
The development server uses nodemon to automatically restart when you make changes to the source files.
API Reference
The SDK is exported as a pre-configured instance tutorAI.
setToken(token: string)
Sets the authentication token required for all API calls.
createSession(topic: string, userPersona: UserPersona)
Creates a new learning session for the specified topic.
submitAnswer(sessionId: string, answer: string)
Submits an answer for the current question in the session.
getResources(sessionId: string, question: string, answer: string, useCombinedSearch?: boolean)
Retrieves learning resources for incorrect answers.
getPersonas(sessionId: string)
Retrieves the user and teacher personas for the current session.
Available Scripts
npm run build- Build the SDKnpm run dev- Run the development server with hot-reloadnpm run test- Run testsnpm run lint- Run ESLintnpm run prepare- Build before publishing
License
MIT
