From 656481247bac93d2544dd27b603bab66c7182ffa Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Tue, 24 Dec 2024 10:50:38 -0800 Subject: [PATCH] feat (provider/openai-compatible): Add'l exports for customization. (#4179) Co-authored-by: minpeter --- .changeset/orange-melons-brake.md | 5 +++++ .../01-custom-providers.mdx | 10 ++++++++++ packages/openai-compatible/package.json | 9 ++++++++- packages/openai-compatible/src/internal/index.ts | 4 ++++ packages/openai-compatible/tsup.config.ts | 7 +++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .changeset/orange-melons-brake.md create mode 100644 packages/openai-compatible/src/internal/index.ts diff --git a/.changeset/orange-melons-brake.md b/.changeset/orange-melons-brake.md new file mode 100644 index 000000000000..b26fdab25d6b --- /dev/null +++ b/.changeset/orange-melons-brake.md @@ -0,0 +1,5 @@ +--- +'@ai-sdk/openai-compatible': patch +--- + +feat (provider/openai-compatible): Add'l exports for customization. diff --git a/content/providers/02-openai-compatible-providers/01-custom-providers.mdx b/content/providers/02-openai-compatible-providers/01-custom-providers.mdx index 5a953c2408f2..a68c8de1a4ee 100644 --- a/content/providers/02-openai-compatible-providers/01-custom-providers.mdx +++ b/content/providers/02-openai-compatible-providers/01-custom-providers.mdx @@ -229,3 +229,13 @@ const { text } = await generateText({ ``` This structure provides a clean, type-safe implementation that leverages the OpenAI Compatible package while maintaining consistency with the usage of other AI SDK providers. + +### Internal API + +As you work on your provider you may need to use some of the internal API of the OpenAI Compatible package. You can import these from the `@ai-sdk/openai-compatible/internal` package, for example: + +```ts +import { convertToOpenAICompatibleChatMessages } from '@ai-sdk/openai-compatible/internal'; +``` + +You can see the latest available exports in the AI SDK [GitHub repository](https://github.com/vercel/ai/blob/main/packages/openai-compatible/src/internal/index.ts). diff --git a/packages/openai-compatible/package.json b/packages/openai-compatible/package.json index a813b02f9e0d..55e68c56b486 100644 --- a/packages/openai-compatible/package.json +++ b/packages/openai-compatible/package.json @@ -8,12 +8,13 @@ "types": "./dist/index.d.ts", "files": [ "dist/**/*", + "internal/dist/**/*", "CHANGELOG.md" ], "scripts": { "build": "tsup", "build:watch": "tsup --watch", - "clean": "rm -rf dist", + "clean": "rm -rf dist && rm -rf internal/dist", "lint": "eslint \"./**/*.ts*\"", "type-check": "tsc --noEmit", "prettier-check": "prettier --check \"./**/*.ts*\"", @@ -27,6 +28,12 @@ "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.js" + }, + "./internal": { + "types": "./internal/dist/index.d.ts", + "import": "./internal/dist/index.mjs", + "module": "./internal/dist/index.mjs", + "require": "./internal/dist/index.js" } }, "dependencies": { diff --git a/packages/openai-compatible/src/internal/index.ts b/packages/openai-compatible/src/internal/index.ts new file mode 100644 index 000000000000..9b6e5c20a618 --- /dev/null +++ b/packages/openai-compatible/src/internal/index.ts @@ -0,0 +1,4 @@ +export { convertToOpenAICompatibleChatMessages } from '../convert-to-openai-compatible-chat-messages'; +export { mapOpenAICompatibleFinishReason } from '../map-openai-compatible-finish-reason'; +export { getResponseMetadata } from '../get-response-metadata'; +export type { OpenAICompatibleChatConfig } from '../openai-compatible-chat-language-model'; diff --git a/packages/openai-compatible/tsup.config.ts b/packages/openai-compatible/tsup.config.ts index 3f92041b987c..1085a16f678a 100644 --- a/packages/openai-compatible/tsup.config.ts +++ b/packages/openai-compatible/tsup.config.ts @@ -7,4 +7,11 @@ export default defineConfig([ dts: true, sourcemap: true, }, + { + entry: ['src/internal/index.ts'], + outDir: 'internal/dist', + format: ['cjs', 'esm'], + dts: true, + sourcemap: true, + }, ]);