mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 06:19:05 +08:00
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:
parent
02bcf03da9
commit
3d2caaf96a
@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user