Skip to content

Commit

Permalink
fixing bug where defining Azure OpenAI implementation as boolean true…
Browse files Browse the repository at this point in the history
… would throw an error
  • Loading branch information
OvidijusParsiunas committed Nov 14, 2024
1 parent 55d381f commit abbe915
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions component/src/services/azure/azureOpenAIAssistantIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ export class AzureOpenAIAssistantIO extends OpenAIAssistantIOI {
super(deepChat, config?.assistant, urlSegments,
AzureOpenAIUtils.buildKeyVerificationDetails(urlDetails), AzureOpenAIUtils.buildHeaders, apiKey);

if (typeof config === 'object') {
const {function_handler} = deepChat.directConnection?.azure?.openAI?.assistant as OpenAIAssistant;
if (function_handler) this._functionHandler = function_handler;
const {files_tool_type} = deepChat.directConnection?.azure?.openAI?.assistant as OpenAIAssistant;
if (typeof config?.assistant === 'object') {
const {function_handler, files_tool_type} = deepChat.directConnection?.azure?.openAI?.assistant as OpenAIAssistant;
if (function_handler) this.functionHandler = function_handler;
if (files_tool_type) this.filesToolType = files_tool_type;
}
if (!AzureOpenAIUtils.validateURLDetails(urlDetails)) {
Expand Down
5 changes: 2 additions & 3 deletions component/src/services/openAI/assistant/openAIAssistantIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export class OpenAIAssistantIO extends OpenAIAssistantIOI {
this.connectSettings.headers['OpenAI-Beta'] ??= 'assistants=v2'; // runs keep failing but keep trying
if (this.shouldFetchHistory && this.sessionId) this.fetchHistory = this.fetchHistoryFunc.bind(this);
if (typeof config === 'object') {
const {function_handler} = deepChat.directConnection?.openAI?.assistant as OpenAIAssistant;
if (function_handler) this._functionHandler = function_handler;
const {files_tool_type} = deepChat.directConnection?.openAI?.assistant as OpenAIAssistant;
const {function_handler, files_tool_type} = deepChat.directConnection?.openAI?.assistant as OpenAIAssistant;
if (function_handler) this.functionHandler = function_handler;
if (files_tool_type) this.filesToolType = files_tool_type;
}
}
Expand Down
8 changes: 4 additions & 4 deletions component/src/services/openAI/assistant/openAIAssistantIOI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export class OpenAIAssistantIOI extends DirectServiceIO {
override keyHelpUrl = 'https://platform.openai.com/account/api-keys';
url = ''; // set dynamically
private static readonly POLLING_TIMEOUT_MS = 800;
_functionHandler?: AssistantFunctionHandler;
permittedErrorPrefixes = ['Incorrect', 'Please send text', History.FAILED_ERROR_MESSAGE];
functionHandler?: AssistantFunctionHandler;
filesToolType: OpenAIAssistant['files_tool_type'];
readonly shouldFetchHistory: boolean = false;
private messages?: Messages;
private run_id?: string;
Expand All @@ -67,7 +68,6 @@ export class OpenAIAssistantIOI extends DirectServiceIO {
private readonly isSSEStream: boolean = false;
private readonly urlSegments: URLSegments;
private messageStream: MessageStream | undefined;
filesToolType: OpenAIAssistant['files_tool_type'];

// prettier-ignore
constructor(deepChat: DeepChat, config: OpenAI['assistant'], urlSegments: URLSegments,
Expand Down Expand Up @@ -293,7 +293,7 @@ export class OpenAIAssistantIOI extends DirectServiceIO {

// prettier-ignore
private async handleTools(toolCalls: ToolCalls): PollResult {
if (!this._functionHandler) {
if (!this.functionHandler) {
throw Error(
'Please define the `function_handler` property inside' +
' the [openAI](https://deepchat.dev/docs/directConnection/openAI#Assistant) object.'
Expand All @@ -302,7 +302,7 @@ export class OpenAIAssistantIOI extends DirectServiceIO {
const functions = toolCalls.map((call) => {
return {name: call.function.name, arguments: call.function.arguments};
});
const handlerResponse = await this._functionHandler(functions);
const handlerResponse = await this.functionHandler(functions);
if (!Array.isArray(handlerResponse) || toolCalls.length !== handlerResponse.length) {
throw Error(OpenAIAssistantUtils.FUNCTION_TOOL_RESP_ERROR);
}
Expand Down

0 comments on commit abbe915

Please sign in to comment.