@aigne/openai 0.11.1 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.3](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.11.2...openai-v0.11.3) (2025-08-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **core:** make getCredential async for aigne-hub mount point retrieval ([#372](https://github.com/AIGNE-io/aigne-framework/issues/372)) ([34ce7a6](https://github.com/AIGNE-io/aigne-framework/commit/34ce7a645fa83994d3dfe0f29ca70098cfecac9c))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.50.1
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.29
18
+
19
+ ## [0.11.2](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.11.1...openai-v0.11.2) (2025-08-14)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **cli:** log only once in loadAIGNE ([#357](https://github.com/AIGNE-io/aigne-framework/issues/357)) ([6e6d968](https://github.com/AIGNE-io/aigne-framework/commit/6e6d96814fbc87f210522ae16daf94c1f84f311a))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @aigne/core bumped to 1.50.0
32
+ * devDependencies
33
+ * @aigne/test-utils bumped to 0.5.28
34
+
3
35
  ## [0.11.1](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.11.0...openai-v0.11.1) (2025-08-12)
4
36
 
5
37
 
@@ -131,7 +131,12 @@ export declare class OpenAIChatModel extends ChatModel {
131
131
  protected supportsToolsEmptyParameters: boolean;
132
132
  protected supportsToolStreaming: boolean;
133
133
  protected supportsTemperature: boolean;
134
- get client(): OpenAI;
134
+ client(): Promise<OpenAI>;
135
+ getCredential(): Promise<{
136
+ url: string | undefined;
137
+ apiKey: string | undefined;
138
+ model: string;
139
+ }>;
135
140
  get modelOptions(): ChatModelOptions | undefined;
136
141
  /**
137
142
  * Process the input and generate a response
@@ -81,17 +81,24 @@ class OpenAIChatModel extends core_1.ChatModel {
81
81
  supportsToolsEmptyParameters = true;
82
82
  supportsToolStreaming = true;
83
83
  supportsTemperature = true;
84
- get client() {
85
- const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault;
84
+ async client() {
85
+ const { apiKey, url } = await this.getCredential();
86
86
  if (!apiKey)
87
87
  throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
88
88
  this._client ??= new CustomOpenAI({
89
- baseURL: this.options?.baseURL,
89
+ baseURL: url,
90
90
  apiKey,
91
91
  ...this.options?.clientOptions,
92
92
  });
93
93
  return this._client;
94
94
  }
95
+ async getCredential() {
96
+ return {
97
+ url: this.options?.baseURL || process.env.OPENAI_BASE_URL,
98
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault,
99
+ model: this.options?.model || CHAT_MODEL_OPENAI_DEFAULT_MODEL,
100
+ };
101
+ }
95
102
  get modelOptions() {
96
103
  return this.options?.modelOptions;
97
104
  }
@@ -106,8 +113,9 @@ class OpenAIChatModel extends core_1.ChatModel {
106
113
  ajv = new ajv_1.Ajv();
107
114
  async _process(input) {
108
115
  const messages = await this.getRunMessages(input);
116
+ const { model } = await this.getCredential();
109
117
  const body = {
110
- model: this.options?.model || CHAT_MODEL_OPENAI_DEFAULT_MODEL,
118
+ model,
111
119
  temperature: this.supportsTemperature
112
120
  ? (input.modelOptions?.temperature ?? this.modelOptions?.temperature)
113
121
  : undefined,
@@ -126,7 +134,8 @@ class OpenAIChatModel extends core_1.ChatModel {
126
134
  return await this.requestStructuredOutput(body, input.responseFormat);
127
135
  }
128
136
  const { jsonMode, responseFormat } = await this.getRunResponseFormat(input);
129
- const stream = (await this.client.chat.completions.create({
137
+ const client = await this.client();
138
+ const stream = (await client.chat.completions.create({
130
139
  ...body,
131
140
  tools: toolsFromInputTools(input.tools, {
132
141
  addTypeToEmptyParameters: !this.supportsToolsEmptyParameters,
@@ -205,7 +214,8 @@ class OpenAIChatModel extends core_1.ChatModel {
205
214
  const { jsonMode, responseFormat: resolvedResponseFormat } = await this.getRunResponseFormat({
206
215
  responseFormat,
207
216
  });
208
- const res = (await this.client.chat.completions.create({
217
+ const client = await this.client();
218
+ const res = (await client.chat.completions.create({
209
219
  ...body,
210
220
  response_format: resolvedResponseFormat,
211
221
  }));
@@ -131,7 +131,12 @@ export declare class OpenAIChatModel extends ChatModel {
131
131
  protected supportsToolsEmptyParameters: boolean;
132
132
  protected supportsToolStreaming: boolean;
133
133
  protected supportsTemperature: boolean;
134
- get client(): OpenAI;
134
+ client(): Promise<OpenAI>;
135
+ getCredential(): Promise<{
136
+ url: string | undefined;
137
+ apiKey: string | undefined;
138
+ model: string;
139
+ }>;
135
140
  get modelOptions(): ChatModelOptions | undefined;
136
141
  /**
137
142
  * Process the input and generate a response
@@ -131,7 +131,12 @@ export declare class OpenAIChatModel extends ChatModel {
131
131
  protected supportsToolsEmptyParameters: boolean;
132
132
  protected supportsToolStreaming: boolean;
133
133
  protected supportsTemperature: boolean;
134
- get client(): OpenAI;
134
+ client(): Promise<OpenAI>;
135
+ getCredential(): Promise<{
136
+ url: string | undefined;
137
+ apiKey: string | undefined;
138
+ model: string;
139
+ }>;
135
140
  get modelOptions(): ChatModelOptions | undefined;
136
141
  /**
137
142
  * Process the input and generate a response
@@ -72,17 +72,24 @@ export class OpenAIChatModel extends ChatModel {
72
72
  supportsToolsEmptyParameters = true;
73
73
  supportsToolStreaming = true;
74
74
  supportsTemperature = true;
75
- get client() {
76
- const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault;
75
+ async client() {
76
+ const { apiKey, url } = await this.getCredential();
77
77
  if (!apiKey)
78
78
  throw new Error(`${this.name} requires an API key. Please provide it via \`options.apiKey\`, or set the \`${this.apiKeyEnvName}\` environment variable`);
79
79
  this._client ??= new CustomOpenAI({
80
- baseURL: this.options?.baseURL,
80
+ baseURL: url,
81
81
  apiKey,
82
82
  ...this.options?.clientOptions,
83
83
  });
84
84
  return this._client;
85
85
  }
86
+ async getCredential() {
87
+ return {
88
+ url: this.options?.baseURL || process.env.OPENAI_BASE_URL,
89
+ apiKey: this.options?.apiKey || process.env[this.apiKeyEnvName] || this.apiKeyDefault,
90
+ model: this.options?.model || CHAT_MODEL_OPENAI_DEFAULT_MODEL,
91
+ };
92
+ }
86
93
  get modelOptions() {
87
94
  return this.options?.modelOptions;
88
95
  }
@@ -97,8 +104,9 @@ export class OpenAIChatModel extends ChatModel {
97
104
  ajv = new Ajv();
98
105
  async _process(input) {
99
106
  const messages = await this.getRunMessages(input);
107
+ const { model } = await this.getCredential();
100
108
  const body = {
101
- model: this.options?.model || CHAT_MODEL_OPENAI_DEFAULT_MODEL,
109
+ model,
102
110
  temperature: this.supportsTemperature
103
111
  ? (input.modelOptions?.temperature ?? this.modelOptions?.temperature)
104
112
  : undefined,
@@ -117,7 +125,8 @@ export class OpenAIChatModel extends ChatModel {
117
125
  return await this.requestStructuredOutput(body, input.responseFormat);
118
126
  }
119
127
  const { jsonMode, responseFormat } = await this.getRunResponseFormat(input);
120
- const stream = (await this.client.chat.completions.create({
128
+ const client = await this.client();
129
+ const stream = (await client.chat.completions.create({
121
130
  ...body,
122
131
  tools: toolsFromInputTools(input.tools, {
123
132
  addTypeToEmptyParameters: !this.supportsToolsEmptyParameters,
@@ -196,7 +205,8 @@ export class OpenAIChatModel extends ChatModel {
196
205
  const { jsonMode, responseFormat: resolvedResponseFormat } = await this.getRunResponseFormat({
197
206
  responseFormat,
198
207
  });
199
- const res = (await this.client.chat.completions.create({
208
+ const client = await this.client();
209
+ const res = (await client.chat.completions.create({
200
210
  ...body,
201
211
  response_format: resolvedResponseFormat,
202
212
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/openai",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -39,7 +39,7 @@
39
39
  "openai": "^5.8.3",
40
40
  "uuid": "^11.1.0",
41
41
  "zod": "^3.25.67",
42
- "@aigne/core": "^1.49.1"
42
+ "@aigne/core": "^1.50.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/bun": "^1.2.18",
@@ -47,7 +47,7 @@
47
47
  "npm-run-all": "^4.1.5",
48
48
  "rimraf": "^6.0.1",
49
49
  "typescript": "^5.8.3",
50
- "@aigne/test-utils": "^0.5.27"
50
+ "@aigne/test-utils": "^0.5.29"
51
51
  },
52
52
  "scripts": {
53
53
  "lint": "tsc --noEmit",