Class ZhiPuAiStreamFunctionCallingHelper

java.lang.Object
org.springframework.ai.zhipuai.api.ZhiPuAiStreamFunctionCallingHelper

public class ZhiPuAiStreamFunctionCallingHelper extends Object
Helper class to support Streaming function calling. It can merge the streamed ChatCompletionChunk in case of function calling message.
Since:
1.0.0 M1
Author:
Geng Rong
  • Constructor Details

    • ZhiPuAiStreamFunctionCallingHelper

      public ZhiPuAiStreamFunctionCallingHelper()
  • 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(ZhiPuAiApi.ChatCompletionChunk chatCompletion)
      Parameters:
      chatCompletion - the ChatCompletionChunk to check
      Returns:
      true if the ChatCompletionChunk is a streaming tool function call.
    • isStreamingToolFunctionCallFinish

      public boolean isStreamingToolFunctionCallFinish(ZhiPuAiApi.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 ZhiPuAiApi.ChatCompletion chunkToChatCompletion(ZhiPuAiApi.ChatCompletionChunk chunk)
      Convert the ChatCompletionChunk into a ChatCompletion. The Usage is set to null.
      Parameters:
      chunk - the ChatCompletionChunk to convert
      Returns:
      the ChatCompletion