Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (provider/openai-compatible): Add'l exports for customization. #4179

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-melons-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/openai-compatible': patch
---

feat (provider/openai-compatible): Add'l exports for customization.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
9 changes: 8 additions & 1 deletion packages/openai-compatible/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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*\"",
Expand All @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions packages/openai-compatible/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -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';
7 changes: 7 additions & 0 deletions packages/openai-compatible/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]);
Loading