@ai-sdk/openai-compatible
Advanced tools
Comparing version 0.0.13 to 0.0.14
# @ai-sdk/openai-compatible | ||
## 0.0.14 | ||
### Patch Changes | ||
- 43b37f7: feat (provider/openai-compatible): Add 'apiKey' option for concise direct use. | ||
- Updated dependencies [19a2ce7] | ||
- Updated dependencies [19a2ce7] | ||
- Updated dependencies [6337688] | ||
- @ai-sdk/provider@1.0.4 | ||
- @ai-sdk/provider-utils@2.0.6 | ||
## 0.0.13 | ||
@@ -4,0 +15,0 @@ |
@@ -76,16 +76,23 @@ import { ProviderV1, LanguageModelV1, EmbeddingModelV1, LanguageModelV1ObjectGenerationMode } from '@ai-sdk/provider'; | ||
/** | ||
Base URL for the API calls. | ||
Base URL for the API calls. | ||
*/ | ||
baseURL?: string; | ||
/** | ||
Custom headers to include in the requests. | ||
API key for authenticating requests. If specified, adds an `Authorization` | ||
header to request headers with the value `Bearer <apiKey>`. This will be added | ||
before any headers potentially specified in the `headers` option. | ||
*/ | ||
apiKey?: string; | ||
/** | ||
Optional custom headers to include in requests. These will be added to request headers | ||
after any headers potentially added by use of the `apiKey` option. | ||
*/ | ||
headers?: Record<string, string>; | ||
/** | ||
Custom fetch implementation. You can use it as a middleware to intercept requests, | ||
or to provide a custom fetch implementation for e.g. testing. | ||
Custom fetch implementation. You can use it as a middleware to intercept requests, | ||
or to provide a custom fetch implementation for e.g. testing. | ||
*/ | ||
fetch?: FetchFunction; | ||
/** | ||
Provider name. | ||
Provider name. | ||
*/ | ||
@@ -92,0 +99,0 @@ name?: string; |
@@ -1127,9 +1127,10 @@ "use strict"; | ||
const providerName = options.name; | ||
const getHeaders = () => ({ | ||
...options.apiKey && { Authorization: `Bearer ${options.apiKey}` }, | ||
...options.headers | ||
}); | ||
const getCommonModelConfig = (modelType) => ({ | ||
provider: `${providerName}.${modelType}`, | ||
url: ({ path }) => `${baseURL}${path}`, | ||
headers: () => { | ||
var _a; | ||
return (_a = options.headers) != null ? _a : {}; | ||
}, | ||
headers: getHeaders, | ||
fetch: options.fetch | ||
@@ -1136,0 +1137,0 @@ }); |
{ | ||
"name": "@ai-sdk/openai-compatible", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"license": "Apache-2.0", | ||
@@ -29,4 +29,4 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@ai-sdk/provider": "1.0.3", | ||
"@ai-sdk/provider-utils": "2.0.5" | ||
"@ai-sdk/provider": "1.0.4", | ||
"@ai-sdk/provider-utils": "2.0.6" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
@@ -33,2 +33,20 @@ # AI SDK - OpenAI Compatible Provider | ||
name: 'example', | ||
apiKey: process.env.MY_API_KEY, | ||
}).chatModel('meta-llama/Llama-3-70b-chat-hf'), | ||
prompt: 'Write a vegetarian lasagna recipe for 4 people.', | ||
}); | ||
``` | ||
### Customizing headers | ||
You can further customize headers if desired. For example, here is an alternate implementation to pass along api key authentication: | ||
```ts | ||
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'; | ||
import { generateText } from 'ai'; | ||
const { text } = await generateText({ | ||
model: createOpenAICompatible({ | ||
baseURL: 'https://api.example.com/v1', | ||
name: 'example', | ||
headers: { | ||
@@ -70,5 +88,3 @@ Authorization: `Bearer ${process.env.MY_API_KEY}`, | ||
name: 'example', | ||
headers: { | ||
Authorization: `Bearer ${process.env.MY_API_KEY}`, | ||
}, | ||
apiKey: process.env.MY_API_KEY, | ||
}); | ||
@@ -75,0 +91,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284672
2923
101
+ Added@ai-sdk/provider@1.0.4(transitive)
+ Added@ai-sdk/provider-utils@2.0.6(transitive)
- Removed@ai-sdk/provider@1.0.3(transitive)
- Removed@ai-sdk/provider-utils@2.0.5(transitive)
Updated@ai-sdk/provider@1.0.4
Updated@ai-sdk/provider-utils@2.0.6