sashirestela / simple-openai

A Java library to use the OpenAI Api in the simplest possible way.
MIT License
149 stars 15 forks source link

ToolCallsStep structure changed #192

Closed zhengzheli closed 5 hours ago

zhengzheli commented 6 hours ago

It seems that the thread run step delta step detail has changed its structure. Now type is null and instead it is replaced with a property named according to the tool being called, i.e. fileSearch or function. Could you please change the ToolCallsStep class to match?

private void handleRunEvents(SseEmitter emitter, Stream<Event> runStream, String chatId, String entityName, Integer entityType, String fileId, String question, String username){
        runStream.forEach(event -> {
            switch (event.getName()) {
                case EventName.THREAD_RUN_STEP_DELTA:
                    log.info("Thread run step delta");
                    ThreadRunStepDelta step = (ThreadRunStepDelta) event.getData();
                    var stepDetail = step.getDelta().getStepDetails();
                    if(stepDetail instanceof ToolCallsStep){
                        ToolCallsStep toolCallStep = (ToolCallsStep)step.getDelta().getStepDetails();
                        ToolType type = toolCallStep.getToolCalls().get(0).getType();
                        if(type == ToolType.FILE_SEARCH){
                            log.info("Running file search");
                        }
                        else if (type == ToolType.FUNCTION){
                            log.info("Running function");
                        }else{
                            log.info("function id: " + toolCallStep.getToolCalls().get(0).getId());
                        }
                    }
                    break;

  image image image

zhengzheli commented 5 hours ago

Oh sorry, my fault, I needed to cast the inner StepToolCall object as a FileSearchToolCall or as a FunctionToolCall