@ai-sdk/openai-compatible 0.1.0 → 0.1.2
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/CHANGELOG.md +20 -0
- package/dist/index.d.mts +133 -90
- package/dist/index.d.ts +133 -90
- package/dist/index.js +42 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -19
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +44 -1
- package/internal/dist/index.d.ts +44 -1
- package/package.json +3 -3
package/internal/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { JSONValue, LanguageModelV1Prompt, LanguageModelV1FinishReason, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider';
|
1
|
+
import { JSONValue, LanguageModelV1Prompt, LanguageModelV1FinishReason, LanguageModelV1ProviderMetadata, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider';
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
3
3
|
import { ZodSchema } from 'zod';
|
4
4
|
|
@@ -63,6 +63,48 @@ type ProviderErrorStructure<T> = {
|
|
63
63
|
isRetryable?: (response: Response, error?: T) => boolean;
|
64
64
|
};
|
65
65
|
|
66
|
+
/**
|
67
|
+
Extracts provider-specific metadata from API responses.
|
68
|
+
Used to standardize metadata handling across different LLM providers while allowing
|
69
|
+
provider-specific metadata to be captured.
|
70
|
+
*/
|
71
|
+
type MetadataExtractor = {
|
72
|
+
/**
|
73
|
+
* Extracts provider metadata from a complete, non-streaming response.
|
74
|
+
*
|
75
|
+
* @param parsedBody - The parsed response JSON body from the provider's API.
|
76
|
+
*
|
77
|
+
* @returns Provider-specific metadata or undefined if no metadata is available.
|
78
|
+
* The metadata should be under a key indicating the provider id.
|
79
|
+
*/
|
80
|
+
extractMetadata: ({ parsedBody, }: {
|
81
|
+
parsedBody: unknown;
|
82
|
+
}) => LanguageModelV1ProviderMetadata | undefined;
|
83
|
+
/**
|
84
|
+
* Creates a streaming metadata processor that can accumulate and process chunks
|
85
|
+
* of a streaming response. Used to build metadata progressively during streaming.
|
86
|
+
*
|
87
|
+
* @returns A new StreamingMetadataProcessor instance
|
88
|
+
*/
|
89
|
+
createStreamExtractor: () => {
|
90
|
+
/**
|
91
|
+
* Process an individual chunk from the stream. Called for each chunk in the response stream
|
92
|
+
* to accumulate metadata throughout the streaming process.
|
93
|
+
*
|
94
|
+
* @param parsedChunk - The parsed JSON response chunk from the provider's API
|
95
|
+
*/
|
96
|
+
processChunk(parsedChunk: unknown): void;
|
97
|
+
/**
|
98
|
+
* Builds the metadata object after all chunks have been processed.
|
99
|
+
* Called at the end of the stream to generate the complete provider metadata.
|
100
|
+
*
|
101
|
+
* @returns Provider-specific metadata or undefined if no metadata is available.
|
102
|
+
* The metadata should be under a key indicating the provider id.
|
103
|
+
*/
|
104
|
+
buildMetadata(): LanguageModelV1ProviderMetadata | undefined;
|
105
|
+
};
|
106
|
+
};
|
107
|
+
|
66
108
|
type OpenAICompatibleChatConfig = {
|
67
109
|
provider: string;
|
68
110
|
headers: () => Record<string, string | undefined>;
|
@@ -72,6 +114,7 @@ type OpenAICompatibleChatConfig = {
|
|
72
114
|
}) => string;
|
73
115
|
fetch?: FetchFunction;
|
74
116
|
errorStructure?: ProviderErrorStructure<any>;
|
117
|
+
metadataExtractor?: MetadataExtractor;
|
75
118
|
/**
|
76
119
|
Default object generation mode that should be used with this model when
|
77
120
|
no mode is specified. Should be the mode with the best results for this
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ai-sdk/openai-compatible",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.2",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"sideEffects": false,
|
6
6
|
"main": "./dist/index.js",
|
@@ -26,8 +26,8 @@
|
|
26
26
|
}
|
27
27
|
},
|
28
28
|
"dependencies": {
|
29
|
-
"@ai-sdk/provider": "1.0.
|
30
|
-
"@ai-sdk/provider-utils": "2.1.
|
29
|
+
"@ai-sdk/provider": "1.0.6",
|
30
|
+
"@ai-sdk/provider-utils": "2.1.2"
|
31
31
|
},
|
32
32
|
"devDependencies": {
|
33
33
|
"@types/node": "^18",
|