@apertis/ai-sdk-provider 1.0.0 → 1.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 +52 -0
- package/dist/index.cjs +336 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -5
- package/dist/index.d.ts +66 -5
- package/dist/index.js +341 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
type ApertisModelId = "gpt-5.2" | "gpt-5.2-codex" | "gpt-5.1" | "claude-opus-4-5-20251101" | "claude-sonnet-4.5" | "claude-haiku-4.5" | "gemini-3-pro-preview" | "gemini-3-flash-preview" | "gemini-2.5-flash-preview" | (string & {});
|
|
4
4
|
interface ApertisProviderSettings {
|
|
@@ -36,9 +36,51 @@ interface ApertisChatSettings {
|
|
|
36
36
|
topLogprobs?: number;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
interface
|
|
39
|
+
interface ApertisCompletionSettings {
|
|
40
|
+
/**
|
|
41
|
+
* Echo back the prompt in addition to the completion.
|
|
42
|
+
*/
|
|
43
|
+
echo?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Include the log probabilities on the logprobs most likely tokens.
|
|
46
|
+
*/
|
|
47
|
+
logprobs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The suffix that comes after a completion of inserted text.
|
|
50
|
+
*/
|
|
51
|
+
suffix?: string;
|
|
52
|
+
/**
|
|
53
|
+
* A unique identifier representing your end-user.
|
|
54
|
+
*/
|
|
55
|
+
user?: string;
|
|
56
|
+
}
|
|
57
|
+
type ApertisCompletionModelId = "gpt-3.5-turbo-instruct" | "davinci-002" | "babbage-002" | (string & {});
|
|
58
|
+
|
|
59
|
+
interface ApertisEmbeddingSettings {
|
|
60
|
+
/**
|
|
61
|
+
* Override the maximum number of embeddings per call.
|
|
62
|
+
*/
|
|
63
|
+
maxEmbeddingsPerCall?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Override the parallelism of embedding calls.
|
|
66
|
+
*/
|
|
67
|
+
supportsParallelCalls?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
70
|
+
* Only supported in text-embedding-3 and later models.
|
|
71
|
+
*/
|
|
72
|
+
dimensions?: number;
|
|
73
|
+
/**
|
|
74
|
+
* A unique identifier representing your end-user.
|
|
75
|
+
*/
|
|
76
|
+
user?: string;
|
|
77
|
+
}
|
|
78
|
+
type ApertisEmbeddingModelId = "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002" | (string & {});
|
|
79
|
+
|
|
80
|
+
interface ApertisProvider extends ProviderV3 {
|
|
40
81
|
/**
|
|
41
82
|
* Creates a chat model for text generation.
|
|
83
|
+
* Default call creates a chat model.
|
|
42
84
|
*/
|
|
43
85
|
(modelId: ApertisModelId, settings?: ApertisChatSettings): LanguageModelV3;
|
|
44
86
|
/**
|
|
@@ -46,9 +88,28 @@ interface ApertisProvider {
|
|
|
46
88
|
*/
|
|
47
89
|
chat(modelId: ApertisModelId, settings?: ApertisChatSettings): LanguageModelV3;
|
|
48
90
|
/**
|
|
49
|
-
* Creates a
|
|
91
|
+
* Creates a language model (alias for chat).
|
|
92
|
+
* Required by ProviderV3 interface.
|
|
93
|
+
*/
|
|
94
|
+
languageModel(modelId: string): LanguageModelV3;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a completion model for text completions.
|
|
97
|
+
*/
|
|
98
|
+
completion(modelId: ApertisCompletionModelId, settings?: ApertisCompletionSettings): LanguageModelV3;
|
|
99
|
+
/**
|
|
100
|
+
* Creates an embedding model.
|
|
101
|
+
* Required by ProviderV3 interface.
|
|
102
|
+
*/
|
|
103
|
+
embeddingModel(modelId: string): EmbeddingModelV3;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a text embedding model.
|
|
106
|
+
*/
|
|
107
|
+
textEmbeddingModel(modelId: ApertisEmbeddingModelId, settings?: ApertisEmbeddingSettings): EmbeddingModelV3;
|
|
108
|
+
/**
|
|
109
|
+
* Image models are not supported by Apertis.
|
|
110
|
+
* Required by ProviderV3 interface.
|
|
50
111
|
*/
|
|
51
|
-
|
|
112
|
+
imageModel(modelId: string): never;
|
|
52
113
|
}
|
|
53
114
|
declare function createApertis(options?: ApertisProviderSettings): ApertisProvider;
|
|
54
115
|
/**
|
|
@@ -56,4 +117,4 @@ declare function createApertis(options?: ApertisProviderSettings): ApertisProvid
|
|
|
56
117
|
*/
|
|
57
118
|
declare const apertis: ApertisProvider;
|
|
58
119
|
|
|
59
|
-
export { type ApertisChatSettings, type ApertisModelId, type ApertisProvider, type ApertisProviderSettings, apertis, createApertis };
|
|
120
|
+
export { type ApertisChatSettings, type ApertisCompletionModelId, type ApertisCompletionSettings, type ApertisEmbeddingModelId, type ApertisEmbeddingSettings, type ApertisModelId, type ApertisProvider, type ApertisProviderSettings, apertis, createApertis };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
type ApertisModelId = "gpt-5.2" | "gpt-5.2-codex" | "gpt-5.1" | "claude-opus-4-5-20251101" | "claude-sonnet-4.5" | "claude-haiku-4.5" | "gemini-3-pro-preview" | "gemini-3-flash-preview" | "gemini-2.5-flash-preview" | (string & {});
|
|
4
4
|
interface ApertisProviderSettings {
|
|
@@ -36,9 +36,51 @@ interface ApertisChatSettings {
|
|
|
36
36
|
topLogprobs?: number;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
interface
|
|
39
|
+
interface ApertisCompletionSettings {
|
|
40
|
+
/**
|
|
41
|
+
* Echo back the prompt in addition to the completion.
|
|
42
|
+
*/
|
|
43
|
+
echo?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Include the log probabilities on the logprobs most likely tokens.
|
|
46
|
+
*/
|
|
47
|
+
logprobs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The suffix that comes after a completion of inserted text.
|
|
50
|
+
*/
|
|
51
|
+
suffix?: string;
|
|
52
|
+
/**
|
|
53
|
+
* A unique identifier representing your end-user.
|
|
54
|
+
*/
|
|
55
|
+
user?: string;
|
|
56
|
+
}
|
|
57
|
+
type ApertisCompletionModelId = "gpt-3.5-turbo-instruct" | "davinci-002" | "babbage-002" | (string & {});
|
|
58
|
+
|
|
59
|
+
interface ApertisEmbeddingSettings {
|
|
60
|
+
/**
|
|
61
|
+
* Override the maximum number of embeddings per call.
|
|
62
|
+
*/
|
|
63
|
+
maxEmbeddingsPerCall?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Override the parallelism of embedding calls.
|
|
66
|
+
*/
|
|
67
|
+
supportsParallelCalls?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
70
|
+
* Only supported in text-embedding-3 and later models.
|
|
71
|
+
*/
|
|
72
|
+
dimensions?: number;
|
|
73
|
+
/**
|
|
74
|
+
* A unique identifier representing your end-user.
|
|
75
|
+
*/
|
|
76
|
+
user?: string;
|
|
77
|
+
}
|
|
78
|
+
type ApertisEmbeddingModelId = "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002" | (string & {});
|
|
79
|
+
|
|
80
|
+
interface ApertisProvider extends ProviderV3 {
|
|
40
81
|
/**
|
|
41
82
|
* Creates a chat model for text generation.
|
|
83
|
+
* Default call creates a chat model.
|
|
42
84
|
*/
|
|
43
85
|
(modelId: ApertisModelId, settings?: ApertisChatSettings): LanguageModelV3;
|
|
44
86
|
/**
|
|
@@ -46,9 +88,28 @@ interface ApertisProvider {
|
|
|
46
88
|
*/
|
|
47
89
|
chat(modelId: ApertisModelId, settings?: ApertisChatSettings): LanguageModelV3;
|
|
48
90
|
/**
|
|
49
|
-
* Creates a
|
|
91
|
+
* Creates a language model (alias for chat).
|
|
92
|
+
* Required by ProviderV3 interface.
|
|
93
|
+
*/
|
|
94
|
+
languageModel(modelId: string): LanguageModelV3;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a completion model for text completions.
|
|
97
|
+
*/
|
|
98
|
+
completion(modelId: ApertisCompletionModelId, settings?: ApertisCompletionSettings): LanguageModelV3;
|
|
99
|
+
/**
|
|
100
|
+
* Creates an embedding model.
|
|
101
|
+
* Required by ProviderV3 interface.
|
|
102
|
+
*/
|
|
103
|
+
embeddingModel(modelId: string): EmbeddingModelV3;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a text embedding model.
|
|
106
|
+
*/
|
|
107
|
+
textEmbeddingModel(modelId: ApertisEmbeddingModelId, settings?: ApertisEmbeddingSettings): EmbeddingModelV3;
|
|
108
|
+
/**
|
|
109
|
+
* Image models are not supported by Apertis.
|
|
110
|
+
* Required by ProviderV3 interface.
|
|
50
111
|
*/
|
|
51
|
-
|
|
112
|
+
imageModel(modelId: string): never;
|
|
52
113
|
}
|
|
53
114
|
declare function createApertis(options?: ApertisProviderSettings): ApertisProvider;
|
|
54
115
|
/**
|
|
@@ -56,4 +117,4 @@ declare function createApertis(options?: ApertisProviderSettings): ApertisProvid
|
|
|
56
117
|
*/
|
|
57
118
|
declare const apertis: ApertisProvider;
|
|
58
119
|
|
|
59
|
-
export { type ApertisChatSettings, type ApertisModelId, type ApertisProvider, type ApertisProviderSettings, apertis, createApertis };
|
|
120
|
+
export { type ApertisChatSettings, type ApertisCompletionModelId, type ApertisCompletionSettings, type ApertisEmbeddingModelId, type ApertisEmbeddingSettings, type ApertisModelId, type ApertisProvider, type ApertisProviderSettings, apertis, createApertis };
|
package/dist/index.js
CHANGED
|
@@ -458,6 +458,327 @@ var ApertisChatLanguageModel = class {
|
|
|
458
458
|
}
|
|
459
459
|
};
|
|
460
460
|
|
|
461
|
+
// src/apertis-completion-language-model.ts
|
|
462
|
+
import {
|
|
463
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
464
|
+
createJsonResponseHandler as createJsonResponseHandler2,
|
|
465
|
+
generateId as generateId2,
|
|
466
|
+
postJsonToApi as postJsonToApi2
|
|
467
|
+
} from "@ai-sdk/provider-utils";
|
|
468
|
+
|
|
469
|
+
// src/schemas/completion-response.ts
|
|
470
|
+
import { z as z3 } from "zod";
|
|
471
|
+
var openAICompletionResponseSchema = z3.object({
|
|
472
|
+
id: z3.string(),
|
|
473
|
+
object: z3.literal("text_completion"),
|
|
474
|
+
created: z3.number(),
|
|
475
|
+
model: z3.string(),
|
|
476
|
+
choices: z3.array(
|
|
477
|
+
z3.object({
|
|
478
|
+
text: z3.string(),
|
|
479
|
+
index: z3.number(),
|
|
480
|
+
logprobs: z3.object({
|
|
481
|
+
tokens: z3.array(z3.string()).optional(),
|
|
482
|
+
token_logprobs: z3.array(z3.number()).optional(),
|
|
483
|
+
top_logprobs: z3.array(z3.record(z3.number())).optional(),
|
|
484
|
+
text_offset: z3.array(z3.number()).optional()
|
|
485
|
+
}).nullable().optional(),
|
|
486
|
+
finish_reason: z3.string().nullable().optional()
|
|
487
|
+
})
|
|
488
|
+
),
|
|
489
|
+
usage: z3.object({
|
|
490
|
+
prompt_tokens: z3.number(),
|
|
491
|
+
completion_tokens: z3.number(),
|
|
492
|
+
total_tokens: z3.number()
|
|
493
|
+
}).optional()
|
|
494
|
+
});
|
|
495
|
+
var openAICompletionChunkSchema = z3.object({
|
|
496
|
+
id: z3.string(),
|
|
497
|
+
object: z3.literal("text_completion"),
|
|
498
|
+
created: z3.number(),
|
|
499
|
+
model: z3.string(),
|
|
500
|
+
choices: z3.array(
|
|
501
|
+
z3.object({
|
|
502
|
+
text: z3.string(),
|
|
503
|
+
index: z3.number(),
|
|
504
|
+
logprobs: z3.object({
|
|
505
|
+
tokens: z3.array(z3.string()).optional(),
|
|
506
|
+
token_logprobs: z3.array(z3.number()).optional(),
|
|
507
|
+
top_logprobs: z3.array(z3.record(z3.number())).optional(),
|
|
508
|
+
text_offset: z3.array(z3.number()).optional()
|
|
509
|
+
}).nullable().optional(),
|
|
510
|
+
finish_reason: z3.string().nullable().optional()
|
|
511
|
+
})
|
|
512
|
+
),
|
|
513
|
+
usage: z3.object({
|
|
514
|
+
prompt_tokens: z3.number(),
|
|
515
|
+
completion_tokens: z3.number(),
|
|
516
|
+
total_tokens: z3.number()
|
|
517
|
+
}).optional().nullable()
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
// src/apertis-completion-language-model.ts
|
|
521
|
+
var ApertisCompletionLanguageModel = class {
|
|
522
|
+
constructor(modelId, settings, config) {
|
|
523
|
+
this.modelId = modelId;
|
|
524
|
+
this.settings = settings;
|
|
525
|
+
this.config = config;
|
|
526
|
+
}
|
|
527
|
+
specificationVersion = "v3";
|
|
528
|
+
supportedUrls = {};
|
|
529
|
+
get provider() {
|
|
530
|
+
return this.config.provider;
|
|
531
|
+
}
|
|
532
|
+
async doGenerate(options) {
|
|
533
|
+
const body = this.buildRequestBody(options, false);
|
|
534
|
+
const { value: response } = await postJsonToApi2({
|
|
535
|
+
url: `${this.config.baseURL}/completions`,
|
|
536
|
+
headers: this.config.headers(),
|
|
537
|
+
body,
|
|
538
|
+
failedResponseHandler: apertisFailedResponseHandler,
|
|
539
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
540
|
+
openAICompletionResponseSchema
|
|
541
|
+
),
|
|
542
|
+
fetch: this.config.fetch,
|
|
543
|
+
abortSignal: options.abortSignal
|
|
544
|
+
});
|
|
545
|
+
const choice = response.choices[0];
|
|
546
|
+
const content = [];
|
|
547
|
+
if (choice.text) {
|
|
548
|
+
content.push({
|
|
549
|
+
type: "text",
|
|
550
|
+
text: choice.text
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
content,
|
|
555
|
+
finishReason: this.mapFinishReason(choice.finish_reason),
|
|
556
|
+
usage: {
|
|
557
|
+
inputTokens: {
|
|
558
|
+
total: response.usage?.prompt_tokens ?? 0,
|
|
559
|
+
noCache: void 0,
|
|
560
|
+
cacheRead: void 0,
|
|
561
|
+
cacheWrite: void 0
|
|
562
|
+
},
|
|
563
|
+
outputTokens: {
|
|
564
|
+
total: response.usage?.completion_tokens ?? 0,
|
|
565
|
+
text: void 0,
|
|
566
|
+
reasoning: void 0
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
warnings: [],
|
|
570
|
+
request: { body }
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
async doStream(options) {
|
|
574
|
+
const body = this.buildRequestBody(options, true);
|
|
575
|
+
const { value: response } = await postJsonToApi2({
|
|
576
|
+
url: `${this.config.baseURL}/completions`,
|
|
577
|
+
headers: this.config.headers(),
|
|
578
|
+
body,
|
|
579
|
+
failedResponseHandler: apertisFailedResponseHandler,
|
|
580
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
581
|
+
openAICompletionChunkSchema
|
|
582
|
+
),
|
|
583
|
+
fetch: this.config.fetch,
|
|
584
|
+
abortSignal: options.abortSignal
|
|
585
|
+
});
|
|
586
|
+
let textId = null;
|
|
587
|
+
const transformStream = new TransformStream({
|
|
588
|
+
transform(parseResult, controller) {
|
|
589
|
+
if (!parseResult.success) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const chunk = parseResult.value;
|
|
593
|
+
const choice = chunk.choices[0];
|
|
594
|
+
if (!choice) return;
|
|
595
|
+
if (choice.text) {
|
|
596
|
+
if (!textId) {
|
|
597
|
+
textId = generateId2();
|
|
598
|
+
controller.enqueue({
|
|
599
|
+
type: "text-start",
|
|
600
|
+
id: textId
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
controller.enqueue({
|
|
604
|
+
type: "text-delta",
|
|
605
|
+
id: textId,
|
|
606
|
+
delta: choice.text
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (choice.finish_reason) {
|
|
610
|
+
if (textId) {
|
|
611
|
+
controller.enqueue({
|
|
612
|
+
type: "text-end",
|
|
613
|
+
id: textId
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
controller.enqueue({
|
|
617
|
+
type: "finish",
|
|
618
|
+
finishReason: {
|
|
619
|
+
unified: choice.finish_reason === "stop" ? "stop" : choice.finish_reason === "length" ? "length" : "other",
|
|
620
|
+
raw: choice.finish_reason ?? void 0
|
|
621
|
+
},
|
|
622
|
+
usage: {
|
|
623
|
+
inputTokens: {
|
|
624
|
+
total: chunk.usage?.prompt_tokens ?? 0,
|
|
625
|
+
noCache: void 0,
|
|
626
|
+
cacheRead: void 0,
|
|
627
|
+
cacheWrite: void 0
|
|
628
|
+
},
|
|
629
|
+
outputTokens: {
|
|
630
|
+
total: chunk.usage?.completion_tokens ?? 0,
|
|
631
|
+
text: void 0,
|
|
632
|
+
reasoning: void 0
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
flush(controller) {
|
|
639
|
+
if (textId) {
|
|
640
|
+
controller.enqueue({
|
|
641
|
+
type: "text-end",
|
|
642
|
+
id: textId
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
return {
|
|
648
|
+
stream: response.pipeThrough(transformStream),
|
|
649
|
+
request: { body }
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
buildRequestBody(options, stream) {
|
|
653
|
+
const prompt = this.convertPromptToText(options.prompt);
|
|
654
|
+
const body = {
|
|
655
|
+
model: this.modelId,
|
|
656
|
+
prompt,
|
|
657
|
+
stream
|
|
658
|
+
};
|
|
659
|
+
if (stream) body.stream_options = { include_usage: true };
|
|
660
|
+
if (options.maxOutputTokens !== void 0)
|
|
661
|
+
body.max_tokens = options.maxOutputTokens;
|
|
662
|
+
if (options.temperature !== void 0)
|
|
663
|
+
body.temperature = options.temperature;
|
|
664
|
+
if (options.topP !== void 0) body.top_p = options.topP;
|
|
665
|
+
if (options.frequencyPenalty !== void 0)
|
|
666
|
+
body.frequency_penalty = options.frequencyPenalty;
|
|
667
|
+
if (options.presencePenalty !== void 0)
|
|
668
|
+
body.presence_penalty = options.presencePenalty;
|
|
669
|
+
if (options.stopSequences !== void 0) body.stop = options.stopSequences;
|
|
670
|
+
if (options.seed !== void 0) body.seed = options.seed;
|
|
671
|
+
if (this.settings.echo !== void 0) body.echo = this.settings.echo;
|
|
672
|
+
if (this.settings.logprobs !== void 0)
|
|
673
|
+
body.logprobs = this.settings.logprobs;
|
|
674
|
+
if (this.settings.suffix !== void 0) body.suffix = this.settings.suffix;
|
|
675
|
+
if (this.settings.user !== void 0) body.user = this.settings.user;
|
|
676
|
+
return body;
|
|
677
|
+
}
|
|
678
|
+
convertPromptToText(prompt) {
|
|
679
|
+
const parts = [];
|
|
680
|
+
for (const message of prompt) {
|
|
681
|
+
if (message.role === "system") {
|
|
682
|
+
parts.push(message.content);
|
|
683
|
+
} else if (message.role === "user") {
|
|
684
|
+
for (const part of message.content) {
|
|
685
|
+
if (part.type === "text") {
|
|
686
|
+
parts.push(part.text);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
} else if (message.role === "assistant") {
|
|
690
|
+
for (const part of message.content) {
|
|
691
|
+
if (part.type === "text") {
|
|
692
|
+
parts.push(part.text);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return parts.join("\n\n");
|
|
698
|
+
}
|
|
699
|
+
mapFinishReason(finishReason) {
|
|
700
|
+
const raw = finishReason ?? void 0;
|
|
701
|
+
switch (finishReason) {
|
|
702
|
+
case "stop":
|
|
703
|
+
return { unified: "stop", raw };
|
|
704
|
+
case "length":
|
|
705
|
+
return { unified: "length", raw };
|
|
706
|
+
default:
|
|
707
|
+
return { unified: "other", raw };
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/apertis-embedding-model.ts
|
|
713
|
+
import {
|
|
714
|
+
createJsonResponseHandler as createJsonResponseHandler3,
|
|
715
|
+
postJsonToApi as postJsonToApi3
|
|
716
|
+
} from "@ai-sdk/provider-utils";
|
|
717
|
+
|
|
718
|
+
// src/schemas/embedding-response.ts
|
|
719
|
+
import { z as z4 } from "zod";
|
|
720
|
+
var openAIEmbeddingResponseSchema = z4.object({
|
|
721
|
+
object: z4.literal("list"),
|
|
722
|
+
data: z4.array(
|
|
723
|
+
z4.object({
|
|
724
|
+
object: z4.literal("embedding"),
|
|
725
|
+
embedding: z4.array(z4.number()),
|
|
726
|
+
index: z4.number()
|
|
727
|
+
})
|
|
728
|
+
),
|
|
729
|
+
model: z4.string(),
|
|
730
|
+
usage: z4.object({
|
|
731
|
+
prompt_tokens: z4.number(),
|
|
732
|
+
total_tokens: z4.number()
|
|
733
|
+
}).optional()
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
// src/apertis-embedding-model.ts
|
|
737
|
+
var ApertisEmbeddingModel = class {
|
|
738
|
+
constructor(modelId, settings, config) {
|
|
739
|
+
this.modelId = modelId;
|
|
740
|
+
this.settings = settings;
|
|
741
|
+
this.config = config;
|
|
742
|
+
this.maxEmbeddingsPerCall = settings.maxEmbeddingsPerCall ?? 2048;
|
|
743
|
+
this.supportsParallelCalls = settings.supportsParallelCalls ?? true;
|
|
744
|
+
}
|
|
745
|
+
specificationVersion = "v3";
|
|
746
|
+
maxEmbeddingsPerCall;
|
|
747
|
+
supportsParallelCalls;
|
|
748
|
+
get provider() {
|
|
749
|
+
return this.config.provider;
|
|
750
|
+
}
|
|
751
|
+
async doEmbed(options) {
|
|
752
|
+
const body = {
|
|
753
|
+
model: this.modelId,
|
|
754
|
+
input: options.values,
|
|
755
|
+
encoding_format: "float"
|
|
756
|
+
};
|
|
757
|
+
if (this.settings.dimensions !== void 0) {
|
|
758
|
+
body.dimensions = this.settings.dimensions;
|
|
759
|
+
}
|
|
760
|
+
if (this.settings.user !== void 0) {
|
|
761
|
+
body.user = this.settings.user;
|
|
762
|
+
}
|
|
763
|
+
const { value: response } = await postJsonToApi3({
|
|
764
|
+
url: `${this.config.baseURL}/embeddings`,
|
|
765
|
+
headers: this.config.headers(),
|
|
766
|
+
body,
|
|
767
|
+
failedResponseHandler: apertisFailedResponseHandler,
|
|
768
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
769
|
+
openAIEmbeddingResponseSchema
|
|
770
|
+
),
|
|
771
|
+
fetch: this.config.fetch,
|
|
772
|
+
abortSignal: options.abortSignal
|
|
773
|
+
});
|
|
774
|
+
return {
|
|
775
|
+
embeddings: response.data.map((item) => item.embedding),
|
|
776
|
+
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
777
|
+
warnings: []
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
461
782
|
// src/apertis-provider.ts
|
|
462
783
|
function createApertis(options = {}) {
|
|
463
784
|
const baseURL = withoutTrailingSlash(options.baseURL) ?? "https://api.apertis.ai/v1";
|
|
@@ -476,11 +797,30 @@ function createApertis(options = {}) {
|
|
|
476
797
|
headers: getHeaders,
|
|
477
798
|
fetch: options.fetch
|
|
478
799
|
});
|
|
800
|
+
const createCompletionModel = (modelId, settings = {}) => new ApertisCompletionLanguageModel(modelId, settings, {
|
|
801
|
+
provider: "apertis.completion",
|
|
802
|
+
baseURL,
|
|
803
|
+
headers: getHeaders,
|
|
804
|
+
fetch: options.fetch
|
|
805
|
+
});
|
|
806
|
+
const createEmbeddingModel = (modelId, settings = {}) => new ApertisEmbeddingModel(modelId, settings, {
|
|
807
|
+
provider: "apertis.embedding",
|
|
808
|
+
baseURL,
|
|
809
|
+
headers: getHeaders,
|
|
810
|
+
fetch: options.fetch
|
|
811
|
+
});
|
|
479
812
|
const provider = Object.assign(
|
|
480
813
|
(modelId, settings) => createChatModel(modelId, settings),
|
|
481
814
|
{
|
|
815
|
+
specificationVersion: "v3",
|
|
482
816
|
chat: createChatModel,
|
|
483
|
-
languageModel: createChatModel
|
|
817
|
+
languageModel: (modelId) => createChatModel(modelId),
|
|
818
|
+
completion: createCompletionModel,
|
|
819
|
+
embeddingModel: (modelId) => createEmbeddingModel(modelId),
|
|
820
|
+
textEmbeddingModel: createEmbeddingModel,
|
|
821
|
+
imageModel: () => {
|
|
822
|
+
throw new Error("Image models are not supported by Apertis");
|
|
823
|
+
}
|
|
484
824
|
}
|
|
485
825
|
);
|
|
486
826
|
return provider;
|