-
Notifications
You must be signed in to change notification settings - Fork 131
feat: LLMs dropdown #1956
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
Merged
Merged
feat: LLMs dropdown #1956
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5455d61
feat(docs): LLMs dropdown
webrdaniel e02ef01
fix
webrdaniel 9c3bcd0
lint fixes
webrdaniel cdcc8da
feat: Add LLMs chat prompt links
birosrichard a9f0357
cleaner code
webrdaniel bbf2341
Fix SSG compatibility
webrdaniel 03c3a91
fix
webrdaniel 2f13047
fix
webrdaniel 2ce622e
Rotate chevron icon on dropdown open
webrdaniel 8e3f17c
fix lint
webrdaniel 7924c50
fix
webrdaniel cfc4ba7
Updated icons
webrdaniel c7b22b4
copied icon
webrdaniel 3b3ca36
add min-width
webrdaniel 5b1acf8
fix: renamed "Copy page" in dropdown options to "Copy for LLM" to hav…
jbartadev fbac4e8
mobile dropdown alignment
webrdaniel 14fc012
fix
webrdaniel 2c4180b
Fix design on API reference page
webrdaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.docItemContent { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
column-gap: 12px; | ||
flex-wrap: wrap; | ||
} |
71 changes: 0 additions & 71 deletions
71
apify-docs-theme/src/theme/LLMButtons/CopyForLLM/index.jsx
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
apify-docs-theme/src/theme/LLMButtons/ViewAsMarkdown/index.jsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,236 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { | ||
ChevronDownIcon, | ||
CopyIcon, | ||
ExternalLinkIcon, | ||
MarkdownIcon, | ||
} from '@apify/ui-icons'; | ||
import { Menu, Text, theme } from '@apify/ui-library'; | ||
|
||
import CopyForLLM from './CopyForLLM'; | ||
import styles from './styles.module.css'; | ||
import ViewAsMarkdown from './ViewAsMarkdown'; | ||
|
||
function ButtonText({ isLoading, isCopied }) { | ||
if (isLoading) { | ||
return 'Copying...'; | ||
} | ||
if (isCopied) { | ||
return 'Copied!'; | ||
} | ||
return 'Copy for LLM'; | ||
} | ||
webrdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
export default function LLMButtons() { | ||
const [isCopyingLoading, setCopyingIsLoading] = useState(false); | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const currentUrl = window.location.href; | ||
const prompt = `Read from ${currentUrl} so I can ask questions about it.`; | ||
const markdownUrl = `${currentUrl}.md`; | ||
|
||
const onCopyAsMarkdownClick = async () => { | ||
if (window.analytics) { | ||
window.analytics.track('Clicked', { | ||
app: 'docs', | ||
button_text: 'Copy for LLM', | ||
element: 'llm-buttons.copyForLLM', | ||
}); | ||
} | ||
|
||
try { | ||
setCopyingIsLoading(true); | ||
|
||
// Fetch the markdown content | ||
const response = await fetch(markdownUrl); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to fetch markdown: ${response.status}`); | ||
} | ||
|
||
const markdownContent = await response.text(); | ||
|
||
// Copy to clipboard | ||
await navigator.clipboard.writeText(markdownContent); | ||
|
||
// Show success feedback | ||
setIsCopied(true); | ||
setTimeout(() => setIsCopied(false), 2000); | ||
} catch (error) { | ||
console.error('Failed to copy markdown content:', error); | ||
} finally { | ||
setCopyingIsLoading(false); | ||
} | ||
}; | ||
|
||
const onViewAsMarkdownClick = () => { | ||
if (window.analytics) { | ||
window.analytics.track('Clicked', { | ||
app: 'docs', | ||
button_text: 'View as Markdown', | ||
element: 'llm-buttons.viewAsMarkdown', | ||
}); | ||
} | ||
|
||
try { | ||
window.open(markdownUrl, '_blank'); | ||
} catch (error) { | ||
console.error('Error opening markdown file:', error); | ||
} | ||
}; | ||
|
||
const onOpenInChatGPTClick = () => { | ||
if (window.analytics) { | ||
window.analytics.track('Clicked', { | ||
app: 'docs', | ||
button_text: 'Open in ChatGPT', | ||
element: 'llm-buttons.openInChatGPT', | ||
}); | ||
} | ||
|
||
try { | ||
window.open(`https://chatgpt.com/?hints=search&q=${encodeURIComponent(prompt)}`, '_blank'); | ||
} catch (error) { | ||
console.error('Error opening ChatGPT:', error); | ||
} | ||
}; | ||
webrdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
const onOpenInClaudeClick = () => { | ||
if (window.analytics) { | ||
window.analytics.track('Clicked', { | ||
app: 'docs', | ||
button_text: 'Open in Claude', | ||
element: 'llm-buttons.openInClaude', | ||
}); | ||
} | ||
|
||
try { | ||
window.open(`https://claude.ai/new?q=${encodeURIComponent(prompt)}`, '_blank'); | ||
} catch (error) { | ||
console.error('Error opening Claude:', error); | ||
} | ||
}; | ||
|
||
const onOpenInPerplexityClick = () => { | ||
if (window.analytics) { | ||
window.analytics.track('Clicked', { | ||
app: 'docs', | ||
button_text: 'Open in Perplexity', | ||
element: 'llm-buttons.openInPerplexity', | ||
}); | ||
} | ||
|
||
try { | ||
window.open(`https://www.perplexity.ai/search/new?q=${encodeURIComponent(prompt)}`, '_blank'); | ||
} catch (error) { | ||
console.error('Error opening Perplexity:', error); | ||
} | ||
}; | ||
|
||
const onMenuOptionClick = (value) => { | ||
switch (value) { | ||
case 'copyForLLM': | ||
onCopyAsMarkdownClick(); | ||
break; | ||
case 'viewAsMarkdown': | ||
onViewAsMarkdownClick(); | ||
break; | ||
case 'openInChatGPT': | ||
onOpenInChatGPTClick(); | ||
break; | ||
case 'openInClaude': | ||
onOpenInClaudeClick(); | ||
break; | ||
case 'openInPerplexity': | ||
onOpenInPerplexityClick(); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.llmButtonsContainer}> | ||
<ViewAsMarkdown /> | ||
<div className={styles.llmButtonsSeparator}></div> | ||
<CopyForLLM /> | ||
</div> | ||
<Menu | ||
components={{ | ||
MenuBase: ({ children, ref, ...props }) => ( | ||
<div ref={ref} className={styles.llmButton}> | ||
<CopyIcon size={16} /> | ||
<Text | ||
size="regular" | ||
className={styles.llmButtonText} | ||
onClick={onCopyAsMarkdownClick} | ||
> | ||
<ButtonText isLoading={isCopyingLoading} isCopied={isCopied} /> | ||
</Text> | ||
<ChevronDownIcon | ||
{...props} | ||
size="16" | ||
color={theme.color.neutral.icon} | ||
className={styles.chevronIcon} | ||
/> | ||
</div> | ||
), | ||
}} | ||
onSelect={onMenuOptionClick} | ||
options={[ | ||
{ | ||
label: 'Copy page', | ||
description: 'Copy page as Markdown for LLMs', | ||
showExternalIcon: false, | ||
icon: CopyIcon, | ||
value: 'copyForLLM', | ||
}, | ||
webrdaniel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
label: 'View as Markdown', | ||
description: 'View this page as plain text', | ||
showExternalIcon: true, | ||
icon: MarkdownIcon, | ||
value: 'viewAsMarkdown', | ||
}, | ||
{ | ||
label: 'Open in ChatGPT', | ||
description: 'Ask questions about this page', | ||
showExternalIcon: true, | ||
// TODO: Replace icon once we have one | ||
icon: MarkdownIcon, | ||
value: 'openInChatGPT', | ||
}, | ||
{ | ||
label: 'Open in Claude', | ||
description: 'Ask questions about this page', | ||
showExternalIcon: true, | ||
// TODO: Replace icon once we have one | ||
icon: MarkdownIcon, | ||
value: 'openInClaude', | ||
}, | ||
{ | ||
label: 'Open in Perplexity', | ||
description: 'Ask questions about this page', | ||
showExternalIcon: true, | ||
// TODO: Replace icon once we have one | ||
icon: MarkdownIcon, | ||
value: 'openInPerplexity', | ||
}, | ||
]} | ||
renderOption={(option) => ( | ||
<div className={styles.menuOption}> | ||
<option.icon size={16} className={styles.menuOptionIcon} /> | ||
<div className={styles.menuOptionText}> | ||
<Text size="regular">{option.label}</Text> | ||
<Text | ||
size="small" | ||
color={theme.color.neutral.textSubtle} | ||
> | ||
{option.description} | ||
</Text> | ||
</div> | ||
{option.showExternalIcon && ( | ||
<ExternalLinkIcon | ||
size={16} | ||
className={styles.menuOptionExternalIcon} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
/> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.