https://github.com/print3m/ai-toolkit
Simple TS toolkit to work with atomic AI (LLM) tasks.
https://github.com/print3m/ai-toolkit
ai automation llm typescript
Last synced: 9 months ago
JSON representation
Simple TS toolkit to work with atomic AI (LLM) tasks.
- Host: GitHub
- URL: https://github.com/print3m/ai-toolkit
- Owner: Print3M
- Created: 2025-07-01T16:33:22.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-01T17:12:42.000Z (12 months ago)
- Last Synced: 2025-07-01T18:25:33.656Z (12 months ago)
- Topics: ai, automation, llm, typescript
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ai-toolkit
**Simple TypeScript toolkit to work with atomic AI (LLM) tasks.**
It automates the following steps:
1. Initialize AI model (`openai` package) with API key from environs.
2. Get system and user prompt template.
3. Inject values into prompt templates (`Nunjucks` template engine).
4. Send a prompt to AI model.
5. Get a response from AI model.
6. Parse the response type-safely.
7. Validate the parsed response.
This is the example usage of the toolkit:
```javascript
// Define expected data
type ReturnedData = {
title: string
summary: string
}
// Create model
const model = new AiModel({
apiKeyEnv: "GEMINI_API_KEY",
model: "gemini-2.0-flash",
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai/",
})
// Create prompt
const prompt = new AiPrompt({
promptTemplates: {
system: "You are world class expert in article summarization.",
user: "Summary this: {{ title }}, {{ article }}",
},
promptParams: {
user: {
title: "Hello world!",
article: "siema"
},
},
responseParser: (v) => JSON.parse(v),
responseValidator: (v) => v.title.length > 0,
})
// Create task
const task = new AiTask({
model,
prompt,
})
// Execute task and get result
const result = await task.execute()
```