Skip to content

Commit fc3ab02

Browse files
committed
Adapt AIPageLinkSummary
1 parent e79f526 commit fc3ab02

File tree

7 files changed

+71
-202
lines changed

7 files changed

+71
-202
lines changed

packages/gitbook/src/components/AI/server-actions/api.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { RenderAIMessageOptions } from './types';
2020
type StreamGenerateInput = {
2121
organizationId: string;
2222
siteId: string;
23-
instructions: string;
23+
instructions?: string;
2424
previousResponseId?: string;
2525
input: AIMessageInput[];
2626
model: AIModel;

packages/gitbook/src/components/Adaptive/AIPageLinkSummary.tsx renamed to packages/gitbook/src/components/AIPageLinkSummary/AIPageLinkSummary.tsx

File renamed without changes.

packages/gitbook/src/components/Adaptive/index.ts renamed to packages/gitbook/src/components/AIPageLinkSummary/index.ts

File renamed without changes.

packages/gitbook/src/components/Adaptive/server-actions/index.ts renamed to packages/gitbook/src/components/AIPageLinkSummary/server-actions/index.ts

File renamed without changes.

packages/gitbook/src/components/Adaptive/server-actions/streamLinkPageSummary.ts renamed to packages/gitbook/src/components/AIPageLinkSummary/server-actions/streamLinkPageSummary.ts

Lines changed: 69 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import { filterOutNullable } from '@/lib/typescript';
33
import { getV1BaseContext } from '@/lib/v1';
44
import { isV2 } from '@/lib/v2';
5-
import { AIMessageRole } from '@gitbook/api';
5+
import { AIMessageRole, AIModel } from '@gitbook/api';
66
import { getSiteURLDataFromMiddleware } from '@v2/lib/middleware';
77
import { getServerActionBaseContext } from '@v2/lib/server-actions';
88
import { z } from 'zod';
9-
import { streamGenerateObject } from './api';
9+
import { streamGenerateAIObject } from '../../AI/server-actions/api';
1010

1111
/**
1212
* Get a summary of a page, in the context of another page
@@ -32,23 +32,17 @@ export async function* streamLinkPageSummary({
3232
const baseContext = isV2() ? await getServerActionBaseContext() : await getV1BaseContext();
3333
const siteURLData = await getSiteURLDataFromMiddleware();
3434

35-
const { stream } = await streamGenerateObject(
36-
baseContext,
37-
{
38-
organizationId: siteURLData.organization,
39-
siteId: siteURLData.site,
40-
},
41-
{
42-
schema: z.object({
43-
highlight: z
44-
.string()
45-
.describe('The reason why the user should read the target page.'),
46-
// questions: z.array(z.string().describe('The questions to sea')).max(3),
47-
}),
48-
messages: [
49-
{
50-
role: AIMessageRole.Developer,
51-
content: `# 1. Role
35+
const { stream } = await streamGenerateAIObject(baseContext, {
36+
organizationId: siteURLData.organization,
37+
siteId: siteURLData.site,
38+
model: AIModel.Fast,
39+
schema: z.object({
40+
highlight: z.string().describe('The reason why the user should read the target page.'),
41+
}),
42+
input: [
43+
{
44+
role: AIMessageRole.Developer,
45+
content: `# 1. Role
5246
You are a contextual fact extractor. Your job is to find the exact fact from the linked page that directly answers the implied question in the current paragraph.
5347
5448
# 2. Task
@@ -64,60 +58,60 @@ Extract a contextually-relevant fact that:
6458
3. Ensure the fact relates directly to the context of the paragraph containing the link
6559
4. Avoid ALL instructional language including words like "use", "click", "select", "create"
6660
5. Keep it under 30 words, factual and declarative about what EXISTS or IS TRUE`,
67-
},
68-
{
69-
role: AIMessageRole.Developer,
70-
content: `# 4. Current page
61+
},
62+
{
63+
role: AIMessageRole.Developer,
64+
content: `# 4. Current page
7165
The content of the current page is:`,
72-
attachments: [
73-
{
74-
type: 'page' as const,
75-
spaceId: currentSpaceId,
76-
pageId: currentPageId,
77-
},
78-
],
79-
},
80-
...(visitedPages
81-
? [
82-
{
83-
role: AIMessageRole.Developer,
84-
content: '# 5. Previous pages',
85-
},
86-
...visitedPages.map(({ spaceId, pageId }) => ({
87-
role: AIMessageRole.Developer,
88-
content: `## Page ${pageId}`,
89-
attachments: [
90-
{
91-
type: 'page' as const,
92-
spaceId,
93-
pageId,
94-
},
95-
],
96-
})),
97-
]
98-
: []),
99-
{
100-
role: AIMessageRole.Developer,
101-
content: `# 6. Target page
66+
attachments: [
67+
{
68+
type: 'page' as const,
69+
spaceId: currentSpaceId,
70+
pageId: currentPageId,
71+
},
72+
],
73+
},
74+
...(visitedPages
75+
? [
76+
{
77+
role: AIMessageRole.Developer,
78+
content: '# 5. Previous pages',
79+
},
80+
...visitedPages.map(({ spaceId, pageId }) => ({
81+
role: AIMessageRole.Developer,
82+
content: `## Page ${pageId}`,
83+
attachments: [
84+
{
85+
type: 'page' as const,
86+
spaceId,
87+
pageId,
88+
},
89+
],
90+
})),
91+
]
92+
: []),
93+
{
94+
role: AIMessageRole.Developer,
95+
content: `# 6. Target page
10296
The content of the target page is:`,
103-
attachments: [
104-
{
105-
type: 'page' as const,
106-
spaceId: targetSpaceId,
107-
pageId: targetPageId,
108-
},
109-
],
110-
},
111-
{
112-
role: AIMessageRole.Developer,
113-
content: `# 7. Link preview
97+
attachments: [
98+
{
99+
type: 'page' as const,
100+
spaceId: targetSpaceId,
101+
pageId: targetPageId,
102+
},
103+
],
104+
},
105+
{
106+
role: AIMessageRole.Developer,
107+
content: `# 7. Link preview
114108
The content of the link preview is:
115109
> ${linkPreview}
116110
> Page ID: ${targetPageId}`,
117-
},
118-
{
119-
role: AIMessageRole.Developer,
120-
content: `# 8. Guidelines & Examples
111+
},
112+
{
113+
role: AIMessageRole.Developer,
114+
content: `# 8. Guidelines & Examples
121115
ALWAYS:
122116
- ALWAYS choose facts that directly fulfill the contextual need where the link appears
123117
- ALWAYS connect target page information specifically to the current paragraph context
@@ -146,14 +140,13 @@ Current paragraph: "Your team mentioned issues with conflicting edits. Need to c
146140
Preview: "Live Edit: Real-time collaborative editing."
147141
✓ "Teams with GitHub repositories (like yours) cannot use this feature due to sync limitations."
148142
✗ "Incompatible with GitHub/GitLab sync and requires specific visibility settings."`,
149-
},
150-
{
151-
role: AIMessageRole.User,
152-
content: `I'm considering reading the link titled "${linkTitle}" pointing to page ${targetPageId}. Why should I read it? Relate it to the paragraph I'm currently reading.`,
153-
},
154-
].filter(filterOutNullable),
155-
}
156-
);
143+
},
144+
{
145+
role: AIMessageRole.User,
146+
content: `I'm considering reading the link titled "${linkTitle}" pointing to page ${targetPageId}. Why should I read it? Relate it to the paragraph I'm currently reading.`,
147+
},
148+
].filter(filterOutNullable),
149+
});
157150

158151
for await (const value of stream) {
159152
const highlight = value.highlight;

packages/gitbook/src/components/Adaptive/server-actions/api.ts

Lines changed: 0 additions & 124 deletions
This file was deleted.

packages/gitbook/src/components/DocumentView/InlineLink/InlineLinkTooltipImpl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { tcls } from '@/lib/tailwind';
33
import { Icon } from '@gitbook/icons';
44
import * as Tooltip from '@radix-ui/react-tooltip';
55
import { Fragment } from 'react';
6-
import { AIPageLinkSummary } from '../../Adaptive';
6+
import { AIPageLinkSummary } from '../../AIPageLinkSummary';
77
import { Button, StyledLink } from '../../primitives';
88

99
export function InlineLinkTooltipImpl(props: {

0 commit comments

Comments
 (0)