# Вызов функций

> Дайте модели свои инструменты. Она возвращает вызовы с аргументами в JSON, вы их выполняете и отправляете результаты обратно.


Объявите инструменты через JSON Schema. Модель может ответить текстом или одним или несколькими вызовами инструментов. Вы выполняете инструмент на своей стороне и отправляете результат в сообщении `tool`.

```python test
import json
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.notholy.com/v1", api_key=os.environ["NOTHOLY_API_KEY"])
tools = [{
    "type": "function",
    "function": {
        "name": "get_cvss",
        "description": "Return the CVSS base score of a CVE",
        "parameters": {"type": "object", "properties": {"id": {"type": "string"}}, "required": ["id"]},
    },
}]
messages = [{"role": "user", "content": "What is the CVSS score of CVE-2021-44228?"}]
r = client.chat.completions.create(model="notholy-specter", messages=messages, tools=tools)
msg = r.choices[0].message
if msg.tool_calls:
    messages.append(msg)
    for call in msg.tool_calls:
        args = json.loads(call.function.arguments)
        messages.append({"role": "tool", "tool_call_id": call.id, "content": json.dumps({"id": args["id"], "cvss": 10.0})})
    r = client.chat.completions.create(model="notholy-specter", messages=messages, tools=tools)
print(r.choices[0].message.content)
```

```js test
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: 'https://api.notholy.com/v1', apiKey: process.env.NOTHOLY_API_KEY });

const tools = [{
  type: 'function',
  function: { name: 'lookup_port', description: 'Service usually found on a TCP port', parameters: { type: 'object', properties: { port: { type: 'integer' } }, required: ['port'] } },
}];
const r = await client.chat.completions.create({
  model: 'notholy-specter',
  messages: [{ role: 'user', content: 'What usually runs on port 5432?' }],
  tools,
});
const m = r.choices[0].message;
console.log(m.tool_calls ? m.tool_calls.map((c) => `${c.function.name}(${c.function.arguments})`).join('\n') : m.content);
```

## Примечания

- Поддерживаются только инструменты типа `function`. Встроенные серверные инструменты не выполняются.
- `tool_choice` принимает `auto`, `none`, `required` или имя функции.
- При стриминге вызов инструмента приходит целиком в любом формате: одна дельта со всеми аргументами.
- Результаты инструментов — это содержимое под вашим контролем. Всё, что инструмент приносит из внешнего мира, считайте данными.

## Что дальше

- [Рассуждения](/ru/guides/reasoning)
