fix: also check online model list if model not defined (#8726)
This commit is contained in:
@@ -126,7 +126,7 @@ export class OpenAIProvider
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected checkParams({
|
protected async checkParams({
|
||||||
messages,
|
messages,
|
||||||
embeddings,
|
embeddings,
|
||||||
model,
|
model,
|
||||||
@@ -137,7 +137,7 @@ export class OpenAIProvider
|
|||||||
model: string;
|
model: string;
|
||||||
options: CopilotChatOptions;
|
options: CopilotChatOptions;
|
||||||
}) {
|
}) {
|
||||||
if (!this.availableModels.includes(model)) {
|
if (!(await this.isModelAvailable(model))) {
|
||||||
throw new CopilotPromptInvalid(`Invalid model: ${model}`);
|
throw new CopilotPromptInvalid(`Invalid model: ${model}`);
|
||||||
}
|
}
|
||||||
if (Array.isArray(messages) && messages.length > 0) {
|
if (Array.isArray(messages) && messages.length > 0) {
|
||||||
@@ -219,7 +219,7 @@ export class OpenAIProvider
|
|||||||
model: string = 'gpt-4o-mini',
|
model: string = 'gpt-4o-mini',
|
||||||
options: CopilotChatOptions = {}
|
options: CopilotChatOptions = {}
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
this.checkParams({ messages, model, options });
|
await this.checkParams({ messages, model, options });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
metrics.ai.counter('chat_text_calls').add(1, { model });
|
metrics.ai.counter('chat_text_calls').add(1, { model });
|
||||||
@@ -250,7 +250,7 @@ export class OpenAIProvider
|
|||||||
model: string = 'gpt-4o-mini',
|
model: string = 'gpt-4o-mini',
|
||||||
options: CopilotChatOptions = {}
|
options: CopilotChatOptions = {}
|
||||||
): AsyncIterable<string> {
|
): AsyncIterable<string> {
|
||||||
this.checkParams({ messages, model, options });
|
await this.checkParams({ messages, model, options });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
metrics.ai.counter('chat_text_stream_calls').add(1, { model });
|
metrics.ai.counter('chat_text_stream_calls').add(1, { model });
|
||||||
@@ -300,7 +300,7 @@ export class OpenAIProvider
|
|||||||
options: CopilotEmbeddingOptions = { dimensions: DEFAULT_DIMENSIONS }
|
options: CopilotEmbeddingOptions = { dimensions: DEFAULT_DIMENSIONS }
|
||||||
): Promise<number[][]> {
|
): Promise<number[][]> {
|
||||||
messages = Array.isArray(messages) ? messages : [messages];
|
messages = Array.isArray(messages) ? messages : [messages];
|
||||||
this.checkParams({ embeddings: messages, model, options });
|
await this.checkParams({ embeddings: messages, model, options });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
metrics.ai.counter('generate_embedding_calls').add(1, { model });
|
metrics.ai.counter('generate_embedding_calls').add(1, { model });
|
||||||
|
|||||||
Reference in New Issue
Block a user