Class OpenAiStreamFunctionCallingHelper

java.lang.Object
org.springframework.ai.openai.api.OpenAiStreamFunctionCallingHelper

public class OpenAiStreamFunctionCallingHelper extends Object
Helper class to support Streaming function calling. It can merge the streamed ChatCompletionChunk in case of function calling message.
Since:
0.8.1
Author:
Christian Tzolov
  • Constructor Details

    • OpenAiStreamFunctionCallingHelper

      public OpenAiStreamFunctionCallingHelper()
  • Method Details

    • merge

      Merge the previous and current ChatCompletionChunk into a single one.
      Parameters:
      previous - the previous ChatCompletionChunk
      current - the current ChatCompletionChunk
      Returns:
      the merged ChatCompletionChunk
    • isStreamingToolFunctionCall

      public boolean isStreamingToolFunctionCall(OpenAiApi.ChatCompletionChunk chatCompletion)
      Parameters:
      chatCompletion - the ChatCompletionChunk to check
      Returns:
      true if the ChatCompletionChunk is a streaming tool function call.
    • isStreamingToolFunctionCallFinish

      public boolean isStreamingToolFunctionCallFinish(OpenAiApi.ChatCompletionChunk chatCompletion)
      Parameters:
      chatCompletion - the ChatCompletionChunk to check
      Returns:
      true if the ChatCompletionChunk is a streaming tool function call and it is the last one.
    • chunkToChatCompletion

      public OpenAiApi.ChatCompletion chunkToChatCompletion(OpenAiApi.ChatCompletionChunk chunk)
      Convert the ChatCompletionChunk into a ChatCompletion. The Usage is set to null.
      Parameters:
      chunk - the ChatCompletionChunk to convert
      Returns:
      the ChatCompletion