@qevrion/sdk 0.1.0 → 0.2.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 +43 -5
- package/dist/genkit.d.ts +14 -0
- package/dist/genkit.js +38 -2
- package/dist/genkit.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +29 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @qevrion/sdk
|
|
2
2
|
|
|
3
|
-
Small, dependency-free TypeScript client for QevrionAI text chat, streaming, and model discovery. ESM, Node.js 20.3+. Keep API keys in your server environment.
|
|
3
|
+
Small, dependency-free TypeScript client for QevrionAI text chat, streaming, embeddings, and model discovery. ESM, Node.js 20.3+. Keep API keys in your server environment.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ npm install @qevrion/sdk
|
|
|
14
14
|
import { Qevrion } from '@qevrion/sdk';
|
|
15
15
|
|
|
16
16
|
const client = new Qevrion({ apiKey: process.env.QEVRION_API_KEY! });
|
|
17
|
-
const { data: models } = await client.models.list();
|
|
17
|
+
const { data: models } = await client.models.list({ type: 'chat' });
|
|
18
18
|
const model = models[0]?.id;
|
|
19
19
|
if (!model) throw new Error('No models are enabled.');
|
|
20
20
|
|
|
@@ -35,13 +35,35 @@ for await (const chunk of client.chat.completions.stream({
|
|
|
35
35
|
|
|
36
36
|
`create()` returns a JSON completion; `stream()` returns an async iterable of raw chat chunks, including usage-only chunks. Breaking the loop cancels the reader and aborts the HTTP request. A stream ending without `[DONE]` raises `QevrionProtocolError` so interrupted responses are detectable. Cancellation cannot guarantee that the upstream provider stops generating or charging.
|
|
37
37
|
|
|
38
|
-
Supported input: text `system`, `user`, and `assistant` messages; `max_tokens` (1–4096, default 1024), `temperature` (0–2), and `top_p` (0–1). Model IDs must be enabled in the catalog. Tool calls, images,
|
|
38
|
+
Supported input: text `system`, `user`, and `assistant` messages; `max_tokens` (1–4096, default 1024), `temperature` (0–2), and `top_p` (0–1). Model IDs must be enabled in the catalog. Tool calls, images, and native JSON schema output are not supported by the current API. Upstream `usage.cost`, when included, is not the final Qevrion account charge.
|
|
39
|
+
|
|
40
|
+
## Embeddings
|
|
41
|
+
|
|
42
|
+
Available from SDK version `0.2.0`. An admin must publish an embedding model in the model catalog before use. Chat and embedding model IDs are separate; `models.list()` returns both types, while `models.list({ type: 'chat' })` and `models.list({ type: 'embedding' })` filter them.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const { data: embeddingModels } = await client.models.list({ type: 'embedding' });
|
|
46
|
+
const embeddingModel = embeddingModels[0]?.id;
|
|
47
|
+
if (!embeddingModel) throw new Error('No embedding models are enabled.');
|
|
48
|
+
|
|
49
|
+
const result = await client.embeddings.create({
|
|
50
|
+
model: embeddingModel,
|
|
51
|
+
input: ['A document about Lagos.', 'A document about Abuja.'],
|
|
52
|
+
});
|
|
53
|
+
for (const item of result.data) {
|
|
54
|
+
console.log(item.index, item.embedding); // number[] with the default float format
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`input` accepts one non-empty string or 1–100 non-empty strings. The API caps the entire JSON request at 100,000 bytes; model context limits still apply. Token arrays, multimodal input, and streaming are not supported for embeddings. Optional parameters: `dimensions` (1–65536, subject to the model), `encoding_format` (`float` by default, or `base64`), and a provider-specific `input_type` such as `search_query` or `search_document`. With `encoding_format: 'base64'`, response embeddings are typed as strings. Each result includes its original input index; use it to match vectors to inputs.
|
|
59
|
+
|
|
60
|
+
Embeddings require the same account credits as chat. The API reserves a conservative estimate (minimum $0.01) and settles at 2× the reported upstream cost. If cost is missing, it estimates from reported prompt tokens and the catalog input price; if token usage is also missing, it conservatively uses input bytes as the token estimate. Estimated charges are marked in usage history. Provider HTTP errors and connection failures release the reservation. A malformed successful response is charged using the original reservation estimate and returned as an upstream error, since the provider may already have performed work.
|
|
39
61
|
|
|
40
62
|
## Configuration and errors
|
|
41
63
|
|
|
42
64
|
The default API root is `https://useqevrion.com/v1`. For local development pass `baseURL: 'http://localhost:3000/v1'`. A custom `fetch` can be supplied for testing or transport integration. Redirects are rejected.
|
|
43
65
|
|
|
44
|
-
All operations accept a second options argument (the first argument for `models.list`) with `signal` and `timeoutMs`. The default deadline is 120 seconds and includes reading the response body or stream. Network failures and aborts propagate from fetch. Automatic retries are disabled because
|
|
66
|
+
All operations accept a second options argument (the first argument for `models.list`) with `signal` and `timeoutMs`. The default deadline is 120 seconds and includes reading the response body or stream. Network failures and aborts propagate from fetch. Automatic retries are disabled because model requests can incur charges.
|
|
45
67
|
|
|
46
68
|
```ts
|
|
47
69
|
import { QevrionAPIError } from '@qevrion/sdk';
|
|
@@ -84,7 +106,23 @@ const response = await ai.generate({
|
|
|
84
106
|
console.log(response.text);
|
|
85
107
|
```
|
|
86
108
|
|
|
87
|
-
The adapter uses the SDK transport, including its cancellation, deadlines, errors, and disabled retries. It accepts `baseURL`, `timeoutMs`, a custom `fetch`, and a plugin `name` (default `qevrion`). If you change the name, pass the same name as the second argument to `qevrionModel`.
|
|
109
|
+
The adapter uses the SDK transport, including its cancellation, deadlines, errors, and disabled retries. It accepts `baseURL`, `timeoutMs`, a custom `fetch`, and a plugin `name` (default `qevrion`). If you change the name, pass the same name as the second argument to `qevrionModel` or `qevrionEmbedder`. For chat it supports `generate` and `generateStream`, advertises text chat capabilities, and maps `maxOutputTokens`, `temperature`, and `topP` to the API parameters. Unsupported configuration is rejected rather than silently ignored.
|
|
110
|
+
|
|
111
|
+
For text embeddings, use the same plugin and an enabled embedding model:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { qevrionEmbedder } from '@qevrion/sdk/genkit';
|
|
115
|
+
|
|
116
|
+
const embeddings = await ai.embed({
|
|
117
|
+
embedder: qevrionEmbedder('openai/text-embedding-3-small'),
|
|
118
|
+
content: 'A document about Lagos.',
|
|
119
|
+
// Optional; supported dimensions and task hints depend on the selected model.
|
|
120
|
+
options: { inputType: 'search_document' },
|
|
121
|
+
});
|
|
122
|
+
console.log(embeddings[0]?.embedding);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`ai.embedMany()` accepts batches of up to 100 text documents. Embedder options are `dimensions` and `inputType` (mapped to `input_type`). The Genkit adapter returns float vectors in input order.
|
|
88
126
|
|
|
89
127
|
## Build and release
|
|
90
128
|
|
package/dist/genkit.d.ts
CHANGED
|
@@ -4,6 +4,20 @@ export interface QevrionGenkitOptions extends QevrionOptions {
|
|
|
4
4
|
name?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function qevrion(options: QevrionGenkitOptions): import("genkit/plugin").GenkitPluginV2Instance;
|
|
7
|
+
/** Reference an enabled embedding model for ai.embed() or ai.embedMany(). */
|
|
8
|
+
export declare function qevrionEmbedder(modelId: string, pluginName?: string): import("genkit").EmbedderReference<z.ZodObject<{
|
|
9
|
+
version: z.ZodOptional<z.ZodUndefined>;
|
|
10
|
+
dimensions: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
inputType: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strict", z.ZodTypeAny, {
|
|
13
|
+
version?: undefined;
|
|
14
|
+
dimensions?: number | undefined;
|
|
15
|
+
inputType?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
version?: undefined;
|
|
18
|
+
dimensions?: number | undefined;
|
|
19
|
+
inputType?: string | undefined;
|
|
20
|
+
}>>;
|
|
7
21
|
/** Pass a catalog model ID, including its provider, e.g. openai/gpt-4o-mini. */
|
|
8
22
|
export declare function qevrionModel(modelId: string, pluginName?: string): import("genkit").ModelReference<z.ZodObject<{
|
|
9
23
|
version: z.ZodOptional<z.ZodUndefined>;
|
package/dist/genkit.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { modelRef, z } from 'genkit';
|
|
2
|
-
import {
|
|
2
|
+
import { embedderRef } from 'genkit/embedder';
|
|
3
|
+
import { embedder, genkitPluginV2, model } from 'genkit/plugin';
|
|
3
4
|
import { Qevrion } from './index.js';
|
|
4
5
|
const configSchema = z
|
|
5
6
|
.object({
|
|
@@ -17,6 +18,13 @@ const supports = {
|
|
|
17
18
|
systemRole: true,
|
|
18
19
|
output: ['text'],
|
|
19
20
|
};
|
|
21
|
+
const embeddingConfigSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
version: z.undefined().optional(),
|
|
24
|
+
dimensions: z.number().int().min(1).max(65536).optional(),
|
|
25
|
+
inputType: z.string().min(1).max(100).optional(),
|
|
26
|
+
})
|
|
27
|
+
.strict();
|
|
20
28
|
function usage(value) {
|
|
21
29
|
return value
|
|
22
30
|
? {
|
|
@@ -37,9 +45,29 @@ export function qevrion(options) {
|
|
|
37
45
|
return genkitPluginV2({
|
|
38
46
|
name,
|
|
39
47
|
async resolve(actionType, actionName) {
|
|
48
|
+
const id = actionName.startsWith(`${name}/`) ? actionName.slice(name.length + 1) : actionName;
|
|
49
|
+
if (actionType === 'embedder') {
|
|
50
|
+
return embedder({
|
|
51
|
+
name: `${name}/${id}`,
|
|
52
|
+
configSchema: embeddingConfigSchema,
|
|
53
|
+
info: { supports: { input: ['text'] } },
|
|
54
|
+
}, async (request, context) => {
|
|
55
|
+
const config = embeddingConfigSchema.parse(request.options ?? {});
|
|
56
|
+
const input = request.input.map((document) => {
|
|
57
|
+
if (document.content.some((part) => typeof part.text !== 'string'))
|
|
58
|
+
throw new TypeError('Qevrion embeddings support text documents only.');
|
|
59
|
+
return document.text;
|
|
60
|
+
});
|
|
61
|
+
const result = await client.embeddings.create({ model: id, input, dimensions: config.dimensions, input_type: config.inputType }, { signal: context.abortSignal });
|
|
62
|
+
return {
|
|
63
|
+
embeddings: [...result.data]
|
|
64
|
+
.sort((a, b) => a.index - b.index)
|
|
65
|
+
.map((item) => ({ embedding: item.embedding })),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
40
69
|
if (actionType !== 'model')
|
|
41
70
|
return undefined;
|
|
42
|
-
const id = actionName.startsWith(`${name}/`) ? actionName.slice(name.length + 1) : actionName;
|
|
43
71
|
return model({ name: `${name}/${id}`, supports, configSchema }, async (request, context) => {
|
|
44
72
|
const config = configSchema.parse(request.config ?? {});
|
|
45
73
|
if (request.tools?.length || (request.output?.format && request.output.format !== 'text')) {
|
|
@@ -99,6 +127,14 @@ export function qevrion(options) {
|
|
|
99
127
|
},
|
|
100
128
|
});
|
|
101
129
|
}
|
|
130
|
+
/** Reference an enabled embedding model for ai.embed() or ai.embedMany(). */
|
|
131
|
+
export function qevrionEmbedder(modelId, pluginName = 'qevrion') {
|
|
132
|
+
return embedderRef({
|
|
133
|
+
name: `${pluginName}/${modelId}`,
|
|
134
|
+
configSchema: embeddingConfigSchema,
|
|
135
|
+
info: { supports: { input: ['text'] } },
|
|
136
|
+
});
|
|
137
|
+
}
|
|
102
138
|
/** Pass a catalog model ID, including its provider, e.g. openai/gpt-4o-mini. */
|
|
103
139
|
export function qevrionModel(modelId, pluginName = 'qevrion') {
|
|
104
140
|
return modelRef({
|
package/dist/genkit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genkit.js","sourceRoot":"","sources":["../src/genkit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,EAAoD,MAAM,YAAY,CAAC;AAMvF,MAAM,YAAY,GAAG,CAAC;KACnB,MAAM,CAAC;IACN,sEAAsE;IACtE,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;IACjC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC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,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;oBAC9D,IAAI,CAAC,MAAM;wBAAE,SAAS;oBACtB,IAAI,MAAM,CAAC,aAAa;wBAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;oBACxD,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;wBACzB,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;wBAC7B,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;oBACnF,CAAC;gBACH,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE;oBAC/C,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC;oBAClC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC;iBACzB,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,UAAU,GAAG,SAAS;IAClE,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,GAAG,UAAU,IAAI,OAAO,EAAE;QAChC,YAAY;QACZ,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { modelRef, z } from 'genkit';\nimport { genkitPluginV2, model } from 'genkit/plugin';\nimport { Qevrion, type ChatParams, type QevrionOptions, type Usage } from './index.js';\n\nexport interface QevrionGenkitOptions extends QevrionOptions {\n name?: string;\n}\n\nconst configSchema = z\n .object({\n // Genkit injects this field even when no model version was requested.\n version: z.undefined().optional(),\n maxOutputTokens: z.number().int().min(1).max(4096).optional(),\n temperature: z.number().min(0).max(2).optional(),\n topP: z.number().min(0).max(1).optional(),\n })\n .strict();\n\nconst supports = {\n multiturn: true,\n tools: false,\n media: false,\n systemRole: true,\n output: ['text' as const],\n};\n\nfunction usage(value?: Usage | null) {\n return value\n ? {\n inputTokens: value.prompt_tokens,\n outputTokens: value.completion_tokens,\n totalTokens: value.total_tokens,\n }\n : undefined;\n}\n\nfunction finishReason(value: string | null): 'stop' | 'length' | 'blocked' | 'other' {\n if (value === 'stop' || value === 'length') return value;\n return value === 'content_filter' ? 'blocked' : 'other';\n}\n\nexport function qevrion(options: QevrionGenkitOptions) {\n const client = new Qevrion(options);\n const name = options.name ?? 'qevrion';\n return genkitPluginV2({\n name,\n async resolve(actionType, actionName) {\n if (actionType !== 'model') return undefined;\n const id = actionName.startsWith(`${name}/`) ? actionName.slice(name.length + 1) : actionName;\n return model({ name: `${name}/${id}`, supports, configSchema }, async (request, context) => {\n const config = configSchema.parse(request.config ?? {});\n if (request.tools?.length || (request.output?.format && request.output.format !== 'text')) {\n throw new TypeError('Qevrion supports text chat only.');\n }\n const params: ChatParams = {\n model: id,\n messages: request.messages.map((message) => {\n if (\n !['user', 'model', 'system'].includes(message.role) ||\n message.content.some((part) => typeof part.text !== 'string')\n ) {\n throw new TypeError(\n 'Qevrion supports text system, user, and assistant messages only.',\n );\n }\n return {\n role: message.role === 'model' ? 'assistant' : (message.role as 'system' | 'user'),\n content: message.content.map((part) => part.text).join(''),\n };\n }),\n max_tokens: config.maxOutputTokens,\n temperature: config.temperature,\n top_p: config.topP,\n };\n const requestOptions = { signal: context.abortSignal };\n if (!context.streamingRequested) {\n const result = await client.chat.completions.create(params, requestOptions);\n const choice = result.choices[0];\n if (!choice) throw new Error('Qevrion returned no completion choices.');\n return {\n message: { role: 'model', content: [{ text: choice.message.content ?? '' }] },\n finishReason: finishReason(choice.finish_reason),\n usage: usage(result.usage),\n raw: result,\n };\n }\n let text = '';\n let reason: string | null = null;\n let finalUsage: Usage | null | undefined;\n for await (const chunk of client.chat.completions.stream(params, requestOptions)) {\n if (chunk.usage) finalUsage = chunk.usage;\n const choice = chunk.choices.find((item) => item.index === 0);\n if (!choice) continue;\n if (choice.finish_reason) reason = choice.finish_reason;\n if (choice.delta.content) {\n text += choice.delta.content;\n await context.sendChunk({ index: 0, content: [{ text: choice.delta.content }] });\n }\n }\n return {\n message: { role: 'model', content: [{ text }] },\n finishReason: finishReason(reason),\n usage: usage(finalUsage),\n };\n });\n },\n });\n}\n\n/** Pass a catalog model ID, including its provider, e.g. openai/gpt-4o-mini. */\nexport function qevrionModel(modelId: string, pluginName = 'qevrion') {\n return modelRef({\n name: `${pluginName}/${modelId}`,\n configSchema,\n info: { label: modelId, supports },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"genkit.js","sourceRoot":"","sources":["../src/genkit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,OAAO,EAAoD,MAAM,YAAY,CAAC;AAMvF,MAAM,YAAY,GAAG,CAAC;KACnB,MAAM,CAAC;IACN,sEAAsE;IACtE,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE;IACjC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;IAC7D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE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AC;QACjB,IAAI,EAAE,GAAG,UAAU,IAAI,OAAO,EAAE;QAChC,YAAY,EAAE,qBAAqB;QACnC,IAAI,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE;KACxC,CAAC,CAAC;AACL,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,UAAU,GAAG,SAAS;IAClE,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,GAAG,UAAU,IAAI,OAAO,EAAE;QAChC,YAAY;QACZ,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { modelRef, z } from 'genkit';\nimport { embedderRef } from 'genkit/embedder';\nimport { embedder, genkitPluginV2, model } from 'genkit/plugin';\nimport { Qevrion, type ChatParams, type QevrionOptions, type Usage } from './index.js';\n\nexport interface QevrionGenkitOptions extends QevrionOptions {\n name?: string;\n}\n\nconst configSchema = z\n .object({\n // Genkit injects this field even when no model version was requested.\n version: z.undefined().optional(),\n maxOutputTokens: z.number().int().min(1).max(4096).optional(),\n temperature: z.number().min(0).max(2).optional(),\n topP: z.number().min(0).max(1).optional(),\n })\n .strict();\n\nconst supports = {\n multiturn: true,\n tools: false,\n media: false,\n systemRole: true,\n output: ['text' as const],\n};\n\nconst embeddingConfigSchema = z\n .object({\n version: z.undefined().optional(),\n dimensions: z.number().int().min(1).max(65536).optional(),\n inputType: z.string().min(1).max(100).optional(),\n })\n .strict();\n\nfunction usage(value?: Usage | null) {\n return value\n ? {\n inputTokens: value.prompt_tokens,\n outputTokens: value.completion_tokens,\n totalTokens: value.total_tokens,\n }\n : undefined;\n}\n\nfunction finishReason(value: string | null): 'stop' | 'length' | 'blocked' | 'other' {\n if (value === 'stop' || value === 'length') return value;\n return value === 'content_filter' ? 'blocked' : 'other';\n}\n\nexport function qevrion(options: QevrionGenkitOptions) {\n const client = new Qevrion(options);\n const name = options.name ?? 'qevrion';\n return genkitPluginV2({\n name,\n async resolve(actionType, actionName) {\n const id = actionName.startsWith(`${name}/`) ? actionName.slice(name.length + 1) : actionName;\n if (actionType === 'embedder') {\n return embedder(\n {\n name: `${name}/${id}`,\n configSchema: embeddingConfigSchema,\n info: { supports: { input: ['text'] } },\n },\n async (request, context) => {\n const config = embeddingConfigSchema.parse(request.options ?? {});\n const input = request.input.map((document) => {\n if (document.content.some((part) => typeof part.text !== 'string'))\n throw new TypeError('Qevrion embeddings support text documents only.');\n return document.text;\n });\n const result = await client.embeddings.create(\n { model: id, input, dimensions: config.dimensions, input_type: config.inputType },\n { signal: context.abortSignal },\n );\n return {\n embeddings: [...result.data]\n .sort((a, b) => a.index - b.index)\n .map((item) => ({ embedding: item.embedding })),\n };\n },\n );\n }\n if (actionType !== 'model') return undefined;\n return model({ name: `${name}/${id}`, supports, configSchema }, async (request, context) => {\n const config = configSchema.parse(request.config ?? {});\n if (request.tools?.length || (request.output?.format && request.output.format !== 'text')) {\n throw new TypeError('Qevrion supports text chat only.');\n }\n const params: ChatParams = {\n model: id,\n messages: request.messages.map((message) => {\n if (\n !['user', 'model', 'system'].includes(message.role) ||\n message.content.some((part) => typeof part.text !== 'string')\n ) {\n throw new TypeError(\n 'Qevrion supports text system, user, and assistant messages only.',\n );\n }\n return {\n role: message.role === 'model' ? 'assistant' : (message.role as 'system' | 'user'),\n content: message.content.map((part) => part.text).join(''),\n };\n }),\n max_tokens: config.maxOutputTokens,\n temperature: config.temperature,\n top_p: config.topP,\n };\n const requestOptions = { signal: context.abortSignal };\n if (!context.streamingRequested) {\n const result = await client.chat.completions.create(params, requestOptions);\n const choice = result.choices[0];\n if (!choice) throw new Error('Qevrion returned no completion choices.');\n return {\n message: { role: 'model', content: [{ text: choice.message.content ?? '' }] },\n finishReason: finishReason(choice.finish_reason),\n usage: usage(result.usage),\n raw: result,\n };\n }\n let text = '';\n let reason: string | null = null;\n let finalUsage: Usage | null | undefined;\n for await (const chunk of client.chat.completions.stream(params, requestOptions)) {\n if (chunk.usage) finalUsage = chunk.usage;\n const choice = chunk.choices.find((item) => item.index === 0);\n if (!choice) continue;\n if (choice.finish_reason) reason = choice.finish_reason;\n if (choice.delta.content) {\n text += choice.delta.content;\n await context.sendChunk({ index: 0, content: [{ text: choice.delta.content }] });\n }\n }\n return {\n message: { role: 'model', content: [{ text }] },\n finishReason: finishReason(reason),\n usage: usage(finalUsage),\n };\n });\n },\n });\n}\n\n/** Reference an enabled embedding model for ai.embed() or ai.embedMany(). */\nexport function qevrionEmbedder(modelId: string, pluginName = 'qevrion') {\n return embedderRef({\n name: `${pluginName}/${modelId}`,\n configSchema: embeddingConfigSchema,\n info: { supports: { input: ['text'] } },\n });\n}\n\n/** Pass a catalog model ID, including its provider, e.g. openai/gpt-4o-mini. */\nexport function qevrionModel(modelId: string, pluginName = 'qevrion') {\n return modelRef({\n name: `${pluginName}/${modelId}`,\n configSchema,\n info: { label: modelId, supports },\n });\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatChunk, ChatCompletion, ChatParams, ModelList, QevrionOptions, RequestOptions } from './types.js';
|
|
1
|
+
import type { ChatChunk, ChatCompletion, ChatParams, EmbeddingParams, EmbeddingResponse, ModelList, ModelListOptions, QevrionOptions, RequestOptions } from './types.js';
|
|
2
2
|
export type * from './types.js';
|
|
3
3
|
export declare const DEFAULT_BASE_URL = "https://useqevrion.com/v1";
|
|
4
4
|
export declare class QevrionAPIError extends Error {
|
|
@@ -22,7 +22,10 @@ export declare class Qevrion {
|
|
|
22
22
|
#private;
|
|
23
23
|
constructor(options: QevrionOptions);
|
|
24
24
|
readonly models: {
|
|
25
|
-
list: (options?:
|
|
25
|
+
list: (options?: ModelListOptions) => Promise<ModelList>;
|
|
26
|
+
};
|
|
27
|
+
readonly embeddings: {
|
|
28
|
+
create: <Encoding extends "float" | "base64" = "float">(params: EmbeddingParams<Encoding>, options?: RequestOptions) => Promise<EmbeddingResponse<Encoding>>;
|
|
26
29
|
};
|
|
27
30
|
readonly chat: {
|
|
28
31
|
completions: {
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,10 @@ export class Qevrion {
|
|
|
66
66
|
this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
67
67
|
}
|
|
68
68
|
models = {
|
|
69
|
-
list: (options) => this.#json('/models', undefined, options),
|
|
69
|
+
list: (options) => this.#json(options?.type ? `/models?type=${encodeURIComponent(options.type)}` : '/models', undefined, options),
|
|
70
|
+
};
|
|
71
|
+
embeddings = {
|
|
72
|
+
create: (params, options) => this.#json('/embeddings', params, options),
|
|
70
73
|
};
|
|
71
74
|
chat = {
|
|
72
75
|
completions: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAE5D,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAAS;IACf,IAAI,CAAU;IACd,IAAI,CAAU;IACd,SAAS,CAAU;IAE5B,YACE,OAAe,EACf,MAAc,EACd,UAII,EAAE;QAEN,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,sBA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E,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n ChatChunk,\n ChatCompletion,\n ChatParams,\n ModelList,\n QevrionOptions,\n RequestOptions,\n} from './types.js';\nexport type * from './types.js';\n\nexport const DEFAULT_BASE_URL = 'https://useqevrion.com/v1';\n\nexport class QevrionAPIError extends Error {\n readonly status: number;\n readonly type?: string;\n readonly code?: string;\n readonly requestId?: string;\n\n constructor(\n message: string,\n status: number,\n details: {\n type?: string;\n code?: string;\n requestId?: string;\n } = {},\n ) {\n super(message);\n this.name = 'QevrionAPIError';\n this.status = status;\n this.type = details.type;\n this.code = details.code;\n this.requestId = details.requestId;\n }\n}\n\nexport class QevrionProtocolError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'QevrionProtocolError';\n }\n}\n\nexport function normalizeBaseURL(value: string = DEFAULT_BASE_URL): string {\n const url = new URL(value);\n if (\n !['http:', 'https:'].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n ) {\n throw new TypeError(\n 'baseURL must be an HTTP(S) API root without credentials, query, or fragment.',\n );\n }\n return url.href.replace(/\\/+$/, '');\n}\n\nexport function validateApiKey(apiKey: string): void {\n if (typeof apiKey !== 'string' || !/^qv_[a-zA-Z0-9_-]+$/.test(apiKey)) {\n throw new TypeError('A Qevrion API key beginning with qv_ is required.');\n }\n}\n\nfunction validateTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout < 1 || timeout > 2_147_483_647) {\n throw new TypeError('timeoutMs must be a positive integer no greater than 2147483647.');\n }\n}\n\nfunction apiError(body: unknown, response: Response): QevrionAPIError {\n const error = (body as { error?: { message?: unknown; type?: unknown; code?: unknown } } | null)\n ?.error;\n return new QevrionAPIError(\n typeof error?.message === 'string'\n ? error.message\n : `Qevrion request failed (${response.status}).`,\n response.status,\n {\n type: typeof error?.type === 'string' ? error.type : undefined,\n code: typeof error?.code === 'string' ? error.code : undefined,\n requestId: response.headers.get('x-qevrionai-request-id') ?? undefined,\n },\n );\n}\n\n/** Server-side ESM client. Requests are never automatically retried. */\nexport class Qevrion {\n readonly #apiKey: string;\n readonly #baseURL: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof globalThis.fetch;\n\n constructor(options: QevrionOptions) {\n validateApiKey(options.apiKey);\n this.#apiKey = options.apiKey;\n this.#baseURL = normalizeBaseURL(options.baseURL);\n this.#timeoutMs = options.timeoutMs ?? 120_000;\n validateTimeout(this.#timeoutMs);\n this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n readonly models = {\n list: (options?: RequestOptions): Promise<ModelList> =>\n this.#json('/models', undefined, options),\n };\n\n readonly chat = {\n completions: {\n create: (params: ChatParams, options?: RequestOptions): Promise<ChatCompletion> =>\n this.#json('/chat/completions', { ...params, stream: false }, options),\n stream: (params: ChatParams, options?: RequestOptions): AsyncGenerator<ChatChunk> =>\n this.#stream(params, options),\n },\n };\n\n async #request(path: string, body: unknown, options: RequestOptions = {}) {\n const timeout = options.timeoutMs ?? this.#timeoutMs;\n validateTimeout(timeout);\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(new DOMException('Qevrion request timed out.', 'TimeoutError')),\n timeout,\n );\n const signal = options.signal\n ? AbortSignal.any([options.signal, controller.signal])\n : controller.signal;\n try {\n const response = await this.#fetch(`${this.#baseURL}${path}`, {\n method: body === undefined ? 'GET' : 'POST',\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal,\n redirect: 'error',\n });\n if (!response.ok) {\n const text = await response.text();\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n /* Proxy errors can be HTML. */\n }\n throw apiError(parsed, response);\n }\n return {\n response,\n dispose: () => {\n clearTimeout(timer);\n controller.abort();\n },\n };\n } catch (error) {\n clearTimeout(timer);\n controller.abort();\n throw error;\n }\n }\n\n async #json<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n const { response, dispose } = await this.#request(path, body, options);\n try {\n const text = await response.text();\n try {\n return JSON.parse(text) as T;\n } catch (cause) {\n throw new QevrionProtocolError('Qevrion returned invalid JSON.', { cause });\n }\n } finally {\n dispose();\n }\n }\n\n async *#stream(params: ChatParams, options?: RequestOptions): AsyncGenerator<ChatChunk> {\n const { response, dispose } = await this.#request(\n '/chat/completions',\n { ...params, stream: true },\n options,\n );\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n try {\n if (\n !response.headers.get('content-type')?.toLowerCase().startsWith('text/event-stream') ||\n !response.body\n ) {\n throw new QevrionProtocolError('Expected a text/event-stream response.');\n }\n reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n while (true) {\n const { value, done } = await reader.read();\n buffer += decoder.decode(value, { stream: !done });\n let boundary: RegExpExecArray | null;\n while ((boundary = /\\r?\\n\\r?\\n/.exec(buffer)) !== null || (done && buffer.length > 0)) {\n const frame = boundary ? buffer.slice(0, boundary.index) : buffer;\n buffer = boundary ? buffer.slice(boundary.index + boundary[0].length) : '';\n const data = frame\n .split(/\\r?\\n/)\n .filter((line) => line.startsWith('data:'))\n .map((line) => line.slice(5).replace(/^ /, ''))\n .join('\\n');\n if (!data) continue;\n if (data.trim() === '[DONE]') return;\n let chunk: ChatChunk;\n try {\n chunk = JSON.parse(data) as ChatChunk;\n } catch (cause) {\n throw new QevrionProtocolError('Invalid JSON in Qevrion stream.', { cause });\n }\n if (chunk && typeof chunk === 'object' && 'error' in chunk)\n throw apiError(chunk, response);\n yield chunk;\n }\n if (done) throw new QevrionProtocolError('Qevrion stream ended before [DONE].');\n }\n } finally {\n dispose();\n if (reader) {\n try {\n await reader.cancel();\n } catch {\n /* An aborted reader may already be closed. */\n }\n reader.releaseLock();\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC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AAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;yBAC9C,IAAI,CAAC,IAAI,CAAC,CAAC;oBACd,IAAI,CAAC,IAAI;wBAAE,SAAS;oBACpB,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,QAAQ;wBAAE,OAAO;oBACrC,IAAI,KAAgB,CAAC;oBACrB,IAAI,CAAC;wBACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAc,CAAC;oBACxC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,IAAI,oBAAoB,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;oBAC/E,CAAC;oBACD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK;wBACxD,MAAM,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;oBAClC,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,IAAI,IAAI;oBAAE,MAAM,IAAI,oBAAoB,CAAC,qCAAqC,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,OAAO,EAAE,CAAC;YACV,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;gBACxB,CAAC;gBAAC,MAAM,CAAC;oBACP,8CAA8C;gBAChD,CAAC;gBACD,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n ChatChunk,\n ChatCompletion,\n ChatParams,\n EmbeddingParams,\n EmbeddingResponse,\n ModelList,\n ModelListOptions,\n QevrionOptions,\n RequestOptions,\n} from './types.js';\nexport type * from './types.js';\n\nexport const DEFAULT_BASE_URL = 'https://useqevrion.com/v1';\n\nexport class QevrionAPIError extends Error {\n readonly status: number;\n readonly type?: string;\n readonly code?: string;\n readonly requestId?: string;\n\n constructor(\n message: string,\n status: number,\n details: {\n type?: string;\n code?: string;\n requestId?: string;\n } = {},\n ) {\n super(message);\n this.name = 'QevrionAPIError';\n this.status = status;\n this.type = details.type;\n this.code = details.code;\n this.requestId = details.requestId;\n }\n}\n\nexport class QevrionProtocolError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'QevrionProtocolError';\n }\n}\n\nexport function normalizeBaseURL(value: string = DEFAULT_BASE_URL): string {\n const url = new URL(value);\n if (\n !['http:', 'https:'].includes(url.protocol) ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n ) {\n throw new TypeError(\n 'baseURL must be an HTTP(S) API root without credentials, query, or fragment.',\n );\n }\n return url.href.replace(/\\/+$/, '');\n}\n\nexport function validateApiKey(apiKey: string): void {\n if (typeof apiKey !== 'string' || !/^qv_[a-zA-Z0-9_-]+$/.test(apiKey)) {\n throw new TypeError('A Qevrion API key beginning with qv_ is required.');\n }\n}\n\nfunction validateTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout < 1 || timeout > 2_147_483_647) {\n throw new TypeError('timeoutMs must be a positive integer no greater than 2147483647.');\n }\n}\n\nfunction apiError(body: unknown, response: Response): QevrionAPIError {\n const error = (body as { error?: { message?: unknown; type?: unknown; code?: unknown } } | null)\n ?.error;\n return new QevrionAPIError(\n typeof error?.message === 'string'\n ? error.message\n : `Qevrion request failed (${response.status}).`,\n response.status,\n {\n type: typeof error?.type === 'string' ? error.type : undefined,\n code: typeof error?.code === 'string' ? error.code : undefined,\n requestId: response.headers.get('x-qevrionai-request-id') ?? undefined,\n },\n );\n}\n\n/** Server-side ESM client. Requests are never automatically retried. */\nexport class Qevrion {\n readonly #apiKey: string;\n readonly #baseURL: string;\n readonly #timeoutMs: number;\n readonly #fetch: typeof globalThis.fetch;\n\n constructor(options: QevrionOptions) {\n validateApiKey(options.apiKey);\n this.#apiKey = options.apiKey;\n this.#baseURL = normalizeBaseURL(options.baseURL);\n this.#timeoutMs = options.timeoutMs ?? 120_000;\n validateTimeout(this.#timeoutMs);\n this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);\n }\n\n readonly models = {\n list: (options?: ModelListOptions): Promise<ModelList> =>\n this.#json(\n options?.type ? `/models?type=${encodeURIComponent(options.type)}` : '/models',\n undefined,\n options,\n ),\n };\n\n readonly embeddings = {\n create: <Encoding extends 'float' | 'base64' = 'float'>(\n params: EmbeddingParams<Encoding>,\n options?: RequestOptions,\n ): Promise<EmbeddingResponse<Encoding>> => this.#json('/embeddings', params, options),\n };\n\n readonly chat = {\n completions: {\n create: (params: ChatParams, options?: RequestOptions): Promise<ChatCompletion> =>\n this.#json('/chat/completions', { ...params, stream: false }, options),\n stream: (params: ChatParams, options?: RequestOptions): AsyncGenerator<ChatChunk> =>\n this.#stream(params, options),\n },\n };\n\n async #request(path: string, body: unknown, options: RequestOptions = {}) {\n const timeout = options.timeoutMs ?? this.#timeoutMs;\n validateTimeout(timeout);\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(new DOMException('Qevrion request timed out.', 'TimeoutError')),\n timeout,\n );\n const signal = options.signal\n ? AbortSignal.any([options.signal, controller.signal])\n : controller.signal;\n try {\n const response = await this.#fetch(`${this.#baseURL}${path}`, {\n method: body === undefined ? 'GET' : 'POST',\n headers: {\n Authorization: `Bearer ${this.#apiKey}`,\n ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal,\n redirect: 'error',\n });\n if (!response.ok) {\n const text = await response.text();\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n /* Proxy errors can be HTML. */\n }\n throw apiError(parsed, response);\n }\n return {\n response,\n dispose: () => {\n clearTimeout(timer);\n controller.abort();\n },\n };\n } catch (error) {\n clearTimeout(timer);\n controller.abort();\n throw error;\n }\n }\n\n async #json<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n const { response, dispose } = await this.#request(path, body, options);\n try {\n const text = await response.text();\n try {\n return JSON.parse(text) as T;\n } catch (cause) {\n throw new QevrionProtocolError('Qevrion returned invalid JSON.', { cause });\n }\n } finally {\n dispose();\n }\n }\n\n async *#stream(params: ChatParams, options?: RequestOptions): AsyncGenerator<ChatChunk> {\n const { response, dispose } = await this.#request(\n '/chat/completions',\n { ...params, stream: true },\n options,\n );\n let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;\n try {\n if (\n !response.headers.get('content-type')?.toLowerCase().startsWith('text/event-stream') ||\n !response.body\n ) {\n throw new QevrionProtocolError('Expected a text/event-stream response.');\n }\n reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n while (true) {\n const { value, done } = await reader.read();\n buffer += decoder.decode(value, { stream: !done });\n let boundary: RegExpExecArray | null;\n while ((boundary = /\\r?\\n\\r?\\n/.exec(buffer)) !== null || (done && buffer.length > 0)) {\n const frame = boundary ? buffer.slice(0, boundary.index) : buffer;\n buffer = boundary ? buffer.slice(boundary.index + boundary[0].length) : '';\n const data = frame\n .split(/\\r?\\n/)\n .filter((line) => line.startsWith('data:'))\n .map((line) => line.slice(5).replace(/^ /, ''))\n .join('\\n');\n if (!data) continue;\n if (data.trim() === '[DONE]') return;\n let chunk: ChatChunk;\n try {\n chunk = JSON.parse(data) as ChatChunk;\n } catch (cause) {\n throw new QevrionProtocolError('Invalid JSON in Qevrion stream.', { cause });\n }\n if (chunk && typeof chunk === 'object' && 'error' in chunk)\n throw apiError(chunk, response);\n yield chunk;\n }\n if (done) throw new QevrionProtocolError('Qevrion stream ended before [DONE].');\n }\n } finally {\n dispose();\n if (reader) {\n try {\n await reader.cancel();\n } catch {\n /* An aborted reader may already be closed. */\n }\n reader.releaseLock();\n }\n }\n }\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface ChatChunk {
|
|
|
49
49
|
}
|
|
50
50
|
export interface Model {
|
|
51
51
|
id: string;
|
|
52
|
+
type: 'chat' | 'embedding';
|
|
52
53
|
object: 'model';
|
|
53
54
|
owned_by: string;
|
|
54
55
|
name: string;
|
|
@@ -63,6 +64,34 @@ export interface RequestOptions {
|
|
|
63
64
|
/** Deadline for the entire request, including stream consumption. */
|
|
64
65
|
timeoutMs?: number;
|
|
65
66
|
}
|
|
67
|
+
export interface ModelListOptions extends RequestOptions {
|
|
68
|
+
type?: 'chat' | 'embedding';
|
|
69
|
+
}
|
|
70
|
+
export interface EmbeddingParams<Encoding extends 'float' | 'base64' = 'float'> {
|
|
71
|
+
model: string;
|
|
72
|
+
/** A non-empty string or a batch of 1 to 100 non-empty strings. */
|
|
73
|
+
input: string | string[];
|
|
74
|
+
encoding_format?: Encoding;
|
|
75
|
+
/** Between 1 and 65536; support depends on the model. */
|
|
76
|
+
dimensions?: number;
|
|
77
|
+
/** Provider-specific task hint, e.g. search_query or search_document. */
|
|
78
|
+
input_type?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface EmbeddingResponse<Encoding extends 'float' | 'base64' = 'float'> {
|
|
81
|
+
id?: string;
|
|
82
|
+
object: 'list';
|
|
83
|
+
model: string;
|
|
84
|
+
data: Array<{
|
|
85
|
+
object: 'embedding';
|
|
86
|
+
index: number;
|
|
87
|
+
embedding: Encoding extends 'base64' ? string : number[];
|
|
88
|
+
}>;
|
|
89
|
+
usage?: {
|
|
90
|
+
prompt_tokens: number;
|
|
91
|
+
total_tokens: number;
|
|
92
|
+
cost?: number;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
66
95
|
export interface QevrionOptions {
|
|
67
96
|
apiKey: string;
|
|
68
97
|
/** API root including /v1. */
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface Message {\n role: 'system' | 'user' | 'assistant';\n content: string;\n}\n\nexport interface ChatParams {\n model: string;\n messages: Message[];\n /** Between 1 and 4096. Server default: 1024. */\n max_tokens?: number;\n temperature?: number;\n top_p?: number;\n}\n\nexport interface Usage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n /** Upstream cost, when present; not the final Qevrion account charge. */\n cost?: number;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: 'chat.completion';\n created: number;\n model: string;\n choices: Array<{\n index: number;\n message: { role: 'assistant'; content: string | null };\n finish_reason: string | null;\n }>;\n usage?: Usage;\n}\n\nexport interface ChatChunk {\n id: string;\n object: 'chat.completion.chunk';\n created: number;\n model: string;\n choices: Array<{\n index: number;\n delta: { role?: 'assistant'; content?: string | null };\n finish_reason: string | null;\n }>;\n usage?: Usage | null;\n}\n\nexport interface Model {\n id: string;\n object: 'model';\n owned_by: string;\n name: string;\n context_length: number;\n}\n\nexport interface ModelList {\n object: 'list';\n data: Model[];\n}\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n /** Deadline for the entire request, including stream consumption. */\n timeoutMs?: number;\n}\n\nexport interface QevrionOptions {\n apiKey: string;\n /** API root including /v1. */\n baseURL?: string;\n /** Default: 120000 milliseconds. */\n timeoutMs?: number;\n fetch?: typeof globalThis.fetch;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface Message {\n role: 'system' | 'user' | 'assistant';\n content: string;\n}\n\nexport interface ChatParams {\n model: string;\n messages: Message[];\n /** Between 1 and 4096. Server default: 1024. */\n max_tokens?: number;\n temperature?: number;\n top_p?: number;\n}\n\nexport interface Usage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n /** Upstream cost, when present; not the final Qevrion account charge. */\n cost?: number;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: 'chat.completion';\n created: number;\n model: string;\n choices: Array<{\n index: number;\n message: { role: 'assistant'; content: string | null };\n finish_reason: string | null;\n }>;\n usage?: Usage;\n}\n\nexport interface ChatChunk {\n id: string;\n object: 'chat.completion.chunk';\n created: number;\n model: string;\n choices: Array<{\n index: number;\n delta: { role?: 'assistant'; content?: string | null };\n finish_reason: string | null;\n }>;\n usage?: Usage | null;\n}\n\nexport interface Model {\n id: string;\n type: 'chat' | 'embedding';\n object: 'model';\n owned_by: string;\n name: string;\n context_length: number;\n}\n\nexport interface ModelList {\n object: 'list';\n data: Model[];\n}\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n /** Deadline for the entire request, including stream consumption. */\n timeoutMs?: number;\n}\n\nexport interface ModelListOptions extends RequestOptions {\n type?: 'chat' | 'embedding';\n}\n\nexport interface EmbeddingParams<Encoding extends 'float' | 'base64' = 'float'> {\n model: string;\n /** A non-empty string or a batch of 1 to 100 non-empty strings. */\n input: string | string[];\n encoding_format?: Encoding;\n /** Between 1 and 65536; support depends on the model. */\n dimensions?: number;\n /** Provider-specific task hint, e.g. search_query or search_document. */\n input_type?: string;\n}\n\nexport interface EmbeddingResponse<Encoding extends 'float' | 'base64' = 'float'> {\n id?: string;\n object: 'list';\n model: string;\n data: Array<{\n object: 'embedding';\n index: number;\n embedding: Encoding extends 'base64' ? string : number[];\n }>;\n usage?: { prompt_tokens: number; total_tokens: number; cost?: number };\n}\n\nexport interface QevrionOptions {\n apiKey: string;\n /** API root including /v1. */\n baseURL?: string;\n /** Default: 120000 milliseconds. */\n timeoutMs?: number;\n fetch?: typeof globalThis.fetch;\n}\n"]}
|