Table of Contents

⚙️ Function Calling Demo Overview


🎯 Purpose of the Sample

The Function Calling Demo showcases how to use the LM-Kit.NET SDK to interact with language models in a way that allows them to call predefined functions based on user input. This sample demonstrates the integration of function calling capabilities within a language model, enabling the model to perform specific tasks such as retrieving information from an external source and returning structured data. This functionality is ideal for creating AI-powered applications that can execute dynamic tasks based on natural language prompts.


👥 Industry Target Audience

This sample is particularly useful for developers and organizations in the following sectors:

  • 🛠️ Software Development: Developers looking to integrate AI-driven function execution into their applications.
  • 🤖 AI and Automation: Teams building intelligent systems that require dynamic interaction with external APIs or services.
  • 📚 Information Retrieval: Organizations needing automated data retrieval and processing from various online sources.
  • 🔍 Research and Development: Researchers exploring advanced AI model capabilities for executing complex tasks.

🚀 Problem Solved

Many applications require the ability to perform tasks dynamically based on user input. Traditionally, this has required extensive conditional logic and pre-programmed responses. The Function Calling Demo simplifies this process by using a language model to interpret user input and directly call the necessary functions to complete the task. This not only streamlines development but also opens up new possibilities for creating more interactive and responsive applications.


💻 Sample Application Description

The Function Calling Demo is a console application that allows users to interact with a language model, which in turn can call predefined functions to retrieve information or perform tasks. For this demo, the model is integrated with a set of functions that interact with the Open Library API, allowing users to retrieve book-related information such as author names, publication details, and book counts.

✨ Key Features

  • 📈 Model Selection: Users can choose from multiple pre-trained models.
  • 🔗 Function Integration: The demo integrates with external functions that can be called based on natural language prompts.
  • 📚 Book Information Retrieval: Supports retrieval of book-related information using the Open Library API.
  • 🧩 Dynamic Task Execution: The model interprets user input and dynamically selects the appropriate function to execute.

🧠 Supported Models

The sample supports the following pre-trained models for function calling and interaction:

  • Mistral Nemo 2407 12.2B
  • Meta Llama 3.1 8B
  • Google Gemma2 9B Medium
  • Microsoft Phi-3 3.82B Mini
  • Alibaba Qwen-2 7.6B

🛠️ Getting Started

📋 Prerequisites

  • .NET Framework 4.6.2 or .NET 6.0

📥 Download the Project

▶️ Running the Application

  1. 📂 Clone the repository:

    git clone https://github.com/LM-Kit/lm-kit-net-samples.git
    
  2. 📁 Navigate to the project directory:

    cd lm-kit-net-samples/console_framework_4.62/function_calling
    

    or

    cd lm-kit-net-samples/console_net6/function_calling
    
  3. 🔨 Build and run the application:

    dotnet build
    dotnet run
    

💡 Example Usage

  1. Set the License Key (if available):

    LMKit.Licensing.LicenseManager.SetLicenseKey(""); // Set an optional license key here if available.
    
  2. Select the Model: The application will prompt you to select one of the pre-defined models or enter a custom model URI.

  3. Enter Your Query:

    Type your query: What is the most recent work by Stephen K?
    
  4. View the Result: The application will interpret the query, call the appropriate function, and return the result. For example, it might return the author’s name or details about the book.

    Invoking method GetLastBookFromAuthor...
    Result: Cambridge Primary Mathematics Grade 5 Based on National Curriculum of Pakistan 2020, publish year: 2024
    

By following these steps, developers can explore the function calling capabilities of LM-Kit.NET, enabling their applications to perform tasks based on natural language prompts. This demo provides a foundational approach for integrating AI-driven function execution into more complex systems, facilitating intelligent automation and enhanced user interaction.