Skip to content

Commit d283ceb

Browse files
committed
improve openai performance
1 parent 882ff9f commit d283ceb

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

src/config/modelProviders/openai.ts

+3
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ const OpenAI: ModelProviderCard = {
301301
name: 'OpenAI',
302302
settings: {
303303
showModelFetcher: true,
304+
smoothing: {
305+
text: true,
306+
},
304307
},
305308
url: 'https://openai.com',
306309
};

src/features/Conversation/components/MarkdownElements/LobeArtifact/Render/index.tsx

+51-52
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ const Render = memo<ArtifactProps>(({ identifier, title, type, language, childre
6464

6565
const inThread = useContext(InPortalThreadContext);
6666
const { message } = App.useApp();
67-
const [isGenerating, isArtifactTagClosed, currentArtifactMessageId, openArtifact, closeArtifact] =
68-
useChatStore((s) => {
69-
return [
70-
chatSelectors.isMessageGenerating(id)(s),
71-
chatPortalSelectors.isArtifactTagClosed(id)(s),
72-
chatPortalSelectors.artifactMessageId(s),
73-
s.openArtifact,
74-
s.closeArtifact,
75-
];
76-
});
67+
const [isGenerating, isArtifactTagClosed, openArtifact, closeArtifact] = useChatStore((s) => {
68+
return [
69+
chatSelectors.isMessageGenerating(id)(s),
70+
chatPortalSelectors.isArtifactTagClosed(id)(s),
71+
s.openArtifact,
72+
s.closeArtifact,
73+
];
74+
});
7775

7876
const openArtifactUI = () => {
7977
openArtifact({ id, identifier, language, title, type });
@@ -86,52 +84,53 @@ const Render = memo<ArtifactProps>(({ identifier, title, type, language, childre
8684
}, [isGenerating, hasChildren, str, identifier, title, type, id, language]);
8785

8886
return (
89-
<p>
90-
<Flexbox
91-
className={styles.container}
92-
gap={16}
93-
onClick={() => {
94-
if (currentArtifactMessageId === id) {
95-
closeArtifact();
96-
} else {
97-
if (inThread) {
98-
message.info(t('artifact.inThread'));
99-
return;
100-
}
101-
openArtifactUI();
87+
<Flexbox
88+
className={styles.container}
89+
gap={16}
90+
onClick={() => {
91+
const currentArtifactMessageId = chatPortalSelectors.artifactMessageId(
92+
useChatStore.getState(),
93+
);
94+
if (currentArtifactMessageId === id) {
95+
closeArtifact();
96+
} else {
97+
if (inThread) {
98+
message.info(t('artifact.inThread'));
99+
return;
102100
}
103-
}}
104-
width={'100%'}
105-
>
106-
<Flexbox align={'center'} flex={1} horizontal>
107-
<Center className={styles.avatar} height={64} horizontal width={64}>
108-
<ArtifactIcon type={type} />
109-
</Center>
110-
<Flexbox gap={4} paddingBlock={8} paddingInline={12}>
111-
{!title && isGenerating ? (
112-
<Flexbox className={cx(dotLoading)} horizontal>
113-
{t('artifact.generating')}
101+
openArtifactUI();
102+
}
103+
}}
104+
width={'100%'}
105+
>
106+
<Flexbox align={'center'} flex={1} horizontal>
107+
<Center className={styles.avatar} height={64} horizontal width={64}>
108+
<ArtifactIcon type={type} />
109+
</Center>
110+
<Flexbox gap={4} paddingBlock={8} paddingInline={12}>
111+
{!title && isGenerating ? (
112+
<Flexbox className={cx(dotLoading)} horizontal>
113+
{t('artifact.generating')}
114+
</Flexbox>
115+
) : (
116+
<Flexbox className={cx(styles.title)}>{title || t('artifact.unknownTitle')}</Flexbox>
117+
)}
118+
{hasChildren && (
119+
<Flexbox className={styles.desc} horizontal>
120+
{identifier} ·{' '}
121+
<Flexbox gap={2} horizontal>
122+
{!isArtifactTagClosed && (
123+
<div>
124+
<Icon icon={Loader2} spin />
125+
</div>
126+
)}
127+
{str?.length}
114128
</Flexbox>
115-
) : (
116-
<Flexbox className={cx(styles.title)}>{title || t('artifact.unknownTitle')}</Flexbox>
117-
)}
118-
{hasChildren && (
119-
<Flexbox className={styles.desc} horizontal>
120-
{identifier} ·{' '}
121-
<Flexbox gap={2} horizontal>
122-
{!isArtifactTagClosed && (
123-
<div>
124-
<Icon icon={Loader2} spin />
125-
</div>
126-
)}
127-
{str?.length}
128-
</Flexbox>
129-
</Flexbox>
130-
)}
131-
</Flexbox>
129+
</Flexbox>
130+
)}
132131
</Flexbox>
133132
</Flexbox>
134-
</p>
133+
</Flexbox>
135134
);
136135
});
137136

src/utils/fetch/fetchSSE.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export const fetchSSE = async (url: string, options: RequestInit & FetchSSEOptio
296296

297297
const { smoothing } = options;
298298

299-
const textSmoothing = typeof smoothing === 'boolean' ? smoothing : smoothing?.text;
299+
const textSmoothing = typeof smoothing === 'boolean' ? smoothing : (smoothing?.text ?? true);
300300
const toolsCallingSmoothing =
301301
typeof smoothing === 'boolean' ? smoothing : (smoothing?.toolsCalling ?? true);
302302
const smoothingSpeed = isObject(smoothing) ? smoothing.speed : undefined;

0 commit comments

Comments
 (0)