README.md 1.47 KB
Newer Older
chenzk's avatar
v1.0  
chenzk committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# MiniCPM FunctionCall

1. Start VLLM functioncall server

```shell
python -m vllm.entrypoints.openai.api_server \
    --model openbmb/MiniCPM3-4B \
    --dtype auto \
    --api-key token-abc123 \
    --tensor-parallel-size 1 \
    --trust-remote-code \
    --enable-auto-tool-choice \
    --tool-call-parser minicpm \
    --tool-parser-plugin minicpm_tool_parser.py
```


2. Functioncall client example

```python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="token-abc123")

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"]},
        },
        "required": ["location"],
      },
    }
  }
]
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]
completion = client.chat.completions.create(
  model="openbmb/MiniCPM3-4B",
  messages=messages,
  tools=tools,
  tool_choice="auto"
)

print(completion)

```


3. Run functioncall inference locally

```shell
python functioncall.py
```


# Thanks

- resolve_ast_call and resolve_ast_by_type from [gorilla](https://github.com/ShishirPatil/gorilla)
- minicpm chat template with tool from @CISCai