fix: add API key/auth token support across all model clients
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
import type { ModelClient, Message } from '../../models/types.js';
|
||||
import type { ModelRouter, ModelTier } from '../../models/router.js';
|
||||
import type { Session } from '../../session/index.js';
|
||||
|
||||
export interface NativeAgentConfig {
|
||||
modelClient: ModelClient;
|
||||
modelClient: ModelClient | ModelRouter;
|
||||
systemPrompt: string;
|
||||
session?: Session;
|
||||
}
|
||||
|
||||
export class NativeAgent {
|
||||
private modelClient: ModelClient;
|
||||
private modelClient: ModelClient | ModelRouter;
|
||||
private systemPrompt: string;
|
||||
private session?: Session;
|
||||
private inMemoryHistory: Message[] = [];
|
||||
private currentTier: ModelTier = 'default';
|
||||
|
||||
constructor(config: NativeAgentConfig) {
|
||||
this.modelClient = config.modelClient;
|
||||
@@ -32,10 +34,15 @@ export class NativeAgent {
|
||||
this.inMemoryHistory.push(userMsg);
|
||||
}
|
||||
|
||||
const response = await this.modelClient.chat({
|
||||
const request = {
|
||||
messages: this.history,
|
||||
system: this.systemPrompt,
|
||||
});
|
||||
};
|
||||
|
||||
// Use tier if modelClient is a ModelRouter
|
||||
const response = 'getClient' in this.modelClient
|
||||
? await (this.modelClient as ModelRouter).chat(request, this.currentTier)
|
||||
: await this.modelClient.chat(request);
|
||||
|
||||
const assistantMsg: Message = { role: 'assistant', content: response.content };
|
||||
|
||||
@@ -59,4 +66,12 @@ export class NativeAgent {
|
||||
getHistory(): Message[] {
|
||||
return [...this.history];
|
||||
}
|
||||
|
||||
setModelTier(tier: ModelTier): void {
|
||||
this.currentTier = tier;
|
||||
}
|
||||
|
||||
getModelTier(): ModelTier {
|
||||
return this.currentTier;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user