Function Calling - Stumped over forced function

I have been struggling with this all day.

function calling has been working great. In one particular situation, I am setting a flag and calling a specific function back. When I force call that specific function , I am seeing that the assistant content is null.

I decided then to have that function call openAI chat completions for a response which is working fine but my final content is null.

my high level code is

const runner = client.beta.chat.completions
.runTools({
model: “gpt-3.5-turbo-0613”,
tool_choice:
if flag then set tool_choice to “functionC”
})
.on(“message”, (message) => console.log(message));

finalContent = await runner.finalContent();

function A

function B

function C {
{ set flag to true}
call openAI chatCompletions
return response

}

  1. Why is content null for assistant when function is forced. is it because, it doesnt use function calling?
  2. IN that case, why is finalContent null instead of content from second openAI call from function C

logs:
Function call event triggered for: customSolutionBuilder
:rocket: ~ file: aiProcessingFunction.js:314 ~ customSolutionBuilder ~ interactionCount: 2
:rocket: ~ file: advancedSolutionGenerator.js:9 ~ advancedSolutionGenerator ~ userQuery: vibration sensors
:rocket: ~ file: aiProcessingFunction.js:314 ~ customSolutionBuilder ~ interactionCount: 2
:rocket: ~ file: advancedSolutionGenerator.js:9 ~ advancedSolutionGenerator ~ userQuery: vibration sensors
:rocket: ~ file: advancedSolutionGenerator.js:35 ~ advancedSolutionGenerator ~ generatedQuestion: How do you plan on integrating and managing a large number of vibration sensors within your industrial IoT solution, considering factors such as device compatibility, connectivity requirements, data ingestion methods, and analytics capabilities?
:rocket: ~ file: aiProcessingFunction.js:321 ~ customSolutionBuilder ~ questionResponse: {
message: 'How do you plan on integrating and managing a large number of vibration sensors within your industrial IoT solution, considering factors such as device compatibility, connectivity requirements, data ingestion methods, and analytics capabilities? ',
flag: ‘advanced_solutions’
}
:rocket: ~ file: aiProcessingFunction.js:234 ~ eventHandler ~ customSolutionBuilderResponse: {
message: 'How do you plan on integrating and managing a large number of vibration sensors within your industrial IoT solution, considering factors such as device compatibility, connectivity requirements, data ingestion methods, and analytics capabilities? ',
flag: ‘advanced_solutions’
}
Response identified from advancedSolutionGenerator {
message: 'How do you plan on integrating and managing a large number of vibration sensors within your industrial IoT solution, considering factors such as device compatibility, connectivity requirements, data ingestion methods, and analytics capabilities? ',
flag: ‘advanced_solutions’
}
Flag status: advanced_solutions
:rocket: ~ file: advancedSolutionGenerator.js:35 ~ advancedSolutionGenerator ~ generatedQuestion: What specific challenges or objectives does the user intend to address with vibration sensors in their industrial IoT solution, and what is their strategy for data utilization towards maintenance and management?
:rocket: ~ file: aiProcessingFunction.js:321 ~ customSolutionBuilder ~ questionResponse: {
message: 'What specific challenges or objectives does the user intend to address with vibration sensors in their industrial IoT solution, and what is their strategy for data utilization towards maintenance and management? ',
flag: ‘advanced_solutions’
}
{
role: ‘tool’,
tool_call_id: ‘call_randomID1234’,
content: ‘{“message”:"What specific challenges or objectives does the user intend to address with vibration sensors in their industrial IoT solution, and what is their strategy for data utilization towards maintenance and management? ",“flag”:“advanced_solutions”}’
}
{
role: ‘tool’,
tool_call_id: ‘call_randomID1234’,
content: ‘{“message”:"What specific challenges or objectives does the user intend to address with vibration sensors in their industrial IoT solution, and what is their strategy for data utilization towards maintenance and management? ",“flag”:“advanced_solutions”}’
}
:rocket: ~ file: aiProcessingFunction.js:269 ~ eventHandler ~ finalContent: {“message”:"What specific challenges or objectives does the user intend to address with vibration sensors in their industrial IoT solution, and what is their strategy for data utilization towards maintenance and management? ",“flag”:“advanced_solutions”}
Flag status at end: advanced_solutions
:rocket: ~ file: aiProcessingFunction.js:292 ~ finalContent: null

Without probing what actually happens, we can guess that OpenAI doesn’t want to expose the inner workings (and foibles) of AI-emitted language.

While a tool call that results in “requires_action” status is indeed AI-generated language, stored as part of the thread (the assistant doesn’t have to keep retrieving every question) what the AI wrote is abstracted away even when using chatcompletions API.

The AI can answer the user as seen “assistant” when it gets its tool return from you.

After tool return, are you sure you’ve polled the run status and waited for it finally to change to “completed”, only then getting the assistant answer?

Thanks so much for the response. Can you share some details on how to poll the run status ? Very helpful. Thanks

Here’s an API reference link directly into the relevant part: getting back a run’s object with metadata.

https://platform.openai.com/docs/api-reference/runs/getRun

Then you can also read the two-dozen other methods and see how they might be used or required in parts of code that progress through the process of having the AI answer “hello”.

BTW. Mandatory function calling is a bit outside of how the AI has been trained. The type of user question and the descriptions of functions should let it decide when a function is useful, then requiring that return value to continue.