fix: refine experimental_transform handling and improve chunking logic

- Updated PluginEnabledAiClient to streamline the handling of experimental_transform parameters.
- Adjusted ModernAiProvider's smoothStream configuration for better chunking of text, enhancing processing efficiency.
- Re-enabled block updates in messageThunk for improved state management.
This commit is contained in:
MyPrototypeWhat 2025-06-20 17:36:39 +08:00
parent 02bcf03da9
commit 3d2caaf96a
3 changed files with 9 additions and 4 deletions

View File

@ -213,10 +213,13 @@ export class PluginEnabledAiClient<T extends ProviderId = ProviderId> {
params!, params!,
async (finalModelId, transformedParams, streamTransforms) => { async (finalModelId, transformedParams, streamTransforms) => {
const model = await this.getModelWithMiddlewares(finalModelId) const model = await this.getModelWithMiddlewares(finalModelId)
const experimental_transform =
params?.experimental_transform ?? (streamTransforms.length > 0 ? streamTransforms : undefined)
return await streamText({ return await streamText({
model, model,
...transformedParams, ...transformedParams,
experimental_transform: streamTransforms.length > 0 ? streamTransforms : undefined experimental_transform
}) })
} }
) )

View File

@ -178,8 +178,9 @@ export default class ModernAiProvider {
const streamResult = await clientWithMiddlewares.streamText(modelId, { const streamResult = await clientWithMiddlewares.streamText(modelId, {
...params, ...params,
experimental_transform: smoothStream({ experimental_transform: smoothStream({
delayInMs: 100, delayInMs: 80,
chunking: 'word' // 中文3个字符一个chunk,英文一个单词一个chunk
chunking: /([\u4E00-\u9FFF]{3})|\S+\s+/
}) })
}) })
const finalText = await adapter.processStream(streamResult) const finalText = await adapter.processStream(streamResult)

View File

@ -147,7 +147,7 @@ const getBlockThrottler = (id: string) => {
} }
const rafId = requestAnimationFrame(() => { const rafId = requestAnimationFrame(() => {
store.dispatch(updateOneBlock({ id, changes: blockUpdate })) // store.dispatch(updateOneBlock({ id, changes: blockUpdate }))
blockUpdateRafs.delete(id) blockUpdateRafs.delete(id)
}) })
@ -166,6 +166,7 @@ const getBlockThrottler = (id: string) => {
*/ */
const throttledBlockUpdate = (id: string, blockUpdate: any) => { const throttledBlockUpdate = (id: string, blockUpdate: any) => {
const throttler = getBlockThrottler(id) const throttler = getBlockThrottler(id)
store.dispatch(updateOneBlock({ id, changes: blockUpdate }))
throttler(blockUpdate) throttler(blockUpdate)
} }