Class DashScopeAiStreamFunctionCallingHelper
java.lang.Object
com.alibaba.cloud.ai.dashscope.api.DashScopeAiStreamFunctionCallingHelper
Helper class to support Streaming function calling. It can merge the streamed
ChatCompletionChunk in case of function calling message.
- Author:
- Ken
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvert the ChatCompletionChunk into a ChatCompletion.booleanisStreamingToolFunctionCall(DashScopeApiSpec.ChatCompletionChunk chatCompletion) booleanmerge(DashScopeApiSpec.ChatCompletionChunk previous, DashScopeApiSpec.ChatCompletionChunk current) Merge the previous and current ChatCompletionChunk into a single one.
-
Constructor Details
-
DashScopeAiStreamFunctionCallingHelper
public DashScopeAiStreamFunctionCallingHelper() -
DashScopeAiStreamFunctionCallingHelper
-
-
Method Details
-
merge
public DashScopeApiSpec.ChatCompletionChunk merge(DashScopeApiSpec.ChatCompletionChunk previous, DashScopeApiSpec.ChatCompletionChunk current) Merge the previous and current ChatCompletionChunk into a single one.- Parameters:
previous- the previous ChatCompletionChunkcurrent- the current ChatCompletionChunk- Returns:
- the merged ChatCompletionChunk
-
isStreamingToolFunctionCall
- Parameters:
chatCompletion- the ChatCompletionChunk to check- Returns:
- true if the ChatCompletionChunk is a streaming tool function call.
-
isStreamingToolFunctionCallFinish
public boolean isStreamingToolFunctionCallFinish(DashScopeApiSpec.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 DashScopeApiSpec.ChatCompletion chunkToChatCompletion(DashScopeApiSpec.ChatCompletionChunk chunk) Convert the ChatCompletionChunk into a ChatCompletion. The Usage is set to null.- Parameters:
chunk- the ChatCompletionChunk to convert- Returns:
- the ChatCompletion
-