Skip to content

Commit cdcc8da

Browse files
committed
feat: Add LLMs chat prompt links
1 parent 9c3bcd0 commit cdcc8da

File tree

1 file changed

+85
-5
lines changed
  • apify-docs-theme/src/theme/LLMButtons

1 file changed

+85
-5
lines changed

apify-docs-theme/src/theme/LLMButtons/index.jsx

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export default function LLMButtons() {
2424
const [isCopyingLoading, setCopyingIsLoading] = useState(false);
2525
const [isCopied, setIsCopied] = useState(false);
2626

27+
const currentUrl = window.location.href;
28+
const prompt = `Read from ${currentUrl} so I can ask questions about it.`;
29+
const markdownUrl = `${currentUrl}.md`;
30+
2731
const onCopyAsMarkdownClick = async () => {
2832
if (window.analytics) {
2933
window.analytics.track('Clicked', {
@@ -36,9 +40,6 @@ export default function LLMButtons() {
3640
try {
3741
setCopyingIsLoading(true);
3842

39-
const currentUrl = window.location.href;
40-
const markdownUrl = `${currentUrl}.md`;
41-
4243
// Fetch the markdown content
4344
const response = await fetch(markdownUrl);
4445

@@ -71,14 +72,60 @@ export default function LLMButtons() {
7172
}
7273

7374
try {
74-
const currentUrl = window.location.href;
75-
const markdownUrl = `${currentUrl}.md`;
7675
window.open(markdownUrl, '_blank');
7776
} catch (error) {
7877
console.error('Error opening markdown file:', error);
7978
}
8079
};
8180

81+
const onOpenInChatGPTClick = () => {
82+
if (window.analytics) {
83+
window.analytics.track('Clicked', {
84+
app: 'docs',
85+
button_text: 'Open in ChatGPT',
86+
element: 'llm-buttons.openInChatGPT',
87+
});
88+
}
89+
90+
try {
91+
window.open(`https://chatgpt.com/?hints=search&q=${encodeURIComponent(prompt)}`, '_blank');
92+
} catch (error) {
93+
console.error('Error opening ChatGPT:', error);
94+
}
95+
};
96+
97+
const onOpenInClaudeClick = () => {
98+
if (window.analytics) {
99+
window.analytics.track('Clicked', {
100+
app: 'docs',
101+
button_text: 'Open in Claude',
102+
element: 'llm-buttons.openInClaude',
103+
});
104+
}
105+
106+
try {
107+
window.open(`https://claude.ai/new?q=${encodeURIComponent(prompt)}`, '_blank');
108+
} catch (error) {
109+
console.error('Error opening Claude:', error);
110+
}
111+
};
112+
113+
const onOpenInPerplexityClick = () => {
114+
if (window.analytics) {
115+
window.analytics.track('Clicked', {
116+
app: 'docs',
117+
button_text: 'Open in Perplexity',
118+
element: 'llm-buttons.openInPerplexity',
119+
});
120+
}
121+
122+
try {
123+
window.open(`https://www.perplexity.ai/search/new?q=${encodeURIComponent(prompt)}`, '_blank');
124+
} catch (error) {
125+
console.error('Error opening Perplexity:', error);
126+
}
127+
};
128+
82129
const onMenuOptionClick = (value) => {
83130
switch (value) {
84131
case 'copyForLLM':
@@ -87,6 +134,15 @@ export default function LLMButtons() {
87134
case 'viewAsMarkdown':
88135
onViewAsMarkdownClick();
89136
break;
137+
case 'openInChatGPT':
138+
onOpenInChatGPTClick();
139+
break;
140+
case 'openInClaude':
141+
onOpenInClaudeClick();
142+
break;
143+
case 'openInPerplexity':
144+
onOpenInPerplexityClick();
145+
break;
90146
default:
91147
break;
92148
}
@@ -130,6 +186,30 @@ export default function LLMButtons() {
130186
icon: MarkdownIcon,
131187
value: 'viewAsMarkdown',
132188
},
189+
{
190+
label: 'Open in ChatGPT',
191+
description: 'Ask questions about this page',
192+
showExternalIcon: true,
193+
// TODO: Replace icon once we have one
194+
icon: MarkdownIcon,
195+
value: 'openInChatGPT',
196+
},
197+
{
198+
label: 'Open in Claude',
199+
description: 'Ask questions about this page',
200+
showExternalIcon: true,
201+
// TODO: Replace icon once we have one
202+
icon: MarkdownIcon,
203+
value: 'openInClaude',
204+
},
205+
{
206+
label: 'Open in Perplexity',
207+
description: 'Ask questions about this page',
208+
showExternalIcon: true,
209+
// TODO: Replace icon once we have one
210+
icon: MarkdownIcon,
211+
value: 'openInPerplexity',
212+
},
133213
]}
134214
renderOption={(option) => (
135215
<div className={styles.menuOption}>

0 commit comments

Comments
 (0)