Skip to content

Commit 7049914

Browse files
committed
fix: redesigned model map feature
1 parent f9e39e5 commit 7049914

File tree

16 files changed

+184
-152
lines changed

16 files changed

+184
-152
lines changed

src/ax/ai/anthropic/api.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ export interface AxAIAnthropicArgs {
3434
apiKey: string;
3535
config?: Readonly<Partial<AxAIAnthropicConfig>>;
3636
options?: Readonly<AxAIServiceOptions>;
37+
modelMap?: Record<string, AxAIAnthropicModel | string>;
3738
}
3839

3940
export class AxAIAnthropic extends AxBaseAI<
40-
AxAIAnthropicModel,
41-
string,
4241
AxAIAnthropicChatRequest,
4342
unknown,
4443
AxAIAnthropicChatResponse,
@@ -50,7 +49,8 @@ export class AxAIAnthropic extends AxBaseAI<
5049
constructor({
5150
apiKey,
5251
config,
53-
options
52+
options,
53+
modelMap
5454
}: Readonly<Omit<AxAIAnthropicArgs, 'name'>>) {
5555
if (!apiKey || apiKey === '') {
5656
throw new Error('Anthropic API key not set');
@@ -69,7 +69,8 @@ export class AxAIAnthropic extends AxBaseAI<
6969
modelInfo: axModelInfoAnthropic,
7070
models: { model: _config.model },
7171
options,
72-
supportFor: { functions: true, streaming: true }
72+
supportFor: { functions: true, streaming: true },
73+
modelMap
7374
});
7475

7576
this.config = _config;

src/ax/ai/azure-openai/api.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
axAIOpenAIDefaultConfig,
66
axAIOpenAIFastConfig
77
} from '../openai/api.js';
8-
import type { AxAIOpenAIConfig } from '../openai/types.js';
8+
import type {
9+
AxAIOpenAIConfig,
10+
AxAIOpenAIEmbedModel,
11+
AxAIOpenAIModel
12+
} from '../openai/types.js';
913
import type { AxAIServiceOptions } from '../types.js';
1014

1115
export const axAIAzureOpenAIDefaultConfig = axAIOpenAIDefaultConfig;
@@ -24,6 +28,7 @@ export interface AxAIAzureOpenAIArgs {
2428
version?: string;
2529
config?: Readonly<Partial<AxAIOpenAIConfig>>;
2630
options?: Readonly<AxAIServiceOptions>;
31+
modelMap?: Record<string, AxAIOpenAIModel | AxAIOpenAIEmbedModel>;
2732
}
2833

2934
export class AxAIAzureOpenAI extends AxAIOpenAI {
@@ -33,7 +38,8 @@ export class AxAIAzureOpenAI extends AxAIOpenAI {
3338
deploymentName,
3439
version = 'api-version=2024-02-15-preview',
3540
config,
36-
options
41+
options,
42+
modelMap
3743
}: Readonly<Omit<AxAIAzureOpenAIArgs, 'name'>>) {
3844
if (!apiKey || apiKey === '') {
3945
throw new Error('Azure OpenAPI API key not set');
@@ -48,7 +54,7 @@ export class AxAIAzureOpenAI extends AxAIOpenAI {
4854
...axAIAzureOpenAIDefaultConfig(),
4955
...config
5056
};
51-
super({ apiKey, config: _config, options });
57+
super({ apiKey, config: _config, options, modelMap });
5258

5359
const host = resourceName.includes('://')
5460
? resourceName

src/ax/ai/balance.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReadableStream } from 'stream/web';
22

3-
import type { AxAIModelMap } from './base.js';
43
import type {
4+
AxAIModelMap,
55
AxAIPromptConfig,
66
AxAIService,
77
AxAIServiceActionOptions,
@@ -11,18 +11,20 @@ import type {
1111
AxEmbedRequest,
1212
AxEmbedResponse,
1313
AxModelConfig,
14-
AxModelInfo
14+
AxModelInfoWithProvider
1515
} from './types.js';
1616

1717
export class AxBalancer implements AxAIService {
1818
private services: AxAIService[];
1919
private currentServiceIndex: number = 0;
2020
private currentService: AxAIService;
21+
private serviceMap: Record<string, AxAIService> = {};
2122

2223
constructor(services: readonly AxAIService[]) {
2324
if (services.length === 0) {
2425
throw new Error('No AI services provided.');
2526
}
27+
2628
this.services = [...services].sort((a, b) => {
2729
const aInfo = a.getModelInfo();
2830
const bInfo = b.getModelInfo();
@@ -42,12 +44,8 @@ export class AxBalancer implements AxAIService {
4244
this.currentService = cs;
4345
}
4446

45-
setModelMap(modelMap: AxAIModelMap<string>): void {
46-
this.currentService.setModelMap(modelMap);
47-
}
48-
49-
setEmbedModelMap(embedModelMap: AxAIModelMap<string>): void {
50-
this.currentService.setEmbedModelMap(embedModelMap);
47+
getModelMap(): AxAIModelMap | undefined {
48+
throw new Error('Method not implemented.');
5149
}
5250

5351
private getNextService(): boolean {
@@ -72,11 +70,11 @@ export class AxBalancer implements AxAIService {
7270
return this.currentService.getName();
7371
}
7472

75-
getModelInfo(): Readonly<AxModelInfo & { provider: string }> {
73+
getModelInfo(): Readonly<AxModelInfoWithProvider> {
7674
return this.currentService.getModelInfo();
7775
}
7876

79-
getEmbedModelInfo(): Readonly<AxModelInfo> | undefined {
77+
getEmbedModelInfo(): Readonly<AxModelInfoWithProvider> | undefined {
8078
return this.currentService.getEmbedModelInfo();
8179
}
8280

0 commit comments

Comments
 (0)