Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: search and ask AI #2889

Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
SamyPesse committed Feb 27, 2025
commit aaecfeee3768e3f58e0dc55f769af0577cc0128a
7 changes: 3 additions & 4 deletions packages/gitbook/src/components/Search/SearchAskAnswer.tsx
Original file line number Diff line number Diff line change
@@ -33,13 +33,12 @@ export type SearchAskState =
* Fetch and render the answers to a question.
*/
export function SearchAskAnswer(props: { pointer: SiteContentPointer; query: string }) {
const { pointer, query } = props;
const { query } = props;

const language = useLanguage();
const trackEvent = useTrackEvent();
const [, setSearchState] = useSearch();
const [askState, setAskState] = useSearchAskContext();
const { organizationId, siteId, siteSpaceId } = pointer;

React.useEffect(() => {
let cancelled = false;
@@ -52,7 +51,7 @@ export function SearchAskAnswer(props: { pointer: SiteContentPointer; query: str
query,
});

const response = streamAskQuestion({ pointer, question: query });
const response = streamAskQuestion({ question: query });
const stream = iterateStreamResponse(response);

// When we pass in "ask" mode, the query could still be updated by the client
@@ -81,7 +80,7 @@ export function SearchAskAnswer(props: { pointer: SiteContentPointer; query: str
cancelled = true;
}
};
}, [organizationId, siteId, siteSpaceId, query, setAskState, setSearchState, trackEvent]);
}, [query, setAskState, setSearchState, trackEvent]);

React.useEffect(() => {
return () => {
5 changes: 3 additions & 2 deletions packages/gitbook/src/components/Search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -90,8 +90,9 @@ export const SearchResults = React.forwardRef(function SearchResults(
return;
}

const { stream } = await streamRecommendedQuestions();
for await (const entry of readStreamableValue(stream)) {
const response = await streamRecommendedQuestions();
console.log('recommendedQuestions', response);
for await (const entry of readStreamableValue(response.stream)) {
if (!entry) {
continue;
}
3 changes: 3 additions & 0 deletions packages/gitbook/src/components/Search/server-actions.tsx
Original file line number Diff line number Diff line change
@@ -183,13 +183,16 @@ export async function streamRecommendedQuestions() {
);

for await (const chunk of apiStream) {
console.log('chunk', chunk);
stream.update(chunk);
}
})()
.then(() => {
console.log('done');
stream.done();
})
.catch((error) => {
console.log('error', error);
stream.error(error);
});

Loading
Oops, something went wrong.