GraySoft
Projects Models About FAQ Contact Download guIDE →
Model Intelligence Sheet

richarderkhov/salesforce_-_xlam-1b-fc-r-gguf overview

taskinstruction = """ You are an expert in composing functions. You are given a question and a set of possible functions. Based on the question, you will need to make one or more function/tool calls to achieve the purpose. If none of the functions can be used, point it out and refuse to answer. If the given question lacks the parameters required by the function, also point it out. """.strip() formatinstruction = """ The output MUST strictly adhere to the following JSON format, and NO other text MUST be included. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make toolcalls an empty list '[]'. """.strip() # Define the input query and available tools query = "What's the weather like in New York in fahrenheit?" getweatherapi = { "name": "getweather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, New York" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The unit of temperature to return" } }, "required": ["location"] } } searchapi = { "name": "search", "description": "Search for information on the internet", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The search query, e.g. 'latest news on AI'" } }, "required": ["query"] } } openaiformattools = [getweatherapi, searchapi] # Helper function to convert openai format tools to our more concise xLAM format def converttoxlamtool(tools): '''''' if isinstance(tools, dict): return { "name": tools["name"], "description": tools["description"], "parameters": {k: v for k, v in tools["parameters"].get("properties", {}).items()} } elif isinstance(tools, list): return [converttoxlamtool(tool) for tool in tools] else: return tools # Helper function to build the input prompt for our model def buildprompt(taskinstruction: str, formatinstruction: str, tools: list, query: str): prompt = f"[BEGIN OF TASK INSTRUCTION]\n{taskinstruction}\n[END OF TASK INSTRUCTION]\n\n" prompt += f"[BEGIN OF AVAILABLE TOOLS]\n{json.dumps(xlamformattools)}\n[END OF AVAILABLE TOOLS]\n\n" prompt += f"[BEGIN OF FORMAT INSTRUCTION]\n{formatinstruction}\n[END OF FORMAT INSTRUCTION]\n\n" prompt += f"[BEGIN OF QUERY]\n{query}\n[END OF QUERY]\n\n" return prompt # Build the input and start the inference xlamformattools = converttoxlamtool(openaiformattools) content = buildprompt(taskinstruction, formatinstruction, xlamformattools, query) messages=[ { 'role': 'user', 'content': content} ] inputs = tokenizer.applychattemplate(messages, addgenerationprompt=True, returntensors="pt").to(model.device) # tokenizer.eostokenid is the id of token outputs = model.generate(inputs, maxnewtokens=512, dosample=False, numreturnsequences=1, eostokenid=tokenizer.eostokenid) print(tokenizer.decode(outputs[0][len(inputs[0]):], skipspecialtokens=True)) shell {"toolcalls": [{"name": "getweather", "arguments": {"location": "New York", "unit": "fahrenheit"}}]} bash pip install vllm openai argparse jinja2 bash python testprompttemplate.py --model bash python -m vllm.entrypoints.openai.apiserver --model Salesforce/xLAM-1b-fc-r --served-model-name xlam-1b-fc-r --dtype bfloat16 --port 8001 bash python testxlammodelwithendpoint.py --modelname xlam-1b-fc-r --port 8001 [OPTIONS] bash python testxlammodelwith_vllm.py --model Salesforce/xLAM-1b-fc-r [OPTIONS] Options are the same as for the endpoint test. This test script also provides a handler implementation that can be easily applied to your customized function-calling applications. #### Customization These examples are designed to be flexible and easily integrated into your own projects. Feel free to modify the scripts to suit your specific needs and applications. You can adjust test queries or API definitions in each script to test different scenarios or model capabilities. Additional customization tips: These resources provide a robust foundation for integrating xLAM models into your applications, allowing for tailored and efficient deployment.

ggufarxiv:2406.18518endpoints_compatibleregion:usconversational
richarderkhov/salesforce_-_xlam-1b-fc-r-gguf visual
Downloads
831
Likes
1
Pipeline
Library
Visibility
Public
Access
Open

