Skip to content

Commit

Permalink
Fixes key verification for Azure OpenAI API, and customizes placehold…
Browse files Browse the repository at this point in the history
…er text and helpURL.
  • Loading branch information
bruffridge committed Nov 1, 2024
1 parent 37d9dfa commit dbe6f3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion component/src/services/azure/azureOpenAIAssistantIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class AzureOpenAIAssistantIO extends OpenAIAssistantIOI {
private static readonly THREAD_RESOURCE = `threads`;
private static readonly NEW_ASSISTANT_RESOURCE = 'assistants';
override permittedErrorPrefixes: string[] = [AzureOpenAIUtils.URL_DETAILS_ERROR_MESSAGE];
override insertKeyPlaceholderText = 'Azure OpenAI API Key';
override keyHelpUrl = 'https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key';
isTextInputDisabled = false;

constructor(deepChat: DeepChat) {
Expand All @@ -28,7 +30,7 @@ export class AzureOpenAIAssistantIO extends OpenAIAssistantIOI {
getFilesPostfix: `/content${commonPostfix}`,
};

super(deepChat, config?.assistant, urlSegments, AzureOpenAIUtils.buildHeaders, apiKey);
super(deepChat, config?.assistant, urlSegments, AzureOpenAIUtils.buildKeyVerificationDetails(urlDetails), AzureOpenAIUtils.buildHeaders, apiKey);

if (!AzureOpenAIUtils.validateURLDetails(urlDetails)) {
this.isTextInputDisabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class OpenAIAssistantIO extends OpenAIAssistantIOI {
const directConnectionCopy = JSON.parse(JSON.stringify(deepChat.directConnection)) as DirectConnection;
const apiKey = directConnectionCopy.openAI;
const config = directConnectionCopy.openAI?.assistant;
super(deepChat, config, OpenAIAssistantIO.URL_SEGMENTS, OpenAIUtils.buildHeaders, apiKey);
super(deepChat, config, OpenAIAssistantIO.URL_SEGMENTS, OpenAIUtils.buildKeyVerificationDetails(), OpenAIUtils.buildHeaders, apiKey);
this.connectSettings.headers ??= {};
this.connectSettings.headers['OpenAI-Beta'] ??= 'assistants=v2'; // runs keep failing but keep trying
if (this.shouldFetchHistory && this.sessionId) this.fetchHistory = this.fetchHistoryFunc.bind(this);
Expand Down
5 changes: 3 additions & 2 deletions component/src/services/openAI/assistant/openAIAssistantIOI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../../../types/openAIResult';
import {APIKey} from '../../../types/APIKey';
import {BuildHeadersFunc} from '../../../types/headers';
import { KeyVerificationDetails } from '../../../types/keyVerificationDetails';

// https://platform.openai.com/docs/api-reference/messages/createMessage
type MessageContentArr = {
Expand Down Expand Up @@ -68,8 +69,8 @@ export class OpenAIAssistantIOI extends DirectServiceIO {
private messageStream: MessageStream | undefined;
private readonly filesToolType: OpenAIAssistant['files_tool_type'];

constructor(deepChat: DeepChat, config: OpenAI['assistant'], urlSegments: URLSegments, buildHeadersFunc: BuildHeadersFunc, apiKey?: APIKey) {
super(deepChat, OpenAIUtils.buildKeyVerificationDetails(), buildHeadersFunc, apiKey);
constructor(deepChat: DeepChat, config: OpenAI['assistant'], urlSegments: URLSegments, keyVerificationDetails: KeyVerificationDetails, buildHeadersFunc: BuildHeadersFunc, apiKey?: APIKey) {
super(deepChat, keyVerificationDetails, buildHeadersFunc, apiKey);
this.urlSegments = urlSegments;
if (typeof config === 'object') {
this.config = config; // stored that assistant_id could be added
Expand Down

0 comments on commit dbe6f3a

Please sign in to comment.