Skip to content

Commit

Permalink
feat (provider/openai-compatible): Add'l exports for customization. (#…
Browse files Browse the repository at this point in the history
…4179)

Co-authored-by: minpeter <minpeter@friendli.ai>
  • Loading branch information
shaper and minpeter authored Dec 24, 2024
1 parent 8bf49e1 commit 6564812
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
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,
},
]);

0 comments on commit 6564812

Please sign in to comment.