fix: also check online model list if model not defined (#8726)

This commit is contained in:
darkskygit 2024-11-08 05:07:45 +00:00
parent c323e5ae93
commit 2a3e81de3e
No known key found for this signature in database
GPG Key ID: 97B7D036B1566E9D

View File

@ -126,7 +126,7 @@ export class OpenAIProvider
});
}
protected checkParams({
protected async checkParams({
messages,
embeddings,
model,
@ -137,7 +137,7 @@ export class OpenAIProvider
model: string;
options: CopilotChatOptions;
}) {
if (!this.availableModels.includes(model)) {
if (!(await this.isModelAvailable(model))) {
throw new CopilotPromptInvalid(`Invalid model: ${model}`);
}
if (Array.isArray(messages) && messages.length > 0) {
@ -219,7 +219,7 @@ export class OpenAIProvider
model: string = 'gpt-4o-mini',
options: CopilotChatOptions = {}
): Promise<string> {
this.checkParams({ messages, model, options });
await this.checkParams({ messages, model, options });
try {
metrics.ai.counter('chat_text_calls').add(1, { model });
@ -250,7 +250,7 @@ export class OpenAIProvider
model: string = 'gpt-4o-mini',
options: CopilotChatOptions = {}
): AsyncIterable<string> {
this.checkParams({ messages, model, options });
await this.checkParams({ messages, model, options });
try {
metrics.ai.counter('chat_text_stream_calls').add(1, { model });
@ -300,7 +300,7 @@ export class OpenAIProvider
options: CopilotEmbeddingOptions = { dimensions: DEFAULT_DIMENSIONS }
): Promise<number[][]> {
messages = Array.isArray(messages) ? messages : [messages];
this.checkParams({ embeddings: messages, model, options });
await this.checkParams({ embeddings: messages, model, options });
try {
metrics.ai.counter('generate_embedding_calls').add(1, { model });