Repository Files & Downloads

22 files detected
Direct downloads for all repository files
FileTypeQuantizationSizeLink
xLAM-1b-fc-r.IQ3_M.gguf GGUF IQ3_M 641.62 MB Download
xLAM-1b-fc-r.IQ3_S.gguf GGUF IQ3_S 612.09 MB Download
xLAM-1b-fc-r.IQ3_XS.gguf GGUF IQ3_XS 584.95 MB Download
xLAM-1b-fc-r.IQ4_NL.gguf GGUF IQ4_NL 746.04 MB Download
xLAM-1b-fc-r.IQ4_XS.gguf GGUF IQ4_XS 715.94 MB Download
xLAM-1b-fc-r.Q2_K.gguf GGUF Q2_K 533.79 MB Download
xLAM-1b-fc-r.Q3_K.gguf GGUF Q3_K 671.51 MB Download
xLAM-1b-fc-r.Q3_K_L.gguf GGUF Q3_K_L 709.97 MB Download
xLAM-1b-fc-r.Q3_K_M.gguf GGUF Q3_K_M 671.51 MB Download
xLAM-1b-fc-r.Q3_K_S.gguf GGUF Q3_K_S 612.09 MB Download
xLAM-1b-fc-r.Q4_0.gguf GGUF 739.99 MB Download
xLAM-1b-fc-r.Q4_1.gguf GGUF 816.30 MB Download
xLAM-1b-fc-r.Q4_K.gguf GGUF Q4_K 832.99 MB Download
xLAM-1b-fc-r.Q4_K_M.gguf GGUF Q4_K_M 832.99 MB Download
xLAM-1b-fc-r.Q4_K_S.gguf GGUF Q4_K_S 776.26 MB Download
xLAM-1b-fc-r.Q5_0.gguf GGUF 892.62 MB Download
xLAM-1b-fc-r.Q5_1.gguf GGUF 968.93 MB Download
xLAM-1b-fc-r.Q5_K.gguf GGUF Q5_K 955.43 MB Download
xLAM-1b-fc-r.Q5_K_M.gguf GGUF Q5_K_M 955.43 MB Download
xLAM-1b-fc-r.Q5_K_S.gguf GGUF Q5_K_S 908.74 MB Download
xLAM-1b-fc-r.Q6_K.gguf GGUF Q6_K 1.09 GB Download
xLAM-1b-fc-r.Q8_0.gguf GGUF 1.33 GB Download

Model Details Live

Model Slug
richarderkhov/salesforce_-_xlam-1b-fc-r-gguf
Author
RichardErkhov
Pipeline Task
Library
Created
2024-08-23
Last Modified
2024-08-23
Gated
No
Private
No
HF SHA
c5fc2b4ef6820dfeff782727a6ea9b373804e58f
License
Unknown
Language
Unknown
Base Model
Unknown

Metadata Inspector

