-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Feat/video anaylsis #1082
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
Closed
+432
−92
Closed
Feat/video anaylsis #1082
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd8b325
fix: clean-up chat & text-generation features.
sedanah-m 28b4806
comment cleanup
sedanah-m 8795f68
Update ai/ai-samples/src/features/text-generation/index.tsx
sedanah-m 239d37d
Update ai/ai-samples/src/features/chat/index.tsx
sedanah-m a01faab
fix: minor mismatch between prompt passing
sedanah-m de95e86
fix: support optional `systemInstruction` parameter in `generateText`…
sedanah-m 33b494f
refactor: centralize isolated feature routing and clean up App shell;…
sedanah-m e0a48dc
feat: Adds the video-analysis quickstart feature sample.
sedanah-m 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
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,49 +1,110 @@ | ||
| import { useState } from 'react'; | ||
| import { generateText } from './service'; | ||
| import { generateText, streamText } from './service'; | ||
|
|
||
| export default function TextGeneration() { | ||
| export default function TextGenerationView() { | ||
| const [prompt, setPrompt] = useState<string>(''); | ||
| const cleanPrompt = prompt.trim(); | ||
| const [systemInstruction, setSystemInstruction] = useState<string>(''); | ||
| const [useStreaming, setUseStreaming] = useState<boolean>(true); | ||
| const [response, setResponse] = useState<string>(''); | ||
| const [loading, setLoading] = useState<boolean>(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const handleGenerate = async () => { | ||
| if (!prompt.trim()) return; | ||
| if (!cleanPrompt) return; | ||
|
|
||
| setLoading(true); | ||
| setError(null); | ||
| setResponse(''); | ||
|
|
||
| try { | ||
| // Direct call to the decoupled logic service | ||
| const text = await generateText(prompt); | ||
| setResponse(text); | ||
| } catch (err: any) { | ||
| setError(err.message || 'An unexpected error occurred'); | ||
| const cleanInstruction = systemInstruction.trim() || undefined; | ||
|
|
||
| if (useStreaming) { | ||
| await streamText( | ||
| cleanPrompt, | ||
| (chunk) => setResponse((prev) => prev + chunk), | ||
| cleanInstruction | ||
| ); | ||
| } else { | ||
| const text = await generateText(cleanPrompt, cleanInstruction); | ||
| setResponse(text); | ||
| } | ||
| } catch (err: unknown) { | ||
| const errorMessage = err instanceof Error | ||
| ? err.message | ||
| : 'An unexpected error occurred'; | ||
|
|
||
| setError(errorMessage); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| return ( | ||
| <div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}> | ||
| <h2>Text Generation</h2> | ||
|
|
||
| <textarea | ||
| value={prompt} | ||
| onChange={(e) => setPrompt(e.target.value)} | ||
| placeholder="Ask the AI a question..." | ||
| rows={5} | ||
| style={{ width: '100%', marginBottom: '10px', padding: '10px' }} | ||
| /> | ||
|
|
||
| <button onClick={handleGenerate} disabled={loading || !prompt.trim()} style={{ padding: '10px 20px' }}> | ||
| {loading ? 'Generating...' : 'Generate'} | ||
| </button> | ||
|
|
||
| {error && <p style={{ color: 'red', marginTop: '15px' }}>{error}</p>} | ||
| {response && <div style={{ marginTop: '20px', padding: '15px', backgroundColor: '#f0f0f0' }}><p style={{ whiteSpace: 'pre-wrap' }}>{response}</p></div>} | ||
|
|
||
| {/* System Instruction Input */} | ||
| <div style={{ marginBottom: '12px' }}> | ||
| <label style={{ display: 'block', marginBottom: '4px', fontSize: '0.9rem', color: '#5f6368' }}> | ||
| System Instruction (Persona/Rules) | ||
| </label> | ||
| <input | ||
| type="text" | ||
| value={systemInstruction} | ||
| onChange={(e) => setSystemInstruction(e.target.value)} | ||
| placeholder="e.g., You are a helpful assistant..." | ||
| disabled={loading} | ||
| style={{ width: '100%', padding: '10px', boxSizing: 'border-box' }} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Main Prompt Input */} | ||
| <div style={{ marginBottom: '12px' }}> | ||
| <label style={{ display: 'block', marginBottom: '4px', fontSize: '0.9rem', color: '#5f6368' }}> | ||
| Prompt | ||
| </label> | ||
| <textarea | ||
| value={prompt} | ||
| onChange={(e) => setPrompt(e.target.value)} | ||
| placeholder="Ask the AI a question..." | ||
| rows={5} | ||
| disabled={loading} | ||
| style={{ width: '100%', padding: '10px', boxSizing: 'border-box' }} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Controls: Checkbox and Button */} | ||
| <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}> | ||
| <label style={{ display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer' }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={useStreaming} | ||
| onChange={(e) => setUseStreaming(e.target.checked)} | ||
| disabled={loading} | ||
| /> | ||
| Stream response | ||
| </label> | ||
|
|
||
| <button | ||
| onClick={handleGenerate} | ||
| disabled={loading || !cleanPrompt} | ||
| style={{ padding: '10px 20px', cursor: (loading || !cleanPrompt) ? 'not-allowed' : 'pointer' }} | ||
| > | ||
| {loading ? 'Generating...' : 'Generate'} | ||
| </button> | ||
| </div> | ||
|
|
||
| {/* Error Message */} | ||
| {error && <p style={{ color: '#c5221f', marginTop: '15px' }}>{error}</p>} | ||
|
|
||
| {/* Response Box */} | ||
| {response && ( | ||
| <div style={{ marginTop: '20px', padding: '15px', backgroundColor: '#f0f0f0', borderRadius: '8px' }}> | ||
| <p style={{ whiteSpace: 'pre-wrap', margin: 0 }}>{response}</p> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Video Analysis feature is missing from the sidebar navigation items. Add it to
NAV_ITEMSso users can navigate to it.