mlc-ai / mlc-llm

Universal LLM Deployment Engine with ML Compilation
https://llm.mlc.ai/
Apache License 2.0
19.31k stars 1.59k forks source link

[Question] How to use function calling in MLCChat Android app? #2589

Open wqwz111 opened 5 months ago

wqwz111 commented 5 months ago

❓ General Questions

Currently I use the Qwen2-1.5B-Instruct model. I see there is a tools parameter in ChatCompletionRequest, but I am not clear how to construct the parameters property of ChatFunction. Could you please provide any example?

wqwz111 commented 5 months ago

Can I create the ChatTool instance like this:

val chatTool = ChatTool(
    function = ChatFunction(
        name = "get_current_weather",
        description = "Get the current weather",
        parameters = mapOf(
            "type" to "object",
            "properties" to """
                |{
                |    "location": {
                |        "type": "string",
                |        "description": "The city and state, e.g. San Francisco, CA",
                |    },
                |    "format": {
                |        "type": "string",
                |        "enum": ["celsius", "fahrenheit"],
                |        "description": "The temperature unit to use. Infer this from the users location.",
                |    },
                |}
            """.trimMargin(),
            "required" to "[\"location\", \"format\"]"
        )
    )
)
Mawriyo commented 4 months ago

Would Like to know this too!

chowwil commented 4 months ago

I am interested in this as well. I want to try function calling with the Mistral 3 Instruct model because that should also support function calling. I know how to do it using Python and their API but not through Java using the MLC Chat interface.

zhb-code commented 3 months ago

Would Like to know this too! @tqchen