@ai-sdk/openai
Advanced tools
Comparing version 1.0.0-canary.0 to 1.0.0-canary.1
@@ -23,3 +23,2 @@ "use strict"; | ||
__export(src_exports, { | ||
OpenAI: () => OpenAI, | ||
createOpenAI: () => createOpenAI, | ||
@@ -30,4 +29,4 @@ openai: () => openai | ||
// src/openai-facade.ts | ||
var import_provider_utils5 = require("@ai-sdk/provider-utils"); | ||
// src/openai-provider.ts | ||
var import_provider_utils6 = require("@ai-sdk/provider-utils"); | ||
@@ -1291,55 +1290,5 @@ // src/openai-chat-language-model.ts | ||
// src/openai-facade.ts | ||
var OpenAI = class { | ||
/** | ||
* Creates a new OpenAI provider instance. | ||
*/ | ||
constructor(options = {}) { | ||
var _a, _b; | ||
this.baseURL = (_b = (0, import_provider_utils5.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.openai.com/v1"; | ||
this.apiKey = options.apiKey; | ||
this.organization = options.organization; | ||
this.project = options.project; | ||
this.headers = options.headers; | ||
} | ||
get baseConfig() { | ||
return { | ||
organization: this.organization, | ||
baseURL: this.baseURL, | ||
headers: () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({ | ||
apiKey: this.apiKey, | ||
environmentVariableName: "OPENAI_API_KEY", | ||
description: "OpenAI" | ||
})}`, | ||
"OpenAI-Organization": this.organization, | ||
"OpenAI-Project": this.project, | ||
...this.headers | ||
}) | ||
}; | ||
} | ||
chat(modelId, settings = {}) { | ||
return new OpenAIChatLanguageModel(modelId, settings, { | ||
provider: "openai.chat", | ||
...this.baseConfig, | ||
compatibility: "strict", | ||
url: ({ path }) => `${this.baseURL}${path}` | ||
}); | ||
} | ||
completion(modelId, settings = {}) { | ||
return new OpenAICompletionLanguageModel(modelId, settings, { | ||
provider: "openai.completion", | ||
...this.baseConfig, | ||
compatibility: "strict", | ||
url: ({ path }) => `${this.baseURL}${path}` | ||
}); | ||
} | ||
}; | ||
// src/openai-provider.ts | ||
var import_provider_utils7 = require("@ai-sdk/provider-utils"); | ||
// src/openai-embedding-model.ts | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_provider_utils6 = require("@ai-sdk/provider-utils"); | ||
var import_provider_utils5 = require("@ai-sdk/provider-utils"); | ||
var import_zod4 = require("zod"); | ||
@@ -1377,3 +1326,3 @@ var OpenAIEmbeddingModel = class { | ||
} | ||
const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({ | ||
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({ | ||
url: this.config.url({ | ||
@@ -1383,3 +1332,3 @@ path: "/embeddings", | ||
}), | ||
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers), | ||
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers), | ||
body: { | ||
@@ -1393,3 +1342,3 @@ model: this.modelId, | ||
failedResponseHandler: openaiFailedResponseHandler, | ||
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)( | ||
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)( | ||
openaiTextEmbeddingResponseSchema | ||
@@ -1414,8 +1363,8 @@ ), | ||
function createOpenAI(options = {}) { | ||
var _a, _b, _c, _d; | ||
const baseURL = (_b = (0, import_provider_utils7.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.openai.com/v1"; | ||
const compatibility = (_c = options.compatibility) != null ? _c : "compatible"; | ||
const providerName = (_d = options.name) != null ? _d : "openai"; | ||
var _a, _b, _c; | ||
const baseURL = (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1"; | ||
const compatibility = (_b = options.compatibility) != null ? _b : "compatible"; | ||
const providerName = (_c = options.name) != null ? _c : "openai"; | ||
const getHeaders = () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({ | ||
Authorization: `Bearer ${(0, import_provider_utils6.loadApiKey)({ | ||
apiKey: options.apiKey, | ||
@@ -1480,3 +1429,2 @@ environmentVariableName: "OPENAI_API_KEY", | ||
0 && (module.exports = { | ||
OpenAI, | ||
createOpenAI, | ||
@@ -1483,0 +1431,0 @@ openai |
# @ai-sdk/openai | ||
## 1.0.0-canary.1 | ||
### Major Changes | ||
- 79644e9: chore (provider/openai): remove OpenAI facade | ||
- 0d3d3f5: chore (providers): remove baseUrl option | ||
### Patch Changes | ||
- Updated dependencies [b1da952] | ||
- @ai-sdk/provider-utils@2.0.0-canary.1 | ||
## 1.0.0-canary.0 | ||
@@ -4,0 +16,0 @@ |
@@ -70,27 +70,2 @@ import { LanguageModelV1, ProviderV1, EmbeddingModelV1 } from '@ai-sdk/provider'; | ||
type OpenAIChatConfig = { | ||
provider: string; | ||
compatibility: 'strict' | 'compatible'; | ||
headers: () => Record<string, string | undefined>; | ||
url: (options: { | ||
modelId: string; | ||
path: string; | ||
}) => string; | ||
fetch?: FetchFunction; | ||
}; | ||
declare class OpenAIChatLanguageModel implements LanguageModelV1 { | ||
readonly specificationVersion = "v1"; | ||
readonly modelId: OpenAIChatModelId; | ||
readonly settings: OpenAIChatSettings; | ||
private readonly config; | ||
constructor(modelId: OpenAIChatModelId, settings: OpenAIChatSettings, config: OpenAIChatConfig); | ||
get supportsStructuredOutputs(): boolean; | ||
get defaultObjectGenerationMode(): "tool" | "json"; | ||
get provider(): string; | ||
get supportsImageUrls(): boolean; | ||
private getArgs; | ||
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>; | ||
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>; | ||
} | ||
type OpenAICompletionModelId = 'gpt-3.5-turbo-instruct' | (string & {}); | ||
@@ -222,6 +197,2 @@ interface OpenAICompletionSettings { | ||
/** | ||
@deprecated Use `baseURL` instead. | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
API key for authenticating requests. | ||
@@ -267,37 +238,2 @@ */ | ||
/** | ||
@deprecated Use `createOpenAI` instead. | ||
*/ | ||
declare class OpenAI { | ||
/** | ||
Use a different URL prefix for API calls, e.g. to use proxy servers. | ||
The default prefix is `https://api.openai.com/v1`. | ||
*/ | ||
readonly baseURL: string; | ||
/** | ||
API key that is being send using the `Authorization` header. | ||
It defaults to the `OPENAI_API_KEY` environment variable. | ||
*/ | ||
readonly apiKey?: string; | ||
/** | ||
OpenAI Organization. | ||
*/ | ||
readonly organization?: string; | ||
/** | ||
OpenAI project. | ||
*/ | ||
readonly project?: string; | ||
/** | ||
Custom headers to include in the requests. | ||
*/ | ||
readonly headers?: Record<string, string>; | ||
/** | ||
* Creates a new OpenAI provider instance. | ||
*/ | ||
constructor(options?: OpenAIProviderSettings); | ||
private get baseConfig(); | ||
chat(modelId: OpenAIChatModelId, settings?: OpenAIChatSettings): OpenAIChatLanguageModel; | ||
completion(modelId: OpenAICompletionModelId, settings?: OpenAICompletionSettings): OpenAICompletionLanguageModel; | ||
} | ||
export { OpenAI, type OpenAIProvider, type OpenAIProviderSettings, createOpenAI, openai }; | ||
export { type OpenAIProvider, type OpenAIProviderSettings, createOpenAI, openai }; |
@@ -23,3 +23,2 @@ "use strict"; | ||
__export(src_exports, { | ||
OpenAI: () => OpenAI, | ||
createOpenAI: () => createOpenAI, | ||
@@ -30,4 +29,4 @@ openai: () => openai | ||
// src/openai-facade.ts | ||
var import_provider_utils5 = require("@ai-sdk/provider-utils"); | ||
// src/openai-provider.ts | ||
var import_provider_utils6 = require("@ai-sdk/provider-utils"); | ||
@@ -1291,55 +1290,5 @@ // src/openai-chat-language-model.ts | ||
// src/openai-facade.ts | ||
var OpenAI = class { | ||
/** | ||
* Creates a new OpenAI provider instance. | ||
*/ | ||
constructor(options = {}) { | ||
var _a, _b; | ||
this.baseURL = (_b = (0, import_provider_utils5.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.openai.com/v1"; | ||
this.apiKey = options.apiKey; | ||
this.organization = options.organization; | ||
this.project = options.project; | ||
this.headers = options.headers; | ||
} | ||
get baseConfig() { | ||
return { | ||
organization: this.organization, | ||
baseURL: this.baseURL, | ||
headers: () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({ | ||
apiKey: this.apiKey, | ||
environmentVariableName: "OPENAI_API_KEY", | ||
description: "OpenAI" | ||
})}`, | ||
"OpenAI-Organization": this.organization, | ||
"OpenAI-Project": this.project, | ||
...this.headers | ||
}) | ||
}; | ||
} | ||
chat(modelId, settings = {}) { | ||
return new OpenAIChatLanguageModel(modelId, settings, { | ||
provider: "openai.chat", | ||
...this.baseConfig, | ||
compatibility: "strict", | ||
url: ({ path }) => `${this.baseURL}${path}` | ||
}); | ||
} | ||
completion(modelId, settings = {}) { | ||
return new OpenAICompletionLanguageModel(modelId, settings, { | ||
provider: "openai.completion", | ||
...this.baseConfig, | ||
compatibility: "strict", | ||
url: ({ path }) => `${this.baseURL}${path}` | ||
}); | ||
} | ||
}; | ||
// src/openai-provider.ts | ||
var import_provider_utils7 = require("@ai-sdk/provider-utils"); | ||
// src/openai-embedding-model.ts | ||
var import_provider6 = require("@ai-sdk/provider"); | ||
var import_provider_utils6 = require("@ai-sdk/provider-utils"); | ||
var import_provider_utils5 = require("@ai-sdk/provider-utils"); | ||
var import_zod4 = require("zod"); | ||
@@ -1377,3 +1326,3 @@ var OpenAIEmbeddingModel = class { | ||
} | ||
const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({ | ||
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({ | ||
url: this.config.url({ | ||
@@ -1383,3 +1332,3 @@ path: "/embeddings", | ||
}), | ||
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers), | ||
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers), | ||
body: { | ||
@@ -1393,3 +1342,3 @@ model: this.modelId, | ||
failedResponseHandler: openaiFailedResponseHandler, | ||
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)( | ||
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)( | ||
openaiTextEmbeddingResponseSchema | ||
@@ -1414,8 +1363,8 @@ ), | ||
function createOpenAI(options = {}) { | ||
var _a, _b, _c, _d; | ||
const baseURL = (_b = (0, import_provider_utils7.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.openai.com/v1"; | ||
const compatibility = (_c = options.compatibility) != null ? _c : "compatible"; | ||
const providerName = (_d = options.name) != null ? _d : "openai"; | ||
var _a, _b, _c; | ||
const baseURL = (_a = (0, import_provider_utils6.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1"; | ||
const compatibility = (_b = options.compatibility) != null ? _b : "compatible"; | ||
const providerName = (_c = options.name) != null ? _c : "openai"; | ||
const getHeaders = () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils7.loadApiKey)({ | ||
Authorization: `Bearer ${(0, import_provider_utils6.loadApiKey)({ | ||
apiKey: options.apiKey, | ||
@@ -1480,3 +1429,2 @@ environmentVariableName: "OPENAI_API_KEY", | ||
0 && (module.exports = { | ||
OpenAI, | ||
createOpenAI, | ||
@@ -1483,0 +1431,0 @@ openai |
{ | ||
"name": "@ai-sdk/openai", | ||
"version": "1.0.0-canary.0", | ||
"version": "1.0.0-canary.1", | ||
"license": "Apache-2.0", | ||
@@ -30,3 +30,3 @@ "sideEffects": false, | ||
"@ai-sdk/provider": "1.0.0-canary.0", | ||
"@ai-sdk/provider-utils": "2.0.0-canary.0" | ||
"@ai-sdk/provider-utils": "2.0.0-canary.1" | ||
}, | ||
@@ -33,0 +33,0 @@ "devDependencies": { |
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
633804
7308
+ Added@ai-sdk/provider-utils@2.0.0-canary.1(transitive)
- Removed@ai-sdk/provider-utils@2.0.0-canary.0(transitive)