Skip to content

Commit b6520b0

Browse files
committed
hotfix: Fix an issue where Ask AI was crashing on some requests.
1 parent 9fe8142 commit b6520b0

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/gitbook/src/components/Search/SearchAskAnswer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ function AnswerBody(props: { answer: AskAnswerResult }) {
167167
'dark:text-light/8',
168168
)}
169169
>
170-
{answer.hasAnswer ? answer.body : t(language, 'search_ask_no_answer')}
170+
{answer.body ?? t(language, 'search_ask_no_answer')}
171171
{answer.followupQuestions.length > 0 ? (
172172
<AnswerFollowupQuestions followupQuestions={answer.followupQuestions} />
173173
) : null}
174174
</div>
175175
{answer.sources.length > 0 ? (
176176
<AnswerSources
177-
hasAnswer={answer.hasAnswer}
178177
sources={answer.sources}
179178
language={language}
179+
hasAnswer={Boolean(answer.body)}
180180
/>
181181
) : null}
182182
</>
@@ -233,7 +233,7 @@ function AnswerFollowupQuestions(props: { followupQuestions: string[] }) {
233233
function AnswerSources(props: {
234234
sources: AskAnswerSource[];
235235
language: TranslationLanguage;
236-
hasAnswer?: boolean;
236+
hasAnswer: boolean;
237237
}) {
238238
const { sources, language, hasAnswer } = props;
239239

packages/gitbook/src/components/Search/server-actions.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export interface AskAnswerSource {
4040
}
4141

4242
export interface AskAnswerResult {
43+
/** Undefined if no answer. */
4344
body?: React.ReactNode;
4445
followupQuestions: string[];
4546
sources: AskAnswerSource[];
46-
hasAnswer: boolean;
4747
}
4848

4949
/**
@@ -181,7 +181,12 @@ export const streamAskQuestion = streamResponse(async function* (
181181

182182
const spaceData = new Map<string, RevisionPage[]>();
183183
for await (const chunk of stream) {
184-
yield transformAnswer(chunk.answer, spaceData);
184+
if (!chunk) {
185+
continue;
186+
}
187+
188+
const encoded = await transformAnswer(chunk.answer, spaceData);
189+
yield encoded;
185190
}
186191
});
187192

@@ -223,7 +228,7 @@ async function transformAnswer(
223228
const { pages } = await api.getSpaceContentData({ spaceId }, undefined);
224229
spaceData.set(spaceId, pages);
225230
},
226-
{ concurrency: 3 },
231+
{ concurrency: 1 },
227232
);
228233

229234
const sources = answer.sources
@@ -267,7 +272,6 @@ async function transformAnswer(
267272
) : null,
268273
followupQuestions: answer.followupQuestions,
269274
sources,
270-
hasAnswer: !!answer.answer && 'document' in answer.answer,
271275
};
272276
}
273277

0 commit comments

Comments
 (0)