Normalized metadata (stored in metadata_json)
{
  "metadata": {},
  "card_data": {
    "frontmatter": {},
    "hero_image_url": "https://huggingface.co/datasets/jianguozhang/logos/resolve/main/xlam-no-background.png",
    "summary": "task_instruction = \"\"\" You are an expert in composing functions. You are given a question and a set of possible functions. Based on the question, you will need to make one or more function/tool calls to achieve the purpose. If none of the functions can be used, point it out and refuse to answer. If the given question lacks the parameters required by the function, also point it out. \"\"\".strip() format_instruction = \"\"\" The output MUST strictly adhere to the following JSON format, and NO other text MUST be included. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'. `` { \"tool_calls\": [ {\"name\": \"func_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}}, ... (more tool calls as required) ] } ` \"\"\".strip() # Define the input query and available tools query = \"What's the weather like in New York in fahrenheit?\" get_weather_api = { \"name\": \"get_weather\", \"description\": \"Get the current weather for a location\", \"parameters\": { \"type\": \"object\", \"properties\": { \"location\": { \"type\": \"string\", \"description\": \"The city and state, e.g. San Francisco, New York\" }, \"unit\": { \"type\": \"string\", \"enum\": [\"celsius\", \"fahrenheit\"], \"description\": \"The unit of temperature to return\" } }, \"required\": [\"location\"] } } search_api = { \"name\": \"search\", \"description\": \"Search for information on the internet\", \"parameters\": { \"type\": \"object\", \"properties\": { \"query\": { \"type\": \"string\", \"description\": \"The search query, e.g. 'latest news on AI'\" } }, \"required\": [\"query\"] } } openai_format_tools = [get_weather_api, search_api] # Helper function to convert openai format tools to our more concise xLAM format def convert_to_xlam_tool(tools): '''''' if isinstance(tools, dict): return { \"name\": tools[\"name\"], \"description\": tools[\"description\"], \"parameters\": {k: v for k, v in tools[\"parameters\"].get(\"properties\", {}).items()} } elif isinstance(tools, list): return [convert_to_xlam_tool(tool) for tool in tools] else: return tools # Helper function to build the input prompt for our model def build_prompt(task_instruction: str, format_instruction: str, tools: list, query: str): prompt = f\"[BEGIN OF TASK INSTRUCTION]\\n{task_instruction}\\n[END OF TASK INSTRUCTION]\\n\\n\" prompt += f\"[BEGIN OF AVAILABLE TOOLS]\\n{json.dumps(xlam_format_tools)}\\n[END OF AVAILABLE TOOLS]\\n\\n\" prompt += f\"[BEGIN OF FORMAT INSTRUCTION]\\n{format_instruction}\\n[END OF FORMAT INSTRUCTION]\\n\\n\" prompt += f\"[BEGIN OF QUERY]\\n{query}\\n[END OF QUERY]\\n\\n\" return prompt # Build the input and start the inference xlam_format_tools = convert_to_xlam_tool(openai_format_tools) content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query) messages=[ { 'role': 'user', 'content': content} ] inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors=\"pt\").to(model.device) # tokenizer.eos_token_id is the id of  token outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id) print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)) `` Then you should be able to see the following output string in JSON format: `shell {\"tool_calls\": [{\"name\": \"get_weather\", \"arguments\": {\"location\": \"New York\", \"unit\": \"fahrenheit\"}}]} ` We highly recommend to use our provided prompt format and helper functions to yield the best function-calling performance of our model. ### Usage with vLLM We provide example scripts to deploy our model with vllm and run inferences. First, install the required packages: `bash pip install vllm openai argparse jinja2 ` The example scripts are located in the examples folder. #### 1. Test Prompt Template To build prompts using the chat template and output formatted prompts ready for various test cases, run: `bash python test_prompt_template.py --model ` #### 2. Test xLAM Model with a Manually Served Endpoint a. Serve the model with vLLM: `bash python -m vllm.entrypoints.openai.api_server --model Salesforce/xLAM-1b-fc-r --served-model-name xlam-1b-fc-r --dtype bfloat16 --port 8001 ` b. Run the test script: `bash python test_xlam_model_with_endpoint.py --model_name xlam-1b-fc-r --port 8001 [OPTIONS] ` Options: This test script provides a handler implementation that can be easily applied to your customized function-calling applications. #### 3. Test xLAM Model by Directly Using vLLM Library To test the xLAM model directly with the vLLM library, run: `bash python test_xlam_model_with_vllm.py --model Salesforce/xLAM-1b-fc-r [OPTIONS] `` Options are the same as for the endpoint test. This test script also provides a handler implementation that can be easily applied to your customized function-calling applications. #### Customization These examples are designed to be flexible and easily integrated into your own projects. Feel free to modify the scripts to suit your specific needs and applications. You can adjust test queries or API definitions in each script to test different scenarios or model capabilities. Additional customization tips: These resources provide a robust foundation for integrating xLAM models into your applications, allowing for tailored and efficient deployment.",
    "quick_links": [],
    "benchmark_table_html": "",
    "readme_markdown": "Quantization made by Richard Erkhov.\n\n[Github](https://github.com/RichardErkhov)\n\n[Discord](https://discord.gg/pvy7H8DZMG)\n\n[Request more models](https://github.com/RichardErkhov/quant_request)\n\n\nxLAM-1b-fc-r - GGUF\n- Model creator: https://huggingface.co/Salesforce/\n- Original model: https://huggingface.co/Salesforce/xLAM-1b-fc-r/\n\n\n| Name | Quant method | Size |\n| ---- | ---- | ---- |\n| [xLAM-1b-fc-r.Q2_K.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q2_K.gguf) | Q2_K | 0.52GB |\n| [xLAM-1b-fc-r.IQ3_XS.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.IQ3_XS.gguf) | IQ3_XS | 0.57GB |\n| [xLAM-1b-fc-r.IQ3_S.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.IQ3_S.gguf) | IQ3_S | 0.6GB |\n| [xLAM-1b-fc-r.Q3_K_S.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q3_K_S.gguf) | Q3_K_S | 0.6GB |\n| [xLAM-1b-fc-r.IQ3_M.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.IQ3_M.gguf) | IQ3_M | 0.63GB |\n| [xLAM-1b-fc-r.Q3_K.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q3_K.gguf) | Q3_K | 0.66GB |\n| [xLAM-1b-fc-r.Q3_K_M.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q3_K_M.gguf) | Q3_K_M | 0.66GB |\n| [xLAM-1b-fc-r.Q3_K_L.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q3_K_L.gguf) | Q3_K_L | 0.69GB |\n| [xLAM-1b-fc-r.IQ4_XS.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.IQ4_XS.gguf) | IQ4_XS | 0.7GB |\n| [xLAM-1b-fc-r.Q4_0.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q4_0.gguf) | Q4_0 | 0.72GB |\n| [xLAM-1b-fc-r.IQ4_NL.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.IQ4_NL.gguf) | IQ4_NL | 0.73GB |\n| [xLAM-1b-fc-r.Q4_K_S.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q4_K_S.gguf) | Q4_K_S | 0.76GB |\n| [xLAM-1b-fc-r.Q4_K.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q4_K.gguf) | Q4_K | 0.81GB |\n| [xLAM-1b-fc-r.Q4_K_M.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q4_K_M.gguf) | Q4_K_M | 0.81GB |\n| [xLAM-1b-fc-r.Q4_1.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q4_1.gguf) | Q4_1 | 0.8GB |\n| [xLAM-1b-fc-r.Q5_0.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q5_0.gguf) | Q5_0 | 0.87GB |\n| [xLAM-1b-fc-r.Q5_K_S.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q5_K_S.gguf) | Q5_K_S | 0.89GB |\n| [xLAM-1b-fc-r.Q5_K.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q5_K.gguf) | Q5_K | 0.93GB |\n| [xLAM-1b-fc-r.Q5_K_M.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q5_K_M.gguf) | Q5_K_M | 0.93GB |\n| [xLAM-1b-fc-r.Q5_1.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q5_1.gguf) | Q5_1 | 0.95GB |\n| [xLAM-1b-fc-r.Q6_K.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q6_K.gguf) | Q6_K | 1.09GB |\n| [xLAM-1b-fc-r.Q8_0.gguf](https://huggingface.co/RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf/blob/main/xLAM-1b-fc-r.Q8_0.gguf) | Q8_0 | 1.33GB |\n\n\n\n\nOriginal model description:\n---\nextra_gated_heading: >-\n  Acknowledge to follow corresponding license to access the\n  repository\nextra_gated_button_content: Agree and access repository\nextra_gated_fields:\n  First Name: text\n  Last Name: text\n  Country: country\n  Affiliation: text\nlicense: cc-by-nc-4.0\ndatasets:\n- Salesforce/xlam-function-calling-60k\nlanguage:\n- en\npipeline_tag: text-generation\ntags:\n- function-calling\n- LLM Agent\n- tool-use\n- deepseek\n- pytorch\n---\n\n<p align=\"center\">\n<img width=\"500px\" alt=\"xLAM\" src=\"https://huggingface.co/datasets/jianguozhang/logos/resolve/main/xlam-no-background.png\">\n</p>\n<p align=\"center\">\n  <a href=\"https://apigen-pipeline.github.io/\">[Homepage]</a>  |  \n  <a href=\"https://arxiv.org/abs/2406.18518\">[Paper]</a> | \n  <a href=\"https://huggingface.co/datasets/Salesforce/xlam-function-calling-60k\">[Dataset]</a> | \n  <a href=\"https://github.com/SalesforceAIResearch/xLAM\">[Github]</a>\n</p>\n<hr>\n\nWelcome to the xLAM model family! [Large Action Models (LAMs)](https://blog.salesforceairesearch.com/large-action-models/) are advanced large language models designed to enhance decision-making and translate user intentions into executable actions that interact with the world. LAMs autonomously plan and execute tasks to achieve specific goals, serving as the brains of AI agents. They have the potential to automate workflow processes across various domains, making them invaluable for a wide range of applications.\n\n## Table of Contents\n- [Model Series](#model-series)\n- [Repository Overview](#repository-overview)\n- [Benchmark Results](#benchmark-results)\n- [Usage](#usage)\n  - [Basic Usage with Huggingface](#basic-usage-with-huggingface)\n  - [Usage with vLLM](#usage-with-vllm)\n- [License](#license)\n- [Citation](#citation)\n\n## Model Series\n\nWe provide a series of xLAMs in different sizes to cater to various applications, including those optimized for function-calling and general agent applications:\n\n| Model                  | # Total Params | Context Length | Download Model  | Download GGUF files |\n|------------------------|----------------|----------------|----------------|----------|\n| xLAM-1b-fc-r           | 1.35B          | 16384            | [🤗 Link](https://huggingface.co/Salesforce/xLAM-1b-fc-r) | [🤗 Link](https://huggingface.co/Salesforce/xLAM-1b-fc-r-gguf) |\n| xLAM-7b-fc-r           | 6.91B          | 4096             | [🤗 Link](https://huggingface.co/Salesforce/xLAM-7b-fc-r) | [🤗 Link](https://huggingface.co/Salesforce/xLAM-7b-fc-r-gguf) |   |\n\nThe `fc` series of models are optimized for function-calling capability, providing fast, accurate, and structured responses based on input queries and available APIs. These models are fine-tuned based on the [deepseek-coder](https://huggingface.co/collections/deepseek-ai/deepseek-coder-65f295d7d8a0a29fe39b4ec4) models and are designed to be small enough for deployment on personal devices like phones or computers.\n\nWe also provide their quantized [GGUF](https://huggingface.co/docs/hub/en/gguf) files for efficient deployment and execution. GGUF is a file format designed to efficiently store and load large language models, making GGUF ideal for running AI models on local devices with limited resources, enabling offline functionality and enhanced privacy.\n\nFor more details, check our [GitHub](https://github.com/SalesforceAIResearch/xLAM) and [paper](https://arxiv.org/abs/2406.18518).\n\n## Repository Overview\n\nThis repository is focused on our tiny `xLAM-1b-fc-r` model, which is optimized for function-calling and can be easily deployed on personal devices.\n\n<div align=\"center\">\n<img src=\"https://github.com/apigen-pipeline/apigen-pipeline.github.io/blob/main/img/function-call-overview.png?raw=true\"\nalt=\"drawing\" width=\"620\"/>\n</div>\n\nFunction-calling, or tool use, is one of the key capabilities for AI agents. It requires the model not only understand and generate human-like text but also to execute functional API calls based on natural language instructions. This extends the utility of LLMs beyond simple conversation tasks to dynamic interactions with a variety of digital services and applications, such as retrieving weather information, managing social media platforms, and handling financial services.\n\nThe instructions will guide you through the setup, usage, and integration of `xLAM-1b-fc-r` with HuggingFace and vLLM.\nWe will first introduce the basic usage, and then walk through the provided tutorial and example scripts in the [examples](https://huggingface.co/Salesforce/xLAM-1b-fc-r/tree/main/examples) folder.\n\n### Framework Versions\n\n- Transformers 4.41.0\n- Pytorch 2.3.0+cu121\n- Datasets 2.19.1\n- Tokenizers 0.19.1\n\n## Benchmark Results\n\nWe mainly test our function-calling models on the [Berkeley Function-Calling Leaderboard (BFCL)](https://gorilla.cs.berkeley.edu/leaderboard.html), which offers a comprehensive evaluation framework for assessing LLMs' function-calling capabilities across various programming languages and application domains like Java, JavaScript, and Python. \n\n\n<div align=\"center\">\n<img src=\"https://github.com/apigen-pipeline/apigen-pipeline.github.io/blob/main/img/table-result-0718.png?raw=true\" width=\"620\" alt=\"Performance comparison on Berkeley Function-Calling Leaderboard\">\n<p>Performance comparison on the BFCL benchmark as of date 07/18/2024. Evaluated with <code>temperature=0.001</code> and <code>top_p=1</code></p> \n</div>\n\n<p>Our <code>xLAM-7b-fc-r</code> secures the 3rd place with an overall accuracy of 88.24% on the leaderboard, outperforming many strong models. Notably, our <code>xLAM-1b-fc-r</code> model is the only tiny model with less than 2B parameters on the leaderboard, but still achieves a competitive overall accuracy of 78.94% and outperforming GPT3-Turbo and many larger models.\nBoth models exhibit balanced performance across various categories, showing their strong function-calling capabilities despite their small sizes.</p>\n\nSee our [paper](https://arxiv.org/abs/2406.18518) and Github [repo](https://github.com/SalesforceAIResearch/xLAM) for more detailed analysis.\n\n\n## Usage\n\n### Basic Usage with Huggingface\n\nTo use the `xLAM-1b-fc-r` model from Huggingface, please first install the `transformers` library:\n```bash\npip install transformers>=4.41.0\n```\n\nWe use the following example to illustrate how to use our model to perform function-calling tasks. \nPlease note that, our model works best with our provided prompt format. \nIt allows us to extract JSON output that is similar to the [function-calling mode of ChatGPT](https://platform.openai.com/docs/guides/function-calling).\n\n````python\nimport json\nimport torch \nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\ntorch.random.manual_seed(0) \n\nmodel_name = \"Salesforce/xLAM-1b-fc-r\"\nmodel = AutoModelForCausalLM.from_pretrained(model_name, device_map=\"auto\", torch_dtype=\"auto\", trust_remote_code=True)\ntokenizer = AutoTokenizer.from_pretrained(model_name) \n\n# Please use our provided instruction prompt for best performance\ntask_instruction = \"\"\"\nYou are an expert in composing functions. You are given a question and a set of possible functions. \nBased on the question, you will need to make one or more function/tool calls to achieve the purpose. \nIf none of the functions can be used, point it out and refuse to answer. \nIf the given question lacks the parameters required by the function, also point it out.\n\"\"\".strip()\n\nformat_instruction = \"\"\"\nThe output MUST strictly adhere to the following JSON format, and NO other text MUST be included.\nThe example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.\n```\n{\n    \"tool_calls\": [\n    {\"name\": \"func_name1\", \"arguments\": {\"argument1\": \"value1\", \"argument2\": \"value2\"}},\n    ... (more tool calls as required)\n    ]\n}\n```\n\"\"\".strip()\n\n# Define the input query and available tools\nquery = \"What's the weather like in New York in fahrenheit?\"\n\nget_weather_api = {\n    \"name\": \"get_weather\",\n    \"description\": \"Get the current weather for a location\",\n    \"parameters\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"location\": {\n                \"type\": \"string\",\n                \"description\": \"The city and state, e.g. San Francisco, New York\"\n            },\n            \"unit\": {\n                \"type\": \"string\",\n                \"enum\": [\"celsius\", \"fahrenheit\"],\n                \"description\": \"The unit of temperature to return\"\n            }\n        },\n        \"required\": [\"location\"]\n    }\n}\n\nsearch_api = {\n    \"name\": \"search\",\n    \"description\": \"Search for information on the internet\",\n    \"parameters\": {\n        \"type\": \"object\",\n        \"properties\": {\n            \"query\": {\n                \"type\": \"string\",\n                \"description\": \"The search query, e.g. 'latest news on AI'\"\n            }\n        },\n        \"required\": [\"query\"]\n    }\n}\n\nopenai_format_tools = [get_weather_api, search_api]\n\n# Helper function to convert openai format tools to our more concise xLAM format\ndef convert_to_xlam_tool(tools):\n    ''''''\n    if isinstance(tools, dict):\n        return {\n            \"name\": tools[\"name\"],\n            \"description\": tools[\"description\"],\n            \"parameters\": {k: v for k, v in tools[\"parameters\"].get(\"properties\", {}).items()}\n        }\n    elif isinstance(tools, list):\n        return [convert_to_xlam_tool(tool) for tool in tools]\n    else:\n        return tools\n\n# Helper function to build the input prompt for our model\ndef build_prompt(task_instruction: str, format_instruction: str, tools: list, query: str):\n    prompt = f\"[BEGIN OF TASK INSTRUCTION]\\n{task_instruction}\\n[END OF TASK INSTRUCTION]\\n\\n\"\n    prompt += f\"[BEGIN OF AVAILABLE TOOLS]\\n{json.dumps(xlam_format_tools)}\\n[END OF AVAILABLE TOOLS]\\n\\n\"\n    prompt += f\"[BEGIN OF FORMAT INSTRUCTION]\\n{format_instruction}\\n[END OF FORMAT INSTRUCTION]\\n\\n\"\n    prompt += f\"[BEGIN OF QUERY]\\n{query}\\n[END OF QUERY]\\n\\n\"\n    return prompt\n    \n# Build the input and start the inference\nxlam_format_tools = convert_to_xlam_tool(openai_format_tools)\ncontent = build_prompt(task_instruction, format_instruction, xlam_format_tools, query)\n\nmessages=[\n    { 'role': 'user', 'content': content}\n]\ninputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors=\"pt\").to(model.device)\n\n# tokenizer.eos_token_id is the id of <|EOT|> token\noutputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)\nprint(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))\n````\n\nThen you should be able to see the following output string in JSON format:\n\n```shell\n{\"tool_calls\": [{\"name\": \"get_weather\", \"arguments\": {\"location\": \"New York\", \"unit\": \"fahrenheit\"}}]}\n```\n\nWe highly recommend to use our provided prompt format and helper functions to yield the best function-calling performance of our model.\n\n### Usage with vLLM\n\nWe provide example scripts to deploy our model with `vllm` and run inferences. First, install the required packages:\n\n```bash\npip install vllm openai argparse jinja2\n```\n\nThe example scripts are located in the [examples](https://huggingface.co/Salesforce/xLAM-1b-fc-r/tree/main/examples) folder.\n\n#### 1. Test Prompt Template\n\nTo build prompts using the chat template and output formatted prompts ready for various test cases, run:\n\n```bash\npython test_prompt_template.py --model \n```\n\n#### 2. Test xLAM Model with a Manually Served Endpoint\n\na. Serve the model with vLLM:\n\n```bash\npython -m vllm.entrypoints.openai.api_server --model Salesforce/xLAM-1b-fc-r --served-model-name xlam-1b-fc-r --dtype bfloat16 --port 8001\n```\n\nb. Run the test script:\n\n```bash\npython test_xlam_model_with_endpoint.py --model_name xlam-1b-fc-r --port 8001 [OPTIONS]\n```\n\nOptions:\n- `--temperature`: Default 0.3\n- `--top_p`: Default 1.0\n- `--max_tokens`: Default 512\n\nThis test script provides a handler implementation that can be easily applied to your customized function-calling applications.\n\n#### 3. Test xLAM Model by Directly Using vLLM Library\n\nTo test the xLAM model directly with the vLLM library, run:\n\n```bash\npython test_xlam_model_with_vllm.py --model Salesforce/xLAM-1b-fc-r [OPTIONS]\n```\n\nOptions are the same as for the endpoint test. This test script also provides a handler implementation that can be easily applied to your customized function-calling applications.\n\n#### Customization\n\nThese examples are designed to be flexible and easily integrated into your own projects. Feel free to modify the scripts to suit your specific needs and applications. You can adjust test queries or API definitions in each script to test different scenarios or model capabilities.\n\nAdditional customization tips:\n- Modify the `--dtype` parameter when serving the model based on your GPU capacity.\n- Refer to the vLLM documentation for more detailed configuration options.\n- Explore the `demo.ipynb` file for a comprehensive description of the entire workflow, including how to execute APIs.\n\nThese resources provide a robust foundation for integrating xLAM models into your applications, allowing for tailored and efficient deployment.\n\n## License\n\n`xLAM-1b-fc-r` is distributed under the CC-BY-NC-4.0 license, with additional terms specified in the [Deepseek license](https://github.com/deepseek-ai/DeepSeek-LLM/blob/main/LICENSE-MODEL).\n\n## Citation\n\nIf you find this repo helpful, please cite our paper:\n```bibtex\n@article{liu2024apigen,\n  title={APIGen: Automated Pipeline for Generating Verifiable and Diverse Function-Calling Datasets},\n  author={Liu, Zuxin and Hoang, Thai and Zhang, Jianguo and Zhu, Ming and Lan, Tian and Kokane, Shirley and Tan, Juntao and Yao, Weiran and Liu, Zhiwei and Feng, Yihao and others},\n  journal={arXiv preprint arXiv:2406.18518},\n  year={2024}\n}\n```\n\n\n",
    "related_quantizations": []
  },
  "tags": [
    "gguf",
    "arxiv:2406.18518",
    "endpoints_compatible",
    "region:us",
    "conversational"
  ],
  "likes": 1,
  "downloads": 831,
  "gated": false,
  "private": false,
  "last_modified": "2024-08-23T06:19:19.000Z",
  "created_at": "2024-08-23T05:46:15.000Z",
  "pipeline_tag": "",
  "library_name": ""
}
Source payload excerpt (from Hugging Face API)
{
  "_id": "66c82227380e8fb44ac0eb75",
  "id": "RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf",
  "modelId": "RichardErkhov/Salesforce_-_xLAM-1b-fc-r-gguf",
  "sha": "c5fc2b4ef6820dfeff782727a6ea9b373804e58f",
  "createdAt": "2024-08-23T05:46:15.000Z",
  "lastModified": "2024-08-23T06:19:19.000Z",
  "author": "RichardErkhov",
  "downloads": 831,
  "likes": 1,
  "gated": false,
  "private": false,
  "pipeline_tag": "",
  "library_name": "",
  "siblings_count": 24
}