Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues related to Azure OpenAI API #292

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading