diff --git a/ai/ai-samples/src/features/function-calling/index.tsx b/ai/ai-samples/src/features/function-calling/index.tsx index 83f2c413a..023f110ed 100644 --- a/ai/ai-samples/src/features/function-calling/index.tsx +++ b/ai/ai-samples/src/features/function-calling/index.tsx @@ -1,9 +1,136 @@ -import React from 'react'; +import { useState } from 'react'; +import { executeFunctionCalling, FunctionCallingResult } from './service'; + +export default function FunctionCallingView() { + const [prompt, setPrompt] = useState('What was the weather in Boston on October 17, 2024?'); + const [loading, setLoading] = useState(false); + const [result, setResult] = useState(null); + const [error, setError] = useState(null); + + const handleRun = async () => { + const cleanedPrompt = prompt.trim(); + + if (!cleanedPrompt) { + setError('Please enter a prompt.'); + return; + } + + setLoading(true); + setError(null); + setResult(null); + + try { + const res = await executeFunctionCalling(cleanedPrompt); + setResult(res); + } catch (err: unknown) { + console.error(err); + const message = err instanceof Error ? err.message : 'An error occurred during function calling.'; + setError(message); + } finally { + setLoading(false); + } + }; -export default function FunctionCallingFeature() { return ( -
-

function-calling

+
+

Function Calling

+

+ Demonstrates the manual round-trip: Gemini extracts structured arguments, + your app executes a local function, and sends the result back for final text synthesis. +

+ + {/* Input Prompt */} +
+