SDK e thirrjes së funksionit AI Edge (FC SDK) është një bibliotekë që u mundëson zhvilluesve të përdorin thirrjet funksionale me LLM në pajisje. Thirrja e funksionit ju lejon të lidhni modelet me mjete të jashtme dhe API, duke u mundësuar modeleve të thërrasin funksione specifike me parametrat e nevojshëm për të ekzekutuar veprime në botën reale.
Në vend që të gjenerojë thjesht tekst, një LLM duke përdorur FC SDK mund të gjenerojë një thirrje të strukturuar për një funksion që ekzekuton një veprim, si kërkimi i informacionit të përditësuar, vendosja e alarmeve ose rezervimi.
AI Edge FC SDK është i disponueshëm për Android dhe mund të ekzekutohet plotësisht në pajisje me API-në LLM Inference. Filloni të përdorni SDK-në duke ndjekur udhëzuesin Android , i cili ju udhëzon përmes një zbatimi bazë të një aplikacioni mostër duke përdorur thirrjen e funksionit.
Funksioni i tubacionit thirrës
Vendosja e një LLM në pajisje me aftësi për thirrjen e funksionit kërkon hapat kryesorë të mëposhtëm:
Përcaktoni deklaratat e funksioneve : Struktura dhe parametrat e funksioneve që mund të thërrasë LLM duhet të përcaktohen në kodin e aplikacionit tuaj. Kjo përfshin specifikimin e emrave, parametrave dhe llojeve të funksioneve.
Formatoni kërkesat dhe daljet : Teksti hyrës dhe dalës mund të përmbajë thirrje të gjuhës natyrore dhe funksioneve. Një formatues kontrollon se si strukturat e të dhënave konvertohen në dhe nga vargjet, duke i mundësuar LLM të formatojë siç duhet informacionin.
Analizimi i rezultateve : Një analizues zbulon nëse përgjigja e gjeneruar përmban një thirrje funksioni dhe e analizon atë në një lloj të dhënash të strukturuar në mënyrë që aplikacioni të mund të ekzekutojë thirrjen e funksionit.
Ekzaminimi i përgjigjeve : Nëse analizuesi zbulon një thirrje funksioni, aplikacioni thërret funksionin me parametrat e duhur dhe llojin e të dhënave të strukturuar. Përndryshe, ai kthen tekstin e gjuhës natyrore.
Komponentët kryesorë
FC SDK përmban përbërësit kryesorë të mëposhtëm:
Inference Backend : Një ndërfaqe për ekzekutimin e konkluzioneve në një model gjenerues të AI. FC SDK përdor API-në e konkluzionit LLM për të ekzekutuar konkluzionet në modelet LiteRT (TFLite). API përdor ndërfaqen InferenceBackend .
Prompt Formatter : Një ndërfaqe për formatimin e kërkesave dhe përgjigjeve ndaj dhe nga modeli Generative AI. FC SDK siguron një formatues që konverton deklaratat e funksionit në formatin specifik të modelit të kërkuar nga LLM dhe i fut ato në kërkesën e sistemit. Formatuesi gjithashtu trajton shenjat specifike të modelit për të treguar kthesat e përdoruesit dhe modelit. API përdor ndërfaqen ModelFormatter .
Analizuesi i daljes : FC SDK siguron një analizues që zbulon nëse dalja e modelit përfaqëson një thirrje funksioni dhe e analizon atë në një strukturë të dhënash për përdorim nga aplikacioni. API përdor ndërfaqen ModelFormatter .
Dekodimi i kufizuar : Një ndërfaqe për krijimin dhe menaxhimin e kufizimeve për të siguruar që prodhimi i gjeneruar t'u përmbahet rregullave ose kushteve specifike. Për modelet e mbështetura, FC SDK do të konfigurojë fundin e përfundimit për të përdorur dekodimin e kufizuar, i cili siguron që modeli të nxjerrë vetëm emra dhe parametra të vlefshëm funksionesh. API përdor ndërfaqen ConstraintProvider .
[[["E lehtë për t'u kuptuar","easyToUnderstand","thumb-up"],["E zgjidhi problemin tim","solvedMyProblem","thumb-up"],["Tjetër","otherUp","thumb-up"]],[["Mungojnë informacionet që më nevojiten","missingTheInformationINeed","thumb-down"],["Shumë e ndërlikuar/shumë hapa","tooComplicatedTooManySteps","thumb-down"],["E papërditësuar","outOfDate","thumb-down"],["Problem përkthimi","translationIssue","thumb-down"],["Problem me kampionët/kodin","samplesCodeIssue","thumb-down"],["Tjetër","otherDown","thumb-down"]],["Përditësimi i fundit: 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."]]