@artemiskit/adapter-openai 0.1.6 → 0.1.9
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 +30 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.js +26 -5
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +54 -6
- package/src/types.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @artemiskit/adapter-openai
|
|
2
2
|
|
|
3
|
+
## 0.1.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d5ca7c6]
|
|
8
|
+
- @artemiskit/core@0.2.2
|
|
9
|
+
|
|
10
|
+
## 0.1.8
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- fix: improve LLM grader compatibility with reasoning models
|
|
15
|
+
|
|
16
|
+
- Remove temperature parameter from LLM grader (reasoning models like o1, o3, gpt-5-mini only support temperature=1)
|
|
17
|
+
- Increase maxTokens from 200 to 1000 to accommodate reasoning models that use tokens for internal thinking
|
|
18
|
+
- Improve grader prompt for stricter JSON-only output format
|
|
19
|
+
- Add fallback parsing for malformed JSON responses
|
|
20
|
+
- Add markdown code block stripping from grader responses
|
|
21
|
+
- Add `modelFamily` configuration option to Azure OpenAI provider for correct parameter detection when deployment names differ from model names
|
|
22
|
+
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @artemiskit/core@0.2.1
|
|
25
|
+
|
|
26
|
+
## 0.1.7
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [d2c3835]
|
|
31
|
+
- @artemiskit/core@0.2.0
|
|
32
|
+
|
|
3
33
|
## 0.1.6
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -5,15 +5,23 @@
|
|
|
5
5
|
import type { AdapterConfig, GenerateOptions, GenerateResult, ModelCapabilities, ModelClient } from '@artemiskit/core';
|
|
6
6
|
export declare class OpenAIAdapter implements ModelClient {
|
|
7
7
|
private client;
|
|
8
|
+
private embeddingClient;
|
|
8
9
|
private config;
|
|
9
10
|
readonly provider: string;
|
|
10
11
|
constructor(config: AdapterConfig);
|
|
11
12
|
generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
12
13
|
stream(options: GenerateOptions, onChunk: (chunk: string) => void): AsyncIterable<string>;
|
|
13
|
-
embed(text: string): Promise<number[]>;
|
|
14
|
+
embed(text: string, model?: string): Promise<number[]>;
|
|
14
15
|
capabilities(): Promise<ModelCapabilities>;
|
|
15
16
|
close(): Promise<void>;
|
|
16
17
|
private normalizePrompt;
|
|
17
18
|
private mapFinishReason;
|
|
19
|
+
/**
|
|
20
|
+
* Determine if model requires max_completion_tokens instead of max_tokens
|
|
21
|
+
* Newer models (GPT-4o, GPT-5, o1, o3) require the new parameter
|
|
22
|
+
*
|
|
23
|
+
* @param model - The deployment name or model name used in the API call
|
|
24
|
+
*/
|
|
25
|
+
private shouldUseMaxCompletionTokens;
|
|
18
26
|
}
|
|
19
27
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAK1B,qBAAa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAiD;IAC/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,MAAM,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAK1B,qBAAa,aAAc,YAAW,WAAW;IAC/C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,MAAM,CAAiD;IAC/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,MAAM,EAAE,aAAa;IAyC3B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAsD1D,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC;IAqB1F,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmBtD,YAAY,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAW1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,eAAe;IAevB;;;;;OAKG;IACH,OAAO,CAAC,4BAA4B;CAUrC"}
|
package/dist/index.js
CHANGED
|
@@ -5516,6 +5516,7 @@ var openai_default = OpenAI;
|
|
|
5516
5516
|
// src/client.ts
|
|
5517
5517
|
class OpenAIAdapter {
|
|
5518
5518
|
client;
|
|
5519
|
+
embeddingClient = null;
|
|
5519
5520
|
config;
|
|
5520
5521
|
provider;
|
|
5521
5522
|
constructor(config) {
|
|
@@ -5531,6 +5532,16 @@ class OpenAIAdapter {
|
|
|
5531
5532
|
timeout: azureConfig.timeout ?? 60000,
|
|
5532
5533
|
maxRetries: azureConfig.maxRetries ?? 2
|
|
5533
5534
|
});
|
|
5535
|
+
if (azureConfig.embeddingDeploymentName) {
|
|
5536
|
+
this.embeddingClient = new openai_default({
|
|
5537
|
+
apiKey: azureConfig.apiKey,
|
|
5538
|
+
baseURL: `https://${azureConfig.resourceName}.openai.azure.com/openai/deployments/${azureConfig.embeddingDeploymentName}`,
|
|
5539
|
+
defaultQuery: { "api-version": azureConfig.apiVersion },
|
|
5540
|
+
defaultHeaders: { "api-key": azureConfig.apiKey ?? "" },
|
|
5541
|
+
timeout: azureConfig.timeout ?? 60000,
|
|
5542
|
+
maxRetries: azureConfig.maxRetries ?? 2
|
|
5543
|
+
});
|
|
5544
|
+
}
|
|
5534
5545
|
} else {
|
|
5535
5546
|
const openaiConfig = config;
|
|
5536
5547
|
this.provider = "openai";
|
|
@@ -5547,10 +5558,12 @@ class OpenAIAdapter {
|
|
|
5547
5558
|
const startTime = Date.now();
|
|
5548
5559
|
const model = options.model || this.config.defaultModel || "gpt-4";
|
|
5549
5560
|
const messages = this.normalizePrompt(options.prompt);
|
|
5561
|
+
const useNewTokenParam = this.shouldUseMaxCompletionTokens(model);
|
|
5562
|
+
const tokenParams = options.maxTokens ? useNewTokenParam ? { max_completion_tokens: options.maxTokens } : { max_tokens: options.maxTokens } : {};
|
|
5550
5563
|
const response = await this.client.chat.completions.create({
|
|
5551
5564
|
model,
|
|
5552
5565
|
messages,
|
|
5553
|
-
|
|
5566
|
+
...tokenParams,
|
|
5554
5567
|
temperature: options.temperature,
|
|
5555
5568
|
top_p: options.topP,
|
|
5556
5569
|
seed: options.seed,
|
|
@@ -5600,10 +5613,11 @@ class OpenAIAdapter {
|
|
|
5600
5613
|
}
|
|
5601
5614
|
}
|
|
5602
5615
|
}
|
|
5603
|
-
async embed(text) {
|
|
5604
|
-
const
|
|
5605
|
-
const
|
|
5606
|
-
|
|
5616
|
+
async embed(text, model) {
|
|
5617
|
+
const embeddingModel = model || (this.config.provider === "azure-openai" ? "text-embedding-3-large" : "text-embedding-3-small");
|
|
5618
|
+
const client = this.embeddingClient || this.client;
|
|
5619
|
+
const response = await client.embeddings.create({
|
|
5620
|
+
model: embeddingModel,
|
|
5607
5621
|
input: text
|
|
5608
5622
|
});
|
|
5609
5623
|
return response.data[0].embedding;
|
|
@@ -5642,6 +5656,13 @@ class OpenAIAdapter {
|
|
|
5642
5656
|
return "stop";
|
|
5643
5657
|
}
|
|
5644
5658
|
}
|
|
5659
|
+
shouldUseMaxCompletionTokens(model) {
|
|
5660
|
+
const azureConfig = this.config;
|
|
5661
|
+
const modelToCheck = azureConfig.modelFamily || model;
|
|
5662
|
+
const modelLower = modelToCheck.toLowerCase();
|
|
5663
|
+
const newParamModels = ["gpt-4o", "gpt-4-turbo", "gpt-5", "o1", "o3", "chatgpt-4o"];
|
|
5664
|
+
return newParamModels.some((m) => modelLower.includes(m));
|
|
5665
|
+
}
|
|
5645
5666
|
}
|
|
5646
5667
|
export {
|
|
5647
5668
|
OpenAIAdapter
|
package/dist/types.d.ts
CHANGED
|
@@ -20,5 +20,12 @@ export interface AzureOpenAIAdapterConfig {
|
|
|
20
20
|
resourceName: string;
|
|
21
21
|
deploymentName: string;
|
|
22
22
|
apiVersion: string;
|
|
23
|
+
/** Optional separate deployment name for embedding models */
|
|
24
|
+
embeddingDeploymentName?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Model family for parameter detection (e.g., 'gpt-5-mini' when deployment is '5-mini')
|
|
27
|
+
* Used to determine which API parameters to use (max_tokens vs max_completion_tokens)
|
|
28
|
+
*/
|
|
29
|
+
modelFamily?: string;
|
|
23
30
|
}
|
|
24
31
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;I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;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artemiskit/adapter-openai",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "OpenAI and Azure OpenAI adapter for ArtemisKit LLM evaluation toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test": "bun test"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@artemiskit/core": "
|
|
33
|
+
"@artemiskit/core": "workspace:*",
|
|
34
34
|
"openai": "^4.28.0",
|
|
35
35
|
"nanoid": "^5.0.0"
|
|
36
36
|
},
|
package/src/client.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { AzureOpenAIAdapterConfig, OpenAIAdapterConfig } from './types';
|
|
|
16
16
|
|
|
17
17
|
export class OpenAIAdapter implements ModelClient {
|
|
18
18
|
private client: OpenAI;
|
|
19
|
+
private embeddingClient: OpenAI | null = null;
|
|
19
20
|
private config: OpenAIAdapterConfig | AzureOpenAIAdapterConfig;
|
|
20
21
|
readonly provider: string;
|
|
21
22
|
|
|
@@ -34,6 +35,18 @@ export class OpenAIAdapter implements ModelClient {
|
|
|
34
35
|
timeout: azureConfig.timeout ?? 60000,
|
|
35
36
|
maxRetries: azureConfig.maxRetries ?? 2,
|
|
36
37
|
});
|
|
38
|
+
|
|
39
|
+
// Create separate client for embeddings if a different deployment is specified
|
|
40
|
+
if (azureConfig.embeddingDeploymentName) {
|
|
41
|
+
this.embeddingClient = new OpenAI({
|
|
42
|
+
apiKey: azureConfig.apiKey,
|
|
43
|
+
baseURL: `https://${azureConfig.resourceName}.openai.azure.com/openai/deployments/${azureConfig.embeddingDeploymentName}`,
|
|
44
|
+
defaultQuery: { 'api-version': azureConfig.apiVersion },
|
|
45
|
+
defaultHeaders: { 'api-key': azureConfig.apiKey ?? '' },
|
|
46
|
+
timeout: azureConfig.timeout ?? 60000,
|
|
47
|
+
maxRetries: azureConfig.maxRetries ?? 2,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
37
50
|
} else {
|
|
38
51
|
const openaiConfig = config as OpenAIAdapterConfig;
|
|
39
52
|
this.provider = 'openai';
|
|
@@ -54,10 +67,20 @@ export class OpenAIAdapter implements ModelClient {
|
|
|
54
67
|
|
|
55
68
|
const messages = this.normalizePrompt(options.prompt);
|
|
56
69
|
|
|
70
|
+
// Determine which token limit parameter to use
|
|
71
|
+
// Newer models (GPT-4o, GPT-5, o1, o3) use max_completion_tokens
|
|
72
|
+
// Older models use max_tokens
|
|
73
|
+
const useNewTokenParam = this.shouldUseMaxCompletionTokens(model);
|
|
74
|
+
const tokenParams = options.maxTokens
|
|
75
|
+
? useNewTokenParam
|
|
76
|
+
? { max_completion_tokens: options.maxTokens }
|
|
77
|
+
: { max_tokens: options.maxTokens }
|
|
78
|
+
: {};
|
|
79
|
+
|
|
57
80
|
const response = await this.client.chat.completions.create({
|
|
58
81
|
model,
|
|
59
82
|
messages,
|
|
60
|
-
|
|
83
|
+
...tokenParams,
|
|
61
84
|
temperature: options.temperature,
|
|
62
85
|
top_p: options.topP,
|
|
63
86
|
seed: options.seed,
|
|
@@ -113,12 +136,20 @@ export class OpenAIAdapter implements ModelClient {
|
|
|
113
136
|
}
|
|
114
137
|
}
|
|
115
138
|
|
|
116
|
-
async embed(text: string): Promise<number[]> {
|
|
117
|
-
|
|
118
|
-
|
|
139
|
+
async embed(text: string, model?: string): Promise<number[]> {
|
|
140
|
+
// Use provided model, or fall back to provider defaults
|
|
141
|
+
const embeddingModel =
|
|
142
|
+
model ||
|
|
143
|
+
(this.config.provider === 'azure-openai'
|
|
144
|
+
? 'text-embedding-3-large'
|
|
145
|
+
: 'text-embedding-3-small');
|
|
119
146
|
|
|
120
|
-
|
|
121
|
-
|
|
147
|
+
// For Azure, use the dedicated embedding client if available
|
|
148
|
+
// Otherwise fall back to main client (which may fail if deployment doesn't support embeddings)
|
|
149
|
+
const client = this.embeddingClient || this.client;
|
|
150
|
+
|
|
151
|
+
const response = await client.embeddings.create({
|
|
152
|
+
model: embeddingModel,
|
|
122
153
|
input: text,
|
|
123
154
|
});
|
|
124
155
|
return response.data[0].embedding;
|
|
@@ -163,4 +194,21 @@ export class OpenAIAdapter implements ModelClient {
|
|
|
163
194
|
return 'stop';
|
|
164
195
|
}
|
|
165
196
|
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Determine if model requires max_completion_tokens instead of max_tokens
|
|
200
|
+
* Newer models (GPT-4o, GPT-5, o1, o3) require the new parameter
|
|
201
|
+
*
|
|
202
|
+
* @param model - The deployment name or model name used in the API call
|
|
203
|
+
*/
|
|
204
|
+
private shouldUseMaxCompletionTokens(model: string): boolean {
|
|
205
|
+
// First check modelFamily from config (most reliable for Azure deployments)
|
|
206
|
+
const azureConfig = this.config as AzureOpenAIAdapterConfig;
|
|
207
|
+
const modelToCheck = azureConfig.modelFamily || model;
|
|
208
|
+
|
|
209
|
+
const modelLower = modelToCheck.toLowerCase();
|
|
210
|
+
// Models that require max_completion_tokens
|
|
211
|
+
const newParamModels = ['gpt-4o', 'gpt-4-turbo', 'gpt-5', 'o1', 'o3', 'chatgpt-4o'];
|
|
212
|
+
return newParamModels.some((m) => modelLower.includes(m));
|
|
213
|
+
}
|
|
166
214
|
}
|
package/src/types.ts
CHANGED
|
@@ -22,4 +22,11 @@ export interface AzureOpenAIAdapterConfig {
|
|
|
22
22
|
resourceName: string;
|
|
23
23
|
deploymentName: string;
|
|
24
24
|
apiVersion: string;
|
|
25
|
+
/** Optional separate deployment name for embedding models */
|
|
26
|
+
embeddingDeploymentName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Model family for parameter detection (e.g., 'gpt-5-mini' when deployment is '5-mini')
|
|
29
|
+
* Used to determine which API parameters to use (max_tokens vs max_completion_tokens)
|
|
30
|
+
*/
|
|
31
|
+
modelFamily?: string;
|
|
25
32
|
}
|