lorax icon indicating copy to clipboard operation
lorax copied to clipboard

feat: Function calling with output schema enforcement

Open jeffreyftang opened this issue 1 year ago • 6 comments

Introduces function-calling capabilities with JSON schema enforcement on output.

Example using Mistral-7B-Instruct-v0.3:

curl 127.0.0.1:8080/generate -X POST -d '{
   "inputs": "WHat is the current temperature of New York, San Francisco and Chicago?",
   "parameters": {
       "max_new_tokens": 512,
        "tools": [
            {
                "type": "function",
                "function": {
                    "name": "get_current_weather",
                    "description": "Get the current weather in a given location",
                    "parameters": {
                        "type": "object",
                        "properties": {
                            "location": {
                                "type": "string",
                                "description": "The city and state, e.g. San Francisco, CA"
                            },
                            "unit": {
                                "type": "string",
                                "enum": [
                                    "celsius",
                                    "fahrenheit"
                                ]
                            }
                        }
                    }
                }
            }
        ]
   }
}' -H 'Content-Type: application/json'


{"generated_text":"[{ \"id\": \"00000173499999999683\", \"type\": \"function\", \"function\": { \"name\": \"get_current_weather\", \"arguments\": { \"location\": \"New York\" } } },{ \"id\": \"00000173499999999684\", \"type\": \"function\", \"function\": { \"name\": \"get_current_weather\", \"arguments\": { \"location\": \"San Francisco\" } } },{ \"id\": \"00000173499999999685\", \"type\": \"function\", \"function\": { \"name\": \"get_current_weather\", \"arguments\": { \"location\": \"Chicago\" } } }]"}

jeffreyftang avatar Jul 11 '24 14:07 jeffreyftang

@tgaddair @magdyksaleh

Waiting for this merge to try out Function Calling in Lorax

llama-shepard avatar Jul 17 '24 20:07 llama-shepard

Failing test doesn't seem related, but will have to dig more.

jeffreyftang avatar Jul 17 '24 21:07 jeffreyftang

@magdyksaleh Still waiting for this feature. I want to deploy Mistral Nemo and Llama 3.1 models with function calling

llama-shepard avatar Jul 23 '24 20:07 llama-shepard

I have been waiting for function calling feature for long time and got exited for this PR. But this PR is still not merged.

@tgaddair @jeffreyftang

llama-shepard avatar Aug 02 '24 14:08 llama-shepard

@llama-shepard Sorry, I've been preoccupied with other obligations. What's remaining on this PR is to verify that pulling in chat templates will provide support for models other than mistral 3 (which is already working).

jeffreyftang avatar Aug 02 '24 18:08 jeffreyftang

This would be extremely useful for me. When can we expect this to be merged?

nikhilh avatar Aug 21 '24 17:08 nikhilh

@tgaddair Hey, do you have any documents regarding this feature?

prd-tuong-nguyen avatar Oct 22 '24 10:10 prd-tuong-nguyen