-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84c79cc
commit 5b3d3ba
Showing
4 changed files
with
155 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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,149 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import { cn } from '../utils'; | ||
import { Alert, AlertDescription, AlertTitle } from './ui/alert'; | ||
import { AlertCircle } from 'lucide-react'; | ||
import Link from 'next/link'; | ||
|
||
export interface OutputsProps extends React.HTMLAttributes<HTMLDivElement> {} | ||
|
||
export const Outputs = React.forwardRef< | ||
HTMLDivElement, | ||
React.PropsWithChildren<OutputsProps> | ||
>(({ children, ...props }, ref) => { | ||
let infoElement = null; | ||
|
||
const [isBrowserSupport, setIsBrowserSupport] = React.useState(true); | ||
const [isEnabledFlags, setIsEnabledFlags] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
function getChromeVersion() { | ||
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); | ||
return raw ? parseInt(raw[2], 10) : 0; | ||
} | ||
const version = getChromeVersion(); | ||
setIsBrowserSupport(version >= 127); | ||
|
||
setIsEnabledFlags(!!('ai' in globalThis)); | ||
|
||
globalThis.ai?.canCreateGenericSession().then((status) => { | ||
setIsEnabledFlags(status === 'readily'); | ||
}); | ||
}, []); | ||
|
||
if (!isBrowserSupport || !isEnabledFlags) { | ||
infoElement = ( | ||
<div className="w-[500px] m-auto flex flex-col gap-4"> | ||
<h2 className="scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0"> | ||
Enabling AI in Chrome | ||
</h2> | ||
<p className="leading-7"> | ||
Chrome's implementation of built-in AI with Gemini Nano is | ||
experimental and will change as they test and address feedback. | ||
</p> | ||
|
||
{isBrowserSupport ? null : ( | ||
<Alert variant="destructive"> | ||
<AlertCircle className="h-4 w-4" /> | ||
<AlertTitle>Your browser is not supported.</AlertTitle> | ||
<AlertDescription> | ||
Please update Chrome to version 127 or higher. | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
|
||
{isEnabledFlags ? null : ( | ||
<div className="flex flex-col items-start justify-start"> | ||
<p className="leading-7 mb-4"> | ||
Once your browser is installed, ensure the following flags are | ||
set: | ||
</p> | ||
<ol className="grid gap-4 counter-reset:step"> | ||
<li className="flex items-center gap-4 text-sm"> | ||
<div className="flex h-6 w-6 text-xs items-center justify-center rounded-full bg-primary text-primary-foreground counter:step"> | ||
1 | ||
</div> | ||
<div className="w-full"> | ||
<h4 className="font-medium"> | ||
Step 1: | ||
<Link | ||
href="chrome://flags/#prompt-api-for-gemini-nano" | ||
target="_blank" | ||
className="underline" | ||
> | ||
chrome://flags/#prompt-api-for-gemini-nano | ||
</Link> | ||
</h4> | ||
<p className="text-muted-foreground"> | ||
Select 'Enabled' | ||
</p> | ||
</div> | ||
</li> | ||
<li className="flex items-center gap-4 text-sm"> | ||
<div className="flex h-6 w-6 text-xs items-center justify-center rounded-full bg-primary text-primary-foreground counter:step"> | ||
2 | ||
</div> | ||
<div className="w-full"> | ||
<h4 className="font-medium"> | ||
Step 2: | ||
<Link | ||
href="chrome://flags/#optimization-guide-on-device-model" | ||
target="_blank" | ||
className="underline" | ||
> | ||
chrome://flags/#optimization-guide-on-device-model | ||
</Link> | ||
</h4> | ||
<p className="text-muted-foreground"> | ||
Select 'Enabled BypassPrefRequirement' | ||
</p> | ||
</div> | ||
</li> | ||
<li className="flex items-center gap-4 text-sm"> | ||
<div className="flex h-6 w-6 text-xs items-center justify-center rounded-full bg-primary text-primary-foreground counter:step"> | ||
3 | ||
</div> | ||
<div className="w-full"> | ||
<h4 className="font-medium"> | ||
Step 3: | ||
<Link | ||
href="chrome://components" | ||
target="_blank" | ||
className="underline" | ||
> | ||
chrome://components | ||
</Link> | ||
</h4> | ||
<p className="text-muted-foreground"> | ||
Click 'Check for Update' on Optimization Guide On | ||
Device Model to download the model. If you don't see | ||
Optimization Guide, ensure you have set the flags correctly | ||
above, relaunch your browser, and refresh the page. | ||
</p> | ||
</div> | ||
</li> | ||
</ol> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} else { | ||
infoElement = null; | ||
} | ||
|
||
return ( | ||
<div | ||
{...props} | ||
ref={ref} | ||
className={cn( | ||
'relative flex h-full min-h-[50vh] flex-col rounded-xl bg-muted/50 p-4 lg:col-span-2 mt-2', | ||
props.className | ||
)} | ||
> | ||
{infoElement ?? children} | ||
</div> | ||
); | ||
}); | ||
|
||
Outputs.displayName = 'Outputs'; |
This file contains 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 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 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