@nordlys-labs/nordlys-ai-provider 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -0
- package/dist/index.cjs +1055 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +1038 -0
- package/dist/index.js.map +1 -0
- package/package.json +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Nordlys AI Provider
|
|
2
|
+
|
|
3
|
+
AI provider for [Vercel AI SDK v5](https://ai-sdk.dev/docs) that provides access to Nordlys models—a Mixture of Models system that behaves like a single unified model. V3 specification compliant.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **V3 Spec Compliant** - Reasoning, file generation, enhanced usage tracking
|
|
8
|
+
- **Mixture of Models** - Access to Nordlys models that activate the right models per prompt
|
|
9
|
+
- **Drop-in Replacement** - OpenAI-compatible API, works with existing code
|
|
10
|
+
- **Production Ready** - TypeScript, full test coverage
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# npm
|
|
16
|
+
npm i @nordlys-labs/nordlys-ai-provider
|
|
17
|
+
|
|
18
|
+
# pnpm
|
|
19
|
+
pnpm add @nordlys-labs/nordlys-ai-provider
|
|
20
|
+
|
|
21
|
+
# bun
|
|
22
|
+
bun add @nordlys-labs/nordlys-ai-provider
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { nordlys } from '@nordlys-labs/nordlys-ai-provider';
|
|
29
|
+
import { generateText } from 'ai';
|
|
30
|
+
|
|
31
|
+
// Use Nordlys models
|
|
32
|
+
const { text } = await generateText({
|
|
33
|
+
model: nordlys('nordlys/hypernova'),
|
|
34
|
+
prompt: 'Explain quantum computing',
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## V3 Content Types
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const { content, usage } = await generateText({
|
|
42
|
+
model: nordlys('nordlys/hypernova'),
|
|
43
|
+
prompt: 'Solve: 2x + 5 = 17',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Access reasoning, files, tool calls
|
|
47
|
+
content.forEach((item) => {
|
|
48
|
+
switch (item.type) {
|
|
49
|
+
case 'text': console.log(item.text); break;
|
|
50
|
+
case 'reasoning': console.log(item.text); break;
|
|
51
|
+
case 'file': console.log(item.media_type, item.data); break;
|
|
52
|
+
case 'tool-call': console.log(item.toolName, item.args); break;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Enhanced usage tracking
|
|
57
|
+
console.log({
|
|
58
|
+
input: usage.inputTokens,
|
|
59
|
+
output: usage.outputTokens,
|
|
60
|
+
reasoning: usage.reasoningTokens,
|
|
61
|
+
cached: usage.cachedInputTokens,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Streaming
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const { fullStream } = streamText({
|
|
69
|
+
model: nordlys('nordlys/hypernova'),
|
|
70
|
+
prompt: 'Count to 10',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
for await (const part of fullStream) {
|
|
74
|
+
if (part.type === 'text') process.stdout.write(part.textDelta);
|
|
75
|
+
if (part.type === 'reasoning') console.log('💭', part.text);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Tools
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const { text } = await generateText({
|
|
83
|
+
model: nordlys('nordlys/hypernova'),
|
|
84
|
+
prompt: 'What is the weather in SF?',
|
|
85
|
+
tools: {
|
|
86
|
+
getWeather: {
|
|
87
|
+
description: 'Get weather for location',
|
|
88
|
+
parameters: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: { location: { type: 'string' } },
|
|
91
|
+
required: ['location'],
|
|
92
|
+
},
|
|
93
|
+
execute: async ({ location }) => `Weather in ${location}: Sunny, 72°F`,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { createNordlys } from '@nordlys-labs/nordlys-ai-provider';
|
|
103
|
+
|
|
104
|
+
const nordlys = createNordlys({
|
|
105
|
+
baseURL: 'https://your-api.com/v1',
|
|
106
|
+
apiKey: 'your-key', // or NORDLYS_API_KEY env var
|
|
107
|
+
headers: { 'Custom-Header': 'value' },
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Multimodal
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const { text } = await generateText({
|
|
115
|
+
model: nordlys('nordlys/hypernova'),
|
|
116
|
+
messages: [{
|
|
117
|
+
role: 'user',
|
|
118
|
+
content: [
|
|
119
|
+
{ type: 'text', text: 'Analyze this image' },
|
|
120
|
+
{ type: 'file', data: 'data:image/jpeg;base64,...', media_type: 'image/jpeg' },
|
|
121
|
+
],
|
|
122
|
+
}],
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Supported Features
|
|
127
|
+
|
|
128
|
+
- Text, reasoning, file generation, tool calls
|
|
129
|
+
- Streaming with all event types
|
|
130
|
+
- Multimodal inputs (images, audio, PDFs)
|
|
131
|
+
- Enhanced usage tracking
|
|
132
|
+
- AI SDK standard error handling
|
|
133
|
+
- Full TypeScript support
|
|
134
|
+
|
|
135
|
+
## Error Handling
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { APICallError, TooManyRequestsError } from 'ai';
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const result = await generateText({
|
|
142
|
+
model: nordlys('nordlys/hypernova'),
|
|
143
|
+
prompt: 'Hello',
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (error instanceof TooManyRequestsError) {
|
|
147
|
+
console.log('Rate limited, retry after:', error.retryAfter);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Environment
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
export NORDLYS_API_KEY="your-api-key"
|
|
156
|
+
```
|