Skip to content

Commit 625e2dc

Browse files
committed
AI Chat followup
- Layout tweaks - Prompt tweaks
1 parent 8d65983 commit 625e2dc

File tree

2 files changed

+92
-84
lines changed

2 files changed

+92
-84
lines changed

packages/gitbook/src/components/AI/server-actions/chat.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import type { RenderAIMessageOptions } from './types';
1010
const PROMPT = `
1111
You are GitBook Docs Assistant, a helpful docs assistant that answers questions from the user about a documentation site.
1212
13-
You analyse the query, and the content of the site, and generate a short, concise answer that will help the user.
13+
You analyse the query and the content of the site, and generate a short, concise answer that will help the user.
1414
1515
# Instructions
1616
1717
- Analyse the user's query to figure out what they want to know.
18-
- Use tools to help answer questions beyond the current page context.
18+
- Go beyond what's available on the current page. A user has most likely already read the page they're on, and are looking for deeper knowledge.
19+
- **ALWAYS start with the search tool for most queries.** Search should be your first action unless the query is specifically about the current page content.
20+
- Use multiple tools extensively to help answer the user's query. You will need more than one tool call to answer most questions.
1921
- Only ever answer using knowledge you can find in the content of the documentation.
2022
- Only answer questions that are related to the docs.
2123
- If the user asks a question that is not related to the docs, say that you can't help with that.
@@ -31,23 +33,27 @@ You analyse the query, and the content of the site, and generate a short, concis
3133
- Do not state the obvious.
3234
- Do not refer to the page or specific blocks directly, they know about the page since they just asked about it. Instead summarise and provide the information directly.
3335
- If the user asks what to read next:
36+
- **ALWAYS search first** to find relevant pages and topics.
3437
- Provide multiple (preferably 3+) relevant suggestions.
3538
- Explain concisely why they're relevant.
3639
- If the user asks for an example:
37-
- Write an example related to the current page they're reading.
40+
- **Search for existing examples** in the documentation first.
41+
- If none found, write an example related to the current page they're reading.
3842
- This could be an implementation example, a code sample, a diagram, etc.
3943
4044
# Tool usage
4145
42-
**Important: Make extensive use of tools to answer the question. Look beyond the current page!**
46+
**CRITICAL: You MUST use the search tool for almost every query. Search is your primary tool.**
4347
44-
- Use the \`getPageContent\` tool to get the current page or additional pages.
45-
- Follow links on the current page to provide more context.
46-
- Use the \`getPages\` tool to list all pages in the site.
47-
- Use the \`search\` tool to find information that is not on the current page.
48+
- **ALWAYS start with the \`search\` tool** unless the query is explicitly about the current page content.
49+
- Search should be your first action for questions about features, concepts, examples, related topics, etc.
4850
- When searching, use short keywords and synonyms for best results.
4951
- Do not use sentences as queries.
5052
- Do not use the exact query as the user's question.
53+
- Try multiple search terms if the first search doesn't yield good results.
54+
- Use the \`getPageContent\` tool to get the current page or additional pages after searching.
55+
- Follow links on the current page to provide more context.
56+
- Use the \`getPages\` tool to list all pages in the site when you need a broader overview.
5157
5258
# Writing style
5359
@@ -78,7 +84,7 @@ ${MARKDOWN_LINKS_PROMPT}
7884
const FOLLOWUP_PROMPT = `
7985
Generate a short JSON list with message suggestions for a user to post in a chat. The suggestions will be displayed next to the text input, allowing the user to quickly tap and pick one.
8086
81-
# Guidelines
87+
# Instructions
8288
8389
- Only suggest responses that are relevant to the documentation and the current conversation.
8490
- If there are no relevant suggestions, return an empty list.

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -77,84 +77,86 @@ export function SpaceLayout(props: {
7777
context={context}
7878
/>
7979
{withAIChat ? <AIChat /> : null}
80-
<div className="transition-all duration-300 lg:chat-open:mr-80 xl:chat-open:mr-96">
81-
<div
82-
className={tcls(
83-
'flex',
84-
'flex-col',
85-
'lg:flex-row',
86-
CONTAINER_STYLE,
87-
'site-full-width:max-w-full',
80+
<div className="scroll-nojump">
81+
<div className="transition-all duration-300 lg:chat-open:mr-80 xl:chat-open:mr-96">
82+
<div
83+
className={tcls(
84+
'flex',
85+
'flex-col',
86+
'lg:flex-row',
87+
CONTAINER_STYLE,
88+
'site-full-width:max-w-full',
8889

89-
// Ensure the footer is display below the viewport even if the content is not enough
90-
withFooter && 'min-h-[calc(100vh-64px)]',
91-
withTopHeader ? null : 'lg:min-h-screen'
92-
)}
93-
>
94-
<TableOfContents
95-
context={context}
96-
header={
97-
withTopHeader ? null : (
98-
<div
99-
className={tcls(
100-
'hidden',
101-
'pr-4',
102-
'lg:flex',
103-
'grow-0',
104-
'flex-wrap',
105-
'dark:shadow-light/1',
106-
'text-base/tight'
107-
)}
108-
>
109-
<HeaderLogo context={context} />
110-
</div>
111-
)
112-
}
113-
innerHeader={
114-
// displays the search button and/or the space dropdown in the ToC according to the header/variant settings. E.g if there is no header, the search button will be displayed in the ToC.
115-
<>
116-
{!withTopHeader && (
117-
<div className={tcls('hidden', 'lg:block')}>
118-
<React.Suspense fallback={null}>
119-
<SearchButton>
120-
<span className={tcls('flex-1')}>
121-
{t(
122-
getSpaceLanguage(customization),
123-
customization.aiSearch.enabled
124-
? 'search_or_ask'
125-
: 'search'
126-
)}
127-
...
128-
</span>
129-
</SearchButton>
130-
</React.Suspense>
131-
</div>
132-
)}
133-
{!withTopHeader && withSections && sections && (
134-
<SiteSectionList
135-
className={tcls('hidden', 'lg:block')}
136-
sections={encodeClientSiteSections(
137-
context,
138-
sections
139-
)}
140-
/>
141-
)}
142-
{isMultiVariants && !sections && (
143-
<SpacesDropdown
144-
context={context}
145-
siteSpace={siteSpace}
146-
siteSpaces={siteSpaces}
90+
// Ensure the footer is display below the viewport even if the content is not enough
91+
withFooter && 'min-h-[calc(100vh-64px)]',
92+
withTopHeader ? null : 'lg:min-h-screen'
93+
)}
94+
>
95+
<TableOfContents
96+
context={context}
97+
header={
98+
withTopHeader ? null : (
99+
<div
147100
className={tcls(
148-
'w-full',
149-
'page-no-toc:hidden',
150-
'site-header-none:page-no-toc:flex'
101+
'hidden',
102+
'pr-4',
103+
'lg:flex',
104+
'grow-0',
105+
'flex-wrap',
106+
'dark:shadow-light/1',
107+
'text-base/tight'
151108
)}
152-
/>
153-
)}
154-
</>
155-
}
156-
/>
157-
<div className="flex min-w-0 flex-1 flex-col">{children}</div>
109+
>
110+
<HeaderLogo context={context} />
111+
</div>
112+
)
113+
}
114+
innerHeader={
115+
// displays the search button and/or the space dropdown in the ToC according to the header/variant settings. E.g if there is no header, the search button will be displayed in the ToC.
116+
<>
117+
{!withTopHeader && (
118+
<div className={tcls('hidden', 'lg:block')}>
119+
<React.Suspense fallback={null}>
120+
<SearchButton>
121+
<span className={tcls('flex-1')}>
122+
{t(
123+
getSpaceLanguage(customization),
124+
customization.aiSearch.enabled
125+
? 'search_or_ask'
126+
: 'search'
127+
)}
128+
...
129+
</span>
130+
</SearchButton>
131+
</React.Suspense>
132+
</div>
133+
)}
134+
{!withTopHeader && withSections && sections && (
135+
<SiteSectionList
136+
className={tcls('hidden', 'lg:block')}
137+
sections={encodeClientSiteSections(
138+
context,
139+
sections
140+
)}
141+
/>
142+
)}
143+
{isMultiVariants && !sections && (
144+
<SpacesDropdown
145+
context={context}
146+
siteSpace={siteSpace}
147+
siteSpaces={siteSpaces}
148+
className={tcls(
149+
'w-full',
150+
'page-no-toc:hidden',
151+
'site-header-none:page-no-toc:flex'
152+
)}
153+
/>
154+
)}
155+
</>
156+
}
157+
/>
158+
<div className="flex min-w-0 flex-1 flex-col">{children}</div>
159+
</div>
158160
</div>
159161
</div>
160162

0 commit comments

Comments
 (0)