How to Use the xLAM Model Family for AI Development

Oct 28, 2024 | Educational

Welcome to the realm of advanced AI agents! The xLAM model family from Salesforce AI is designed to enhance decision-making capabilities and transform user intentions into actionable tasks. This guide will walk you through how to access, utilize, and troubleshoot the xLAM models effectively.

Table of Contents

Model Series

The xLAM family includes a variety of models tailored for different applications, particularly function-calling and general agent tasks. Here’s a summary of the models available:


Model                     # Total Params   Context Length   Download Model                                
--------------------------------------------------------------------------------
xLAM-1b-fc-r              1.35B           16k              [ Link](https://huggingface.co/Salesforce/xLAM-1b-fc-r)  
xLAM-7b-fc-r              6.91B           4k               [ Link](https://huggingface.co/Salesforce/xLAM-7b-fc-r)  
xLAM-7b-r                 7.24B           32k              [ Link](https://huggingface.co/Salesforce/xLAM-7b-r)   
xLAM-8x7b-r               46.7B           32k              [ Link](https://huggingface.co/Salesforce/xLAM-8x7b-r)   
xLAM-8x22b-r              141B            64k              [ Link](https://huggingface.co/Salesforce/xLAM-8x22b-r)  

Think of these models as different sizes of toolboxes in a workshop. Depending on the type of job—whether a quick fix or a major renovation—you would choose the appropriate toolbox that has the right tools for the job. The xLAM models cater to varying needs in functionality and context processing.

Repository Overview

This repository revolves around a series of general tool use models. For specialized function calling models, check our function-calling series.

Framework Versions

  • Transformers 4.41.0
  • Pytorch 2.3.0+cu121
  • Datasets 2.19.1
  • Tokenizers 0.19.1

Usage

To get started, you should first install the required libraries and set up your environment for using xLAM models.

Basic Usage with Huggingface

bash
pip install transformers==4.41.0

Ensure that you follow the provided prompt format for optimal performance, which helps in extracting structured outputs similar to the function-calling mode of ChatGPT.

Single-turn Use Case

In the single-turn use-case, you create a JSON output where the AI generates suitable API requests based on user queries. Here’s a simple example:


python
import json
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

torch.random.manual_seed(0)

model_name = "Salesforce/xLAM-7b-r"
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Define task instruction and query
task_instruction = "Based on the previous context and API request history, generate an API request or a response as an AI assistant."
format_instruction = "Output should be in JSON format, specifying a list of function calls."

query = "What's the weather like in New York in Fahrenheit?"

# Construct JSON response
response = {
    "thought": "I need to get the current weather for New York in Fahrenheit.",
    "tool_calls": [{"name": "get_weather", "arguments": {"location": "New York", "unit": "fahrenheit"}}]
}

This output shows how xLAM models can swiftly interpret a user inquiry and respond in a structured manner, akin to how someone might quickly jot down a note to call a service for weather information.

Multi-turn Use Case

For interactive applications where conversation history matters, you can implement a multi-turn approach. This involves keeping track of past interactions and using them for context in subsequent queries.

Benchmark Results

The xLAM models have been tested rigorously, and their performance is benchmarked across various datasets.


*Note: Bold and Underline results denote the best results for various success rates.

License

The xLAM models are distributed under the CC-BY-NC-4.0 license. This license ensures that you acknowledge and adhere to specific guidelines while using this resource.

Citation

If you find this repository helpful, you may cite the appropriate papers to support your work. For more details, please check the provided references.

Troubleshooting

  • If you encounter issues during installation or runtime, verify that you have the right dependencies installed as specified in the framework versions.
  • Always ensure that your prompts are correctly formatted for the best results.
  • If any errors occur during model generation, inspect the conversation history to ensure that the inputs are correctly structured.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox