AI Edge Function Calling SDK (FC SDK) adalah library yang memungkinkan developer menggunakan panggilan fungsi dengan LLM di perangkat. Panggilan fungsi memungkinkan Anda menghubungkan
model ke alat dan API eksternal, sehingga model dapat memanggil fungsi tertentu
dengan parameter yang diperlukan untuk menjalankan tindakan dunia nyata.
Daripada hanya menghasilkan teks, LLM yang menggunakan FC SDK dapat menghasilkan
panggilan terstruktur ke fungsi yang menjalankan tindakan, seperti menelusuri
informasi terbaru, menyetel alarm, atau membuat reservasi.
AI Edge FC SDK tersedia untuk Android dan dapat dijalankan sepenuhnya di perangkat
dengan LLM Inference API. Mulai gunakan SDK dengan mengikuti panduan Android, yang memandu Anda melalui implementasi dasar aplikasi contoh menggunakan panggilan fungsi.
Pipeline panggilan fungsi
Menyiapkan LLM di perangkat dengan kemampuan panggilan fungsi memerlukan
langkah-langkah utama berikut:
Menentukan deklarasi fungsi: Struktur dan parameter
fungsi yang dapat dipanggil LLM harus ditentukan dalam kode aplikasi Anda.
Hal ini mencakup menentukan nama, parameter, dan jenis fungsi.
Memformat perintah dan output: Teks input dan output dapat berisi bahasa
alam dan panggilan fungsi. Formater mengontrol cara struktur data
dikonversi ke dan dari string, sehingga LLM dapat memformat
informasi dengan tepat.
Mengurai output: Parser mendeteksi apakah respons yang dihasilkan berisi
panggilan fungsi dan mengurainya menjadi jenis data terstruktur sehingga
aplikasi dapat menjalankan panggilan fungsi.
Memeriksa respons: Jika parser mendeteksi panggilan fungsi, aplikasi akan memanggil fungsi dengan parameter yang sesuai dan jenis data terstruktur. Jika tidak, metode ini akan menampilkan teks bahasa alami.
Komponen utama
FC SDK berisi komponen utama berikut:
Backend Inferensi: Antarmuka untuk menjalankan inferensi pada model AI
generatif. FC SDK menggunakan LLM Inference API untuk menjalankan inferensi pada model LiteRT
(TFLite). API ini menggunakan antarmuka
InferenceBackend.
Prompt Formatter: Antarmuka untuk memformat permintaan dan respons ke
dan dari model AI Generatif. FC SDK menyediakan formater yang
mengonversi deklarasi fungsi menjadi format khusus model yang diperlukan oleh
LLM dan menyisipkannya ke dalam perintah sistem. Formator juga menangani
token khusus model untuk menunjukkan giliran pengguna dan model. API ini menggunakan antarmuka
ModelFormatter.
Parser Output: FC SDK menyediakan parser yang mendeteksi apakah output
model mewakili panggilan fungsi dan mengurainya menjadi struktur data untuk
digunakan oleh aplikasi. API ini menggunakan antarmuka
ModelFormatter.
Decoding Terbatas: Antarmuka untuk membuat dan mengelola batasan
guna memastikan bahwa output yang dihasilkan mematuhi aturan atau kondisi tertentu.
Untuk model yang didukung, FC SDK akan mengonfigurasi backend inferensi untuk menggunakan
decoding terbatas, yang memastikan bahwa model hanya menghasilkan nama dan parameter
fungsi yang valid. API ini menggunakan
antarmuka
ConstraintProvider.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-05-26 UTC."],[],[],null,["# AI Edge Function Calling guide\n\n| **Attention:** The AI Edge Function Calling SDK is under active development.\n\nThe AI Edge Function Calling SDK (FC SDK) is a library that enables developers\nto use function calling with on-device LLMs. Function calling lets you connect\nmodels to external tools and APIs, enabling models to call specific functions\nwith the necessary parameters to execute real-world actions.\n\nRather than just generating text, an LLM using the FC SDK can generate a\nstructured call to a function that executes an action, such as searching for\nup-to-date information, setting alarms, or making reservations.\n\nThe AI Edge FC SDK is available for Android and can be run completely on-device\nwith the LLM Inference API. Start using the SDK by following the [Android\nguide](./android), which walks you through a basic implementation of a sample\napplication using function calling.\n\nFunction calling pipeline\n-------------------------\n\nSetting up an on-device LLM with function calling capabilities requires the\nfollowing key steps:\n\n1. **Define function declarations**: The structure and parameters of the functions that the LLM can call must be defined in your application code. This includes specifying function names, parameters, and types.\n2. **Format prompts and outputs**: Input and output text can contain natural language and function calls. A formatter controls how data structures are converted to and from strings, enabling the LLM to appropriately format information.\n3. **Parse outputs**: A parser detects if the generated response contains a function call and parses it into a structured data type so that the application can execute the function call.\n4. **Examine responses**: If the parser detects a function call, the application calls the function with the appropriate parameters and structured data type. Otherwise, it returns natural language text.\n\nKey components\n--------------\n\nThe FC SDK contains to following key components:\n\n- **Inference Backend** : An interface for running inference on a generative AI model. The FC SDK uses the LLM Inference API to execute inference on LiteRT (TFLite) models. The API uses the [InferenceBackend](https://github.com/google-ai-edge/ai-edge-apis/blob/main/local_agents/function_calling/java/com/google/ai/edge/localagents/fc/InferenceBackend.java) interface.\n- **Prompt Formatter** : An interface for formatting requests and responses to and from the Generative AI model. The FC SDK provides a formatter that converts function declarations into the model-specific format required by the LLM and inserts them into the system prompt. The formatter also handles model-specific tokens to indicate user and model turns. The API uses the [ModelFormatter](https://github.com/google-ai-edge/ai-edge-apis/blob/main/local_agents/function_calling/java/com/google/ai/edge/localagents/fc/ModelFormatter.java) interface.\n- **Output Parser** : The FC SDK provides a parser that detects if the model's output represents a function call and parses it into a data structure for use by the application. The API uses the [ModelFormatter](https://github.com/google-ai-edge/ai-edge-apis/blob/main/local_agents/function_calling/java/com/google/ai/edge/localagents/fc/ModelFormatter.java) interface.\n- **Constrained Decoding** : An interface for creating and managing constraints to ensure that the generated output adheres to specific rules or conditions. For supported models, the FC SDK will configure the inference backend to use constrained decoding, which ensures that the model only outputs valid function names and parameters. The API uses the [ConstraintProvider](https://github.com/google-ai-edge/ai-edge-apis/blob/main/local_agents/function_calling/java/com/google/ai/edge/localagents/fc/ConstraintProvider.java) interface."]]