Skip to content

Commit

Permalink
fix: also check online model list if model not defined (#8726)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit authored and forehalo committed Nov 12, 2024
1 parent b052743 commit 2335e8a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/backend/server/src/plugins/copilot/providers/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class OpenAIProvider
});
}

protected checkParams({
protected async checkParams({
messages,
embeddings,
model,
Expand All @@ -134,7 +134,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) {
Expand Down Expand Up @@ -203,7 +203,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 {
const result = await this.instance.chat.completions.create(
Expand Down Expand Up @@ -232,7 +232,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 {
const result = await this.instance.chat.completions.create(
Expand Down Expand Up @@ -280,7 +280,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 {
const result = await this.instance.embeddings.create({
Expand Down

0 comments on commit 2335e8a

Please sign in to comment.