@sweetretry/ai-sdk-volcengine-adapter 0.1.3 → 0.1.4
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/dist/chat/convert-to-volcengine-chat-message.d.ts +2 -2
- package/dist/chat/convert-to-volcengine-chat-message.js +47 -47
- package/dist/chat/convert-to-volcengine-chat-message.js.map +1 -1
- package/dist/chat/convert-volcengine-chat-usage.d.ts +1 -1
- package/dist/chat/convert-volcengine-chat-usage.js.map +1 -1
- package/dist/chat/get-response-metadata.js.map +1 -1
- package/dist/chat/index.d.ts +2 -2
- package/dist/chat/index.js +1 -1
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/map-volcengine-finish-reason.d.ts +1 -1
- package/dist/chat/map-volcengine-finish-reason.js +10 -10
- package/dist/chat/map-volcengine-finish-reason.js.map +1 -1
- package/dist/chat/volcengine-chat-language-model.d.ts +2 -2
- package/dist/chat/volcengine-chat-language-model.js +53 -53
- package/dist/chat/volcengine-chat-language-model.js.map +1 -1
- package/dist/chat/volcengine-chat-options.d.ts +1 -1
- package/dist/chat/volcengine-chat-options.js +20 -20
- package/dist/chat/volcengine-chat-options.js.map +1 -1
- package/dist/chat/volcengine-chat-prompt.js.map +1 -1
- package/dist/chat/volcengine-error.js +2 -2
- package/dist/chat/volcengine-error.js.map +1 -1
- package/dist/image/index.d.ts +1 -1
- package/dist/image/index.js +1 -1
- package/dist/image/index.js.map +1 -1
- package/dist/image/volcengine-image-api.d.ts +1 -1
- package/dist/image/volcengine-image-api.js +1 -1
- package/dist/image/volcengine-image-api.js.map +1 -1
- package/dist/image/volcengine-image-model.d.ts +3 -3
- package/dist/image/volcengine-image-model.js +13 -13
- package/dist/image/volcengine-image-model.js.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/tool/index.d.ts +1 -1
- package/dist/tool/index.js +1 -1
- package/dist/tool/index.js.map +1 -1
- package/dist/tool/web-search.d.ts +1 -1
- package/dist/tool/web-search.js +4 -4
- package/dist/tool/web-search.js.map +1 -1
- package/dist/version.js.map +1 -1
- package/dist/volcengine-provider.d.ts +5 -5
- package/dist/volcengine-provider.js +13 -13
- package/dist/volcengine-provider.js.map +1 -1
- package/dist/volcengine-tools.js +1 -1
- package/dist/volcengine-tools.js.map +1 -1
- package/package.json +8 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { combineHeaders, createJsonResponseHandler, postJsonToApi } from
|
|
2
|
-
import { volcengineFailedResponseHandler } from
|
|
3
|
-
import { volcengineImageResponseSchema } from
|
|
1
|
+
import { combineHeaders, createJsonResponseHandler, postJsonToApi } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { volcengineFailedResponseHandler } from '../chat/volcengine-error';
|
|
3
|
+
import { volcengineImageResponseSchema } from './volcengine-image-api';
|
|
4
4
|
export class VolcengineImageModel {
|
|
5
5
|
modelId;
|
|
6
6
|
config;
|
|
7
|
-
specificationVersion =
|
|
7
|
+
specificationVersion = 'v3';
|
|
8
8
|
get maxImagesPerCall() {
|
|
9
9
|
return 1;
|
|
10
10
|
}
|
|
@@ -20,22 +20,22 @@ export class VolcengineImageModel {
|
|
|
20
20
|
// Handle unsupported options
|
|
21
21
|
if (aspectRatio != null) {
|
|
22
22
|
warnings.push({
|
|
23
|
-
type:
|
|
24
|
-
feature:
|
|
23
|
+
type: 'unsupported',
|
|
24
|
+
feature: 'aspectRatio'
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
if (seed != null) {
|
|
28
28
|
warnings.push({
|
|
29
|
-
type:
|
|
30
|
-
feature:
|
|
29
|
+
type: 'unsupported',
|
|
30
|
+
feature: 'seed'
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
// Build request body
|
|
34
34
|
const body = {
|
|
35
35
|
model: this.modelId,
|
|
36
36
|
prompt,
|
|
37
|
-
size: size ??
|
|
38
|
-
response_format:
|
|
37
|
+
size: size ?? '1024x1024',
|
|
38
|
+
response_format: 'b64_json',
|
|
39
39
|
...providerOptions.volcengine ?? {}
|
|
40
40
|
};
|
|
41
41
|
// Handle reference images for image-to-image generation
|
|
@@ -64,7 +64,7 @@ export class VolcengineImageModel {
|
|
|
64
64
|
if (item.url) {
|
|
65
65
|
return item.url;
|
|
66
66
|
}
|
|
67
|
-
throw new Error(
|
|
67
|
+
throw new Error('No image data in response');
|
|
68
68
|
});
|
|
69
69
|
return {
|
|
70
70
|
images,
|
|
@@ -82,11 +82,11 @@ export class VolcengineImageModel {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
convertFileToDataUrl(file) {
|
|
85
|
-
if (file.type ===
|
|
85
|
+
if (file.type === 'url') {
|
|
86
86
|
return file.url;
|
|
87
87
|
}
|
|
88
88
|
// file.type === "file"
|
|
89
|
-
if (typeof file.data ===
|
|
89
|
+
if (typeof file.data === 'string') {
|
|
90
90
|
// base64 string - convert to data URL
|
|
91
91
|
return `data:${file.mediaType};base64,${file.data}`;
|
|
92
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/image/volcengine-image-model.ts"],"sourcesContent":["import {\n ImageModelV3,\n ImageModelV3CallOptions,\n ImageModelV3File,\n ImageModelV3ProviderMetadata,\n ImageModelV3Usage,\n SharedV3Warning,\n} from
|
|
1
|
+
{"version":3,"sources":["../../src/image/volcengine-image-model.ts"],"sourcesContent":["import {\n ImageModelV3,\n ImageModelV3CallOptions,\n ImageModelV3File,\n ImageModelV3ProviderMetadata,\n ImageModelV3Usage,\n SharedV3Warning,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonResponseHandler,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { volcengineFailedResponseHandler } from '../chat/volcengine-error';\nimport { volcengineImageResponseSchema } from './volcengine-image-api';\n\nexport type VolcengineImageModelId =\n | 'doubao-seedream-4-5-251128'\n | 'doubao-seedream-4-0-250828'\n | (string & {});\n\nexport interface VolcengineImageConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n}\n\nexport class VolcengineImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3' as const;\n\n get maxImagesPerCall(): number {\n return 1;\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: VolcengineImageModelId,\n private readonly config: VolcengineImageConfig,\n ) {}\n\n async doGenerate({\n prompt,\n files,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: ImageModelV3CallOptions): Promise<{\n images: Array<string> | Array<Uint8Array>;\n warnings: Array<SharedV3Warning>;\n providerMetadata?: ImageModelV3ProviderMetadata;\n response: {\n timestamp: Date;\n modelId: string;\n headers: Record<string, string> | undefined;\n };\n usage?: ImageModelV3Usage;\n }> {\n const warnings: SharedV3Warning[] = [];\n\n // Handle unsupported options\n if (aspectRatio != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'aspectRatio',\n });\n }\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n });\n }\n\n // Build request body\n const body: Record<string, unknown> = {\n model: this.modelId,\n prompt,\n size: size ?? '1024x1024',\n response_format: 'b64_json',\n ...(providerOptions.volcengine ?? {}),\n };\n\n // Handle reference images for image-to-image generation\n if (files && files.length > 0) {\n const imageUrls = files.map(file => this.convertFileToDataUrl(file));\n\n if (imageUrls.length === 1) {\n body.image = imageUrls[0];\n } else {\n body.image = imageUrls;\n }\n }\n\n const { value: response, responseHeaders } = await postJsonToApi({\n url: `${this.config.baseURL}/images/generations`,\n headers: combineHeaders(this.config.headers(), headers),\n body,\n failedResponseHandler: volcengineFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n volcengineImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n // Extract images from response\n const images: string[] = response.data.map(item => {\n if (item.b64_json) {\n return item.b64_json;\n }\n if (item.url) {\n return item.url;\n }\n throw new Error('No image data in response');\n });\n\n return {\n images,\n warnings,\n response: {\n timestamp: new Date(),\n modelId: response.model ?? this.modelId,\n headers: responseHeaders,\n },\n usage: response.usage\n ? {\n inputTokens: undefined,\n outputTokens: response.usage.output_tokens,\n totalTokens: response.usage.total_tokens,\n }\n : undefined,\n };\n }\n\n private convertFileToDataUrl(file: ImageModelV3File): string {\n if (file.type === 'url') {\n return file.url;\n }\n\n // file.type === \"file\"\n if (typeof file.data === 'string') {\n // base64 string - convert to data URL\n return `data:${file.mediaType};base64,${file.data}`;\n }\n\n // Uint8Array - convert to base64 data URL\n const base64 = btoa(String.fromCharCode(...file.data));\n return `data:${file.mediaType};base64,${base64}`;\n }\n}\n"],"names":["combineHeaders","createJsonResponseHandler","postJsonToApi","volcengineFailedResponseHandler","volcengineImageResponseSchema","VolcengineImageModel","specificationVersion","maxImagesPerCall","provider","config","modelId","doGenerate","prompt","files","size","aspectRatio","seed","providerOptions","headers","abortSignal","warnings","push","type","feature","body","model","response_format","volcengine","length","imageUrls","map","file","convertFileToDataUrl","image","value","response","responseHeaders","url","baseURL","failedResponseHandler","successfulResponseHandler","fetch","images","data","item","b64_json","Error","timestamp","Date","usage","inputTokens","undefined","outputTokens","output_tokens","totalTokens","total_tokens","mediaType","base64","btoa","String","fromCharCode"],"mappings":"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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export { createVolcengine, volcengine } from
|
|
2
|
-
export type { VolcengineProvider, VolcengineProviderSettings } from
|
|
1
|
+
export { createVolcengine, volcengine } from './volcengine-provider';
|
|
2
|
+
export type { VolcengineProvider, VolcengineProviderSettings, } from './volcengine-provider';
|
|
3
3
|
export type { VolcengineChatOptions } from './chat';
|
|
4
|
-
export type { VolcengineImageModelId
|
|
5
|
-
export { volcengineTools } from './volcengine-tools';
|
|
6
|
-
export { convertVolcengineUsage } from './chat/convert-volcengine-chat-usage';
|
|
7
|
-
export type { VolcengineUsage } from './chat/convert-volcengine-chat-usage';
|
|
4
|
+
export type { VolcengineImageModelId } from './image';
|
|
8
5
|
export { VERSION } from './version';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { createVolcengine, volcengine } from
|
|
2
|
-
export { volcengineTools } from './volcengine-tools';
|
|
3
|
-
export { convertVolcengineUsage } from './chat/convert-volcengine-chat-usage';
|
|
1
|
+
export { createVolcengine, volcengine } from './volcengine-provider';
|
|
4
2
|
export { VERSION } from './version';
|
|
5
3
|
|
|
6
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createVolcengine, volcengine } from
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createVolcengine, volcengine } from './volcengine-provider';\nexport type {\n VolcengineProvider,\n VolcengineProviderSettings,\n} from './volcengine-provider';\nexport type { VolcengineChatOptions } from './chat';\nexport type { VolcengineImageModelId } from './image';\nexport { VERSION } from './version';\n"],"names":["createVolcengine","volcengine","VERSION"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAQ,wBAAwB;AAOrE,SAASC,OAAO,QAAQ,YAAY"}
|
package/dist/tool/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { webSearch } from
|
|
1
|
+
export { webSearch } from './web-search';
|
package/dist/tool/index.js
CHANGED
package/dist/tool/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tool/index.ts"],"sourcesContent":["export { webSearch } from
|
|
1
|
+
{"version":3,"sources":["../../src/tool/index.ts"],"sourcesContent":["export { webSearch } from './web-search';\n"],"names":["webSearch"],"mappings":"AAAA,SAASA,SAAS,QAAQ,eAAe"}
|
package/dist/tool/web-search.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createProviderToolFactoryWithOutputSchema, lazySchema, zodSchema } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import { createProviderToolFactoryWithOutputSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
3
|
const userLocationSchema = z.object({
|
|
4
4
|
type: z.enum([
|
|
5
|
-
|
|
5
|
+
'approximate'
|
|
6
6
|
]).optional(),
|
|
7
7
|
country: z.string().optional(),
|
|
8
8
|
region: z.string().optional(),
|
|
@@ -20,7 +20,7 @@ export const webSearchOutputSchema = lazySchema(()=>zodSchema(z.object({
|
|
|
20
20
|
result: z.string()
|
|
21
21
|
})));
|
|
22
22
|
const webSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
23
|
-
id:
|
|
23
|
+
id: 'volcengine.web_search',
|
|
24
24
|
inputSchema: webSearchInputSchema,
|
|
25
25
|
outputSchema: webSearchOutputSchema
|
|
26
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tool/web-search.ts"],"sourcesContent":["import {\n createProviderToolFactoryWithOutputSchema,\n lazySchema,\n zodSchema,\n} from
|
|
1
|
+
{"version":3,"sources":["../../src/tool/web-search.ts"],"sourcesContent":["import {\n createProviderToolFactoryWithOutputSchema,\n lazySchema,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nconst userLocationSchema = z\n .object({\n type: z.enum(['approximate']).optional(),\n country: z.string().optional(),\n region: z.string().optional(),\n city: z.string().optional(),\n })\n .strict();\n\nexport const webSearchArgsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n maxKeyword: z.number().int().min(1).max(50).optional(),\n limit: z.number().int().min(1).max(50).optional(),\n maxToolCalls: z.number().int().min(1).max(10).optional(),\n sources: z.array(z.string()).optional(),\n userLocation: userLocationSchema.optional(),\n })\n .strict(),\n ),\n);\n\nconst webSearchInputSchema = lazySchema(() => zodSchema(z.object({})));\n\nexport const webSearchOutputSchema = lazySchema(() =>\n zodSchema(z.object({ result: z.string() })),\n);\n\n/**\n * Web search input options.\n */\nexport interface WebSearchArgs {\n /**\n * Maximum number of keywords to extract from the query.\n */\n maxKeyword?: number;\n\n /**\n * Maximum number of search results to return.\n * @default 10\n */\n limit?: number;\n\n /**\n * Maximum number of tool calls.\n * @default 3\n */\n maxToolCalls?: number;\n\n /**\n * Sources to search from (e.g., \"douyin\", \"toutiao\").\n */\n sources?: string[];\n\n /**\n * User location for optimizing search results.\n */\n userLocation?: {\n /**\n * Location type.\n * @default \"approximate\"\n */\n type?: 'approximate';\n /**\n * Country name (e.g., \"中国\").\n */\n country?: string;\n /**\n * Region/Province name (e.g., \"浙江\").\n */\n region?: string;\n /**\n * City name (e.g., \"杭州\").\n */\n city?: string;\n };\n}\n\nconst webSearchToolFactory = createProviderToolFactoryWithOutputSchema<\n {},\n {\n /**\n * The search result.\n */\n result: string;\n },\n WebSearchArgs\n>({\n id: 'volcengine.web_search',\n inputSchema: webSearchInputSchema,\n outputSchema: webSearchOutputSchema,\n});\n\n/**\n * Volcengine Web Search Tool\n *\n * Enables the model to perform web searches to retrieve up-to-date information.\n *\n * @see https://www.volcengine.com/docs/82379/1756990\n *\n * @example\n * ```ts\n * volcengineTools.webSearch({\n * maxKeyword: 5,\n * limit: 20,\n * sources: [\"douyin\", \"toutiao\"],\n * userLocation: {\n * type: \"approximate\",\n * country: \"中国\",\n * region: \"浙江\",\n * city: \"杭州\",\n * },\n * })\n * ```\n */\nexport const webSearch = (args: WebSearchArgs = {}) => {\n return webSearchToolFactory(args);\n};\n"],"names":["createProviderToolFactoryWithOutputSchema","lazySchema","zodSchema","z","userLocationSchema","object","type","enum","optional","country","string","region","city","strict","webSearchArgsSchema","maxKeyword","number","int","min","max","limit","maxToolCalls","sources","array","userLocation","webSearchInputSchema","webSearchOutputSchema","result","webSearchToolFactory","id","inputSchema","outputSchema","webSearch","args"],"mappings":"AAAA,SACEA,yCAAyC,EACzCC,UAAU,EACVC,SAAS,QACJ,yBAAyB;AAChC,SAASC,CAAC,QAAQ,SAAS;AAE3B,MAAMC,qBAAqBD,EACxBE,MAAM,CAAC;IACNC,MAAMH,EAAEI,IAAI,CAAC;QAAC;KAAc,EAAEC,QAAQ;IACtCC,SAASN,EAAEO,MAAM,GAAGF,QAAQ;IAC5BG,QAAQR,EAAEO,MAAM,GAAGF,QAAQ;IAC3BI,MAAMT,EAAEO,MAAM,GAAGF,QAAQ;AAC3B,GACCK,MAAM;AAET,OAAO,MAAMC,sBAAsBb,WAAW,IAC5CC,UACEC,EACGE,MAAM,CAAC;QACNU,YAAYZ,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QACpDY,OAAOjB,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QAC/Ca,cAAclB,EAAEa,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIX,QAAQ;QACtDc,SAASnB,EAAEoB,KAAK,CAACpB,EAAEO,MAAM,IAAIF,QAAQ;QACrCgB,cAAcpB,mBAAmBI,QAAQ;IAC3C,GACCK,MAAM,KAEX;AAEF,MAAMY,uBAAuBxB,WAAW,IAAMC,UAAUC,EAAEE,MAAM,CAAC,CAAC;AAElE,OAAO,MAAMqB,wBAAwBzB,WAAW,IAC9CC,UAAUC,EAAEE,MAAM,CAAC;QAAEsB,QAAQxB,EAAEO,MAAM;IAAG,KACxC;AAoDF,MAAMkB,uBAAuB5B,0CAS3B;IACA6B,IAAI;IACJC,aAAaL;IACbM,cAAcL;AAChB;AAEA;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,MAAMM,YAAY,CAACC,OAAsB,CAAC,CAAC;IAChD,OAAOL,qBAAqBK;AAC9B,EAAE"}
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"names":["VERSION","__PACKAGE_VERSION__"],"mappings":"AAAA,yDAAyD;AAEzD,OAAO,MAAMA,UACX,OAAOC,wBAAwB,cAC3BA,sBACA,aAAa"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ImageModelV3, LanguageModelV3, ProviderV3 } from
|
|
2
|
-
import { FetchFunction } from
|
|
3
|
-
import { VolcengineModelId } from
|
|
4
|
-
import { VolcengineImageModelId } from
|
|
5
|
-
import { volcengineTools } from
|
|
1
|
+
import { ImageModelV3, LanguageModelV3, ProviderV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { VolcengineModelId } from './chat';
|
|
4
|
+
import { VolcengineImageModelId } from './image';
|
|
5
|
+
import { volcengineTools } from './volcengine-tools';
|
|
6
6
|
export interface VolcengineProviderSettings {
|
|
7
7
|
/**
|
|
8
8
|
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { NoSuchModelError } from
|
|
2
|
-
import { loadApiKey, withUserAgentSuffix, withoutTrailingSlash } from
|
|
3
|
-
import { VERSION } from
|
|
4
|
-
import { VolcengineChatLanguageModel } from
|
|
5
|
-
import { VolcengineImageModel } from
|
|
6
|
-
import { volcengineTools } from
|
|
1
|
+
import { NoSuchModelError } from '@ai-sdk/provider';
|
|
2
|
+
import { loadApiKey, withUserAgentSuffix, withoutTrailingSlash } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { VERSION } from './version';
|
|
4
|
+
import { VolcengineChatLanguageModel } from './chat';
|
|
5
|
+
import { VolcengineImageModel } from './image';
|
|
6
|
+
import { volcengineTools } from './volcengine-tools';
|
|
7
7
|
/**
|
|
8
8
|
Create a Volcengine provider instance.
|
|
9
9
|
*/ export function createVolcengine(options = {}) {
|
|
10
|
-
const baseURL = withoutTrailingSlash(options.baseURL) ??
|
|
10
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? 'https://ark.cn-beijing.volces.com/api/v3';
|
|
11
11
|
const getHeaders = ()=>withUserAgentSuffix({
|
|
12
12
|
Authorization: `Bearer ${loadApiKey({
|
|
13
13
|
apiKey: options.apiKey,
|
|
14
|
-
environmentVariableName:
|
|
15
|
-
description:
|
|
14
|
+
environmentVariableName: 'ARK_API_KEY',
|
|
15
|
+
description: 'Volcengine'
|
|
16
16
|
})}`,
|
|
17
17
|
...options.headers
|
|
18
18
|
}, `ai-sdk/volcengine/${VERSION}`);
|
|
19
19
|
const createChatModel = (modelId)=>new VolcengineChatLanguageModel(modelId, {
|
|
20
|
-
provider:
|
|
20
|
+
provider: 'volcengine.chat',
|
|
21
21
|
baseURL,
|
|
22
22
|
headers: getHeaders,
|
|
23
23
|
fetch: options.fetch,
|
|
24
24
|
generateId: options.generateId
|
|
25
25
|
});
|
|
26
26
|
const createImageModel = (modelId)=>new VolcengineImageModel(modelId, {
|
|
27
|
-
provider:
|
|
27
|
+
provider: 'volcengine.image',
|
|
28
28
|
baseURL,
|
|
29
29
|
headers: getHeaders,
|
|
30
30
|
fetch: options.fetch
|
|
@@ -32,14 +32,14 @@ Create a Volcengine provider instance.
|
|
|
32
32
|
const provider = function(modelId) {
|
|
33
33
|
return createChatModel(modelId);
|
|
34
34
|
};
|
|
35
|
-
provider.specificationVersion =
|
|
35
|
+
provider.specificationVersion = 'v3';
|
|
36
36
|
provider.languageModel = createChatModel;
|
|
37
37
|
provider.chat = createChatModel;
|
|
38
38
|
provider.imageModel = createImageModel;
|
|
39
39
|
provider.embeddingModel = (modelId)=>{
|
|
40
40
|
throw new NoSuchModelError({
|
|
41
41
|
modelId,
|
|
42
|
-
modelType:
|
|
42
|
+
modelType: 'embeddingModel'
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
provider.tools = volcengineTools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/volcengine-provider.ts"],"sourcesContent":["import {\n ImageModelV3,\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3
|
|
1
|
+
{"version":3,"sources":["../src/volcengine-provider.ts"],"sourcesContent":["import {\n ImageModelV3,\n LanguageModelV3,\n NoSuchModelError,\n ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withUserAgentSuffix,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport { VERSION } from './version';\nimport { VolcengineChatLanguageModel, VolcengineModelId } from './chat';\nimport { VolcengineImageModel, VolcengineImageModelId } from './image';\nimport { volcengineTools } from './volcengine-tools';\n\nexport interface VolcengineProviderSettings {\n /**\nUse a different URL prefix for API calls, e.g. to use proxy servers.\nThe default prefix is `https://ark.cn-beijing.volces.com/api/v3`.\n */\n baseURL?: string;\n\n /**\nAPI key that is sent using the `Authorization` header.\nIt defaults to the `ARK_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n generateId?: () => string;\n}\n\nexport interface VolcengineProvider extends ProviderV3 {\n (modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for text generation using the Chat Completions API.\n*/\n languageModel(modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for text generation using the Chat Completions API.\n*/\n chat(modelId: VolcengineModelId): LanguageModelV3;\n\n /**\nCreates a model for image generation.\n*/\n imageModel(modelId: VolcengineImageModelId): ImageModelV3;\n\n /**\nCreates a model for text embeddings.\n*/\n embeddingModel(modelId: VolcengineModelId): never;\n\n /**\nVolcengine-specific tools.\n*/\n tools: typeof volcengineTools;\n}\n\n/**\nCreate a Volcengine provider instance.\n */\nexport function createVolcengine(\n options: VolcengineProviderSettings = {},\n): VolcengineProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n 'https://ark.cn-beijing.volces.com/api/v3';\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'ARK_API_KEY',\n description: 'Volcengine',\n })}`,\n ...options.headers,\n },\n `ai-sdk/volcengine/${VERSION}`,\n );\n\n const createChatModel = (modelId: string) =>\n new VolcengineChatLanguageModel(modelId, {\n provider: 'volcengine.chat',\n baseURL,\n headers: getHeaders,\n fetch: options.fetch,\n generateId: options.generateId,\n });\n\n const createImageModel = (modelId: string) =>\n new VolcengineImageModel(modelId, {\n provider: 'volcengine.image',\n baseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function (modelId: VolcengineModelId) {\n return createChatModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n provider.imageModel = createImageModel;\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.tools = volcengineTools;\n\n return provider as VolcengineProvider;\n}\n\n/**\nDefault Volcengine provider instance.\n */\nexport const volcengine = createVolcengine();\n"],"names":["NoSuchModelError","loadApiKey","withUserAgentSuffix","withoutTrailingSlash","VERSION","VolcengineChatLanguageModel","VolcengineImageModel","volcengineTools","createVolcengine","options","baseURL","getHeaders","Authorization","apiKey","environmentVariableName","description","headers","createChatModel","modelId","provider","fetch","generateId","createImageModel","specificationVersion","languageModel","chat","imageModel","embeddingModel","modelType","tools","volcengine"],"mappings":"AAAA,SAGEA,gBAAgB,QAEX,mBAAmB;AAC1B,SAEEC,UAAU,EACVC,mBAAmB,EACnBC,oBAAoB,QACf,yBAAyB;AAChC,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,2BAA2B,QAA2B,SAAS;AACxE,SAASC,oBAAoB,QAAgC,UAAU;AACvE,SAASC,eAAe,QAAQ,qBAAqB;AA0DrD;;CAEC,GACD,OAAO,SAASC,iBACdC,UAAsC,CAAC,CAAC;IAExC,MAAMC,UACJP,qBAAqBM,QAAQC,OAAO,KACpC;IAEF,MAAMC,aAAa,IACjBT,oBACE;YACEU,eAAe,CAAC,OAAO,EAAEX,WAAW;gBAClCY,QAAQJ,QAAQI,MAAM;gBACtBC,yBAAyB;gBACzBC,aAAa;YACf,IAAI;YACJ,GAAGN,QAAQO,OAAO;QACpB,GACA,CAAC,kBAAkB,EAAEZ,SAAS;IAGlC,MAAMa,kBAAkB,CAACC,UACvB,IAAIb,4BAA4Ba,SAAS;YACvCC,UAAU;YACVT;YACAM,SAASL;YACTS,OAAOX,QAAQW,KAAK;YACpBC,YAAYZ,QAAQY,UAAU;QAChC;IAEF,MAAMC,mBAAmB,CAACJ,UACxB,IAAIZ,qBAAqBY,SAAS;YAChCC,UAAU;YACVT;YACAM,SAASL;YACTS,OAAOX,QAAQW,KAAK;QACtB;IAEF,MAAMD,WAAW,SAAUD,OAA0B;QACnD,OAAOD,gBAAgBC;IACzB;IAEAC,SAASI,oBAAoB,GAAG;IAChCJ,SAASK,aAAa,GAAGP;IACzBE,SAASM,IAAI,GAAGR;IAChBE,SAASO,UAAU,GAAGJ;IACtBH,SAASQ,cAAc,GAAG,CAACT;QACzB,MAAM,IAAIlB,iBAAiB;YAAEkB;YAASU,WAAW;QAAiB;IACpE;IACAT,SAASU,KAAK,GAAGtB;IAEjB,OAAOY;AACT;AAEA;;CAEC,GACD,OAAO,MAAMW,aAAatB,mBAAmB"}
|
package/dist/volcengine-tools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/volcengine-tools.ts"],"sourcesContent":["import { webSearch } from
|
|
1
|
+
{"version":3,"sources":["../src/volcengine-tools.ts"],"sourcesContent":["import { webSearch } from './tool/web-search';\n\n/**\n * Volcengine provider tools.\n *\n * @example\n * ```ts\n * import { volcengine, volcengineTools } from \"ai-sdk-volcengine-adapter\";\n * import { generateText } from \"ai\";\n *\n * const result = await generateText({\n * model: volcengine(\"doubao-seed-1-8-251228\"),\n * tools: {\n * web_search: volcengineTools.webSearch(),\n * },\n * prompt: \"What is the weather in Hangzhou today?\",\n * });\n * ```\n */\nexport const volcengineTools = {\n /**\n * Web Search tool for retrieving up-to-date information from the internet.\n *\n * The tool must be named `web_search` in the tools object.\n *\n * @see https://www.volcengine.com/docs/82379/1756990\n *\n * @example\n * ```ts\n * volcengineTools.webSearch({\n * maxKeyword: 5,\n * limit: 20,\n * sources: [\"douyin\", \"toutiao\"],\n * userLocation: {\n * type: \"approximate\",\n * country: \"中国\",\n * region: \"浙江\",\n * city: \"杭州\",\n * },\n * })\n * ```\n */\n webSearch,\n};\n"],"names":["webSearch","volcengineTools"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAoB;AAE9C;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,kBAAkB;IAC7B;;;;;;;;;;;;;;;;;;;;;GAqBC,GACDD;AACF,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sweetretry/ai-sdk-volcengine-adapter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Volcengine adapter for AI SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SweetRetry <zimin.zhang2000@gmail.com>",
|
|
@@ -47,6 +47,13 @@
|
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
|
+
"prettier": {
|
|
51
|
+
"tabWidth": 2,
|
|
52
|
+
"useTabs": false,
|
|
53
|
+
"singleQuote": true,
|
|
54
|
+
"arrowParens": "avoid",
|
|
55
|
+
"trailingComma": "all"
|
|
56
|
+
},
|
|
50
57
|
"devDependencies": {
|
|
51
58
|
"@swc/cli": "^0.3.12",
|
|
52
59
|
"@swc/core": "^1.3.107",
|