Skip to content

Commit

Permalink
Merge pull request #292 from bruffridge/azure-header-fix
Browse files Browse the repository at this point in the history
Fixed issues related to Azure OpenAI API
  • Loading branch information
OvidijusParsiunas authored Nov 2, 2024
2 parents f02b71b + dbe6f3a commit 6beeccb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions 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 @@ -21,14 +23,14 @@ export class AzureOpenAIAssistantIO extends OpenAIAssistantIOI {
threadsPrefix: `${commonPrefix}${AzureOpenAIAssistantIO.THREAD_RESOURCE}`,
threadsPosfix: commonPostfix,
newAssistantUrl: `${commonPrefix}${AzureOpenAIAssistantIO.NEW_ASSISTANT_RESOURCE}${commonPostfix}`,
createMessagePostfix: `?order=desc&api-version=${config?.urlDetails?.version}`,
listMessagesPostfix: commonPostfix,
createMessagePostfix: commonPostfix,
listMessagesPostfix: `order=desc&api-version=${config?.urlDetails?.version}`,
storeFiles: `${commonPrefix}files${commonPostfix}`,
getFilesPrefix: `${commonPrefix}files/`,
getFilesPostfix: `/content${commonPostfix}`,
};

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

if (!AzureOpenAIUtils.validateURLDetails(urlDetails)) {
this.isTextInputDisabled = true;
Expand Down
3 changes: 2 additions & 1 deletion component/src/services/openAI/assistant/openAIAssistantIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {DirectConnection} from '../../../types/directConnection';
import {Response as ResponseI} from '../../../types/response';
import {OpenAIAssistantIOI} from './openAIAssistantIOI';
import {DeepChat} from '../../../deepChat';
import {OpenAIUtils} from '../utils/openAIUtils';

export class OpenAIAssistantIO extends OpenAIAssistantIOI {
fetchHistory?: () => Promise<ResponseI[]>;
Expand All @@ -20,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, 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
8 changes: 5 additions & 3 deletions component/src/services/openAI/assistant/openAIAssistantIOI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
ToolCalls,
} 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 @@ -66,9 +68,9 @@ export class OpenAIAssistantIOI extends DirectServiceIO {
private readonly urlSegments: URLSegments;
private messageStream: MessageStream | undefined;
private readonly filesToolType: OpenAIAssistant['files_tool_type'];

constructor(deepChat: DeepChat, config: OpenAI['assistant'], urlSegments: URLSegments, apiKey?: APIKey) {
super(deepChat, OpenAIUtils.buildKeyVerificationDetails(), OpenAIUtils.buildHeaders, 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 6beeccb

Please sign in to comment.