{"id":504740,"date":"2026-11-25T13:14:07","date_gmt":"2026-11-25T10:14:07","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=504740"},"modified":"2026-11-25T13:14:07","modified_gmt":"2026-11-25T10:14:07","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=504740","title":{"rendered":"GigaChat API \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435: \u0442\u043e\u043a\u0435\u043d \u043d\u0430 30 \u043c\u0438\u043d\u0443\u0442, \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b, \u0444\u0430\u0439\u043b\u044b \u0438 JSON"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u043b GigaChat \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0430 Node.js, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 OpenAI-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0445\u0432\u0430\u0442\u0438\u0442 \u0441\u043c\u0435\u043d\u0438\u0442\u044c base URL \u0438 \u043a\u043b\u044e\u0447. \u041d\u0430 \u0434\u0435\u043b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u043d\u0430\u0431\u0440\u0430\u043b\u043e\u0441\u044c \u0448\u0435\u0441\u0442\u044c, \u0438 \u043a\u0430\u0436\u0434\u043e\u0435 \u043b\u043e\u043c\u0430\u0435\u0442 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 OpenAI. \u041d\u0438\u0436\u0435 \u043e\u043d\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443: \u0447\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438\u043b\u0435\u0442\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a \u044f \u044d\u0442\u043e \u043e\u0431\u043e\u0448\u0451\u043b. \u0421 \u043a\u043e\u0434\u043e\u043c.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/a3\/a4\/23\/a3a4235ff3977bb797a77b2db4ece65b.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/a3\/a4\/23\/a3a4235ff3977bb797a77b2db4ece65b.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/a3\/a4\/23\/a3a4235ff3977bb797a77b2db4ece65b.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h3>1. \u0422\u043e\u043a\u0435\u043d \u0436\u0438\u0432\u0451\u0442 30 \u043c\u0438\u043d\u0443\u0442<\/h3>\n<p>\u0412 \u043b\u0438\u0447\u043d\u043e\u043c \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0435 GigaChat API \u0432\u044b\u0434\u0430\u0451\u0442\u0441\u044f \u00ab\u043a\u043b\u044e\u0447 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438\u00bb: \u0432 \u043d\u0451\u043c \u0443\u0436\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b Client ID \u0438 \u0441\u0435\u043a\u0440\u0435\u0442. \u0412 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043d \u043d\u0435 \u0445\u043e\u0434\u0438\u0442. \u0415\u0433\u043e \u043c\u0435\u043d\u044f\u044e\u0442 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0445\u043e\u0441\u0442, \u0438 \u0442\u043e\u043a\u0435\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 30 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>\u0414\u0432\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>RqUID<\/code> \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u043e\u0432\u044b\u043c uuid4 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u043c\u0435\u043d, \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 400. \u0410 <code>scope<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0442\u0430\u0440\u0438\u0444\u043e\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u043e\u0435\u043a\u0442: <code>GIGACHAT_API_PERS<\/code>, <code>GIGACHAT_API_B2B<\/code> \u0438\u043b\u0438 <code>GIGACHAT_API_CORP<\/code>.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/e1\/96\/33\/e196334bca4cbb72808a964b6eac5bdc.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/e1\/96\/33\/e196334bca4cbb72808a964b6eac5bdc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/e1\/96\/33\/e196334bca4cbb72808a964b6eac5bdc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<pre><code class=\"javascript\">import { randomUUID } from 'node:crypto';async function fetchToken() {  const res = await fetch('https:\/\/ngw.devices.sberbank.ru:9443\/api\/v2\/oauth', {    method: 'POST',    headers: {      Authorization: `Basic ${process.env.GIGACHAT_AUTH_KEY}`,      RqUID: randomUUID(),      'Content-Type': 'application\/x-www-form-urlencoded',      Accept: 'application\/json',    },    body: 'scope=GIGACHAT_API_PERS',    dispatcher: gigachatAgent, \/\/ \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435  });  if (!res.ok) throw new Error(`oauth ${res.status}: ${await res.text()}`);  return (await res.json()).access_token;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper\"><\/span><\/a><\/div><\/pre>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e <code>expires_at<\/code> \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u043b\u0438 \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 API \u043e\u0442\u0432\u0435\u0442\u0438\u0442 401. \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u043e\u043d \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438 \u0447\u0430\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0443\u0442. \u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0434\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u0443 \u043e\u0431\u0451\u0440\u0442\u043a\u0443:<\/p>\n<pre><code class=\"javascript\">const BASE = 'https:\/\/gigachat.devices.sberbank.ru\/api\/v1';let token = null;async function gigachat(path, init = {}, retry = true) {  token ??= await fetchToken();  const res = await fetch(BASE + path, {    ...init,    headers: { ...init.headers, Authorization: `Bearer ${token}` },    dispatcher: gigachatAgent,  });  if (res.status === 401 &amp;&amp; retry) {    token = await fetchToken();    return gigachat(path, init, false);  }  return res;}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/p>\n<h3>2. \u0421\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b<\/h3>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440\u044b GigaChat \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b, Russian Trusted Root CA. \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u043e\u0432\u0435\u0440\u0438\u044f \u0435\u0433\u043e \u043d\u0435\u0442, \u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0430\u0434\u0430\u0435\u0442:<\/p>\n<pre><code>CERTIFICATE_VERIFY_FAILED: self-signed certificate in certificate chain<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u042d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0438\u0445 \u0445\u043e\u0441\u0442\u043e\u0432: \u0438 OAuth, \u0438 API. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, &#8212; \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443, \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e GigaChat. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f Node \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442: Node \u0431\u0435\u0440\u0451\u0442 \u0441\u0432\u043e\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0445 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442. \u0410 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0447\u0438\u0442\u0430\u044e\u0442, \u043a\u043e\u0440\u0435\u043d\u044c \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0430\u0439\u0442\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/1d\/0b\/3a\/1d0b3a1fc2bd144f541b49ed1cb86161.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/1d\/0b\/3a\/1d0b3a1fc2bd144f541b49ed1cb86161.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/1d\/0b\/3a\/1d0b3a1fc2bd144f541b49ed1cb86161.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u042f \u0434\u0435\u0440\u0436\u0443 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0440\u044f\u0434\u043e\u043c \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f GigaChat. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442. \u0424\u0430\u0439\u043b \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u043d\u0430 \u0413\u043e\u0441\u0443\u0441\u043b\u0443\u0433\u0430\u0445, \u0430 \u043d\u0435 \u043f\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438: \u044d\u0442\u043e \u044f\u043a\u043e\u0440\u044c \u0434\u043e\u0432\u0435\u0440\u0438\u044f, \u0435\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0436\u043d\u043e.<\/p>\n<pre><code class=\"javascript\">import { readFileSync } from 'node:fs';import { Agent } from 'undici';\/\/ \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a GigaChat: \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u0430\u043c \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442,\/\/ \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0431\u0435\u0440\u0451\u043c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0440\u044f\u0434\u043e\u043c \u0441 \u043a\u043e\u0434\u043e\u043c.const gigachatAgent = new Agent({  connect: { ca: readFileSync(new URL('.\/russian_trusted_root_ca.pem', import.meta.url)) },});<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/p>\n<h3>3. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435 \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/h3>\n<p>\u0423 OpenAI-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 API \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0438\u0434\u0451\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f: <code>image_url<\/code> \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0438\u043b\u0438 <code>data:<\/code>. \u0423 GigaChat \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f. \u0424\u0430\u0439\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043e\u0442\u0432\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0435\u0433\u043e id, \u0438 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e id \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 <code>attachments<\/code>.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/26\/0b\/63\/260b63ec28070a46c0cf695d420d4188.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/26\/0b\/63\/260b63ec28070a46c0cf695d420d4188.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/26\/0b\/63\/260b63ec28070a46c0cf695d420d4188.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u043e\u0434\u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0434\u043e 10 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441, \u0434\u043e 15 \u041c\u0411 \u043d\u0430 \u0444\u0430\u0439\u043b. \u0424\u043e\u0440\u043c\u0430\u0442\u044b \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u044b JPEG, PNG, TIFF \u0438 BMP. WebP \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c <code>File format is not supported<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435 JPEG \u0438 \u043d\u0435 PNG, \u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0422\u0438\u043f \u0444\u0430\u0439\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u043f\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0431\u0430\u0439\u0442\u0430\u043c, \u0430 \u043d\u0435 \u043f\u043e \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043e: Telegram, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0434\u0430\u0451\u0442 \u0444\u0430\u0439\u043b\u044b \u043a\u0430\u043a <code>application\/octet-stream<\/code>.<\/p>\n<p>\u0424\u0430\u0439\u043b \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430, \u043f\u043e\u043a\u0430 \u0435\u0433\u043e \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0431\u0438\u0440\u0430\u0442\u044c, \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043e\u0441\u0435\u0434\u0430\u0435\u0442 \u0442\u0430\u043c \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430:<\/p>\n<pre><code class=\"javascript\">async function askAboutImage(buf, mime, question) {  const form = new FormData();  form.append('file', new Blob([buf], { type: mime }), mime === 'image\/png' ? 'image.png' : 'image.jpg');  form.append('purpose', 'general');  const { id } = await (await gigachat('\/files', { method: 'POST', body: form })).json();  try {    const res = await gigachat('\/chat\/completions', {      method: 'POST',      headers: { 'Content-Type': 'application\/json' },      body: JSON.stringify({        model: 'GigaChat-2-Max',        messages: [{ role: 'user', content: question, attachments: [id] }],      }),    });    return (await res.json()).choices[0].message.content;  } finally {    \/\/ \u041e\u0448\u0438\u0431\u043a\u0443 \u0443\u0431\u043e\u0440\u043a\u0438 \u0433\u043b\u043e\u0442\u0430\u0435\u043c: \u043e\u0442\u0432\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u0430\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0444\u0430\u0439\u043b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435    await gigachat(`\/files\/${id}\/delete`, { method: 'POST' }).catch(() =&gt; {});  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/p>\n<h3>4. \u041e\u0442\u0432\u0435\u0442 \u043f\u043e JSON-\u0441\u0445\u0435\u043c\u0435<\/h3>\n<p>\u0421\u0445\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0442\u0430 GigaChat \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442, \u043d\u043e \u0436\u0434\u0451\u0442 \u0435\u0451 \u043d\u0435 \u0442\u0430\u043c, \u0433\u0434\u0435 OpenAI. \u0423 OpenAI \u0441\u0445\u0435\u043c\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 <code>response_format.json_schema.schema<\/code>, \u0443 GigaChat \u043b\u0435\u0436\u0438\u0442 \u043f\u0440\u044f\u043c\u043e \u0432 <code>response_format.schema<\/code>. \u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 OpenAI GigaChat \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442:<\/p>\n<pre><code>Empty schema with json format type is not supported<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/48\/74\/c6\/4874c61031cf7650234c81ca3c1819f0.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/48\/74\/c6\/4874c61031cf7650234c81ca3c1819f0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/48\/74\/c6\/4874c61031cf7650234c81ca3c1819f0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0434 OpenAI, \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430:<\/p>\n<pre><code class=\"javascript\">function toGigaChatResponseFormat(rf) {  if (rf?.type !== 'json_schema') return rf;  const { schema, strict } = rf.json_schema;  return { type: 'json_schema', schema, strict };}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 <code>required<\/code> \u0438 <code>strict<\/code> \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 JSON, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0441\u0445\u0435\u043c\u043e\u0439 \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u0412 <code>\/v2\/chat\/completions<\/code> \u043f\u043e\u043b\u0435 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u043e \u0432 <code>model_options.response_format<\/code>.<\/p>\n<\/p>\n<h3>5. functions \u0432\u043c\u0435\u0441\u0442\u043e tools<\/h3>\n<p>\u0412 <code>\/v1<\/code> \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443. \u0412\u043c\u0435\u0441\u0442\u043e <code>tools<\/code> \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 <code>functions<\/code>, \u0432\u043c\u0435\u0441\u0442\u043e <code>tool_calls<\/code> \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 <code>function_call<\/code>, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0440\u043e\u043b\u044c\u044e <code>function<\/code>, \u0430 \u043d\u0435 <code>tool<\/code>. \u0423 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u043b\u044f: <code>few_shot_examples<\/code> \u0438 <code>return_parameters<\/code>.<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/0a\/8e\/98\/0a8e9858c53160b706b84b07ae33e92c.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/0a\/8e\/98\/0a8e9858c53160b706b84b07ae33e92c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/0a\/8e\/98\/0a8e9858c53160b706b84b07ae33e92c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0421\u0430\u043c\u0430\u044f \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 &#8212; <code>arguments<\/code>. \u0423 OpenAI \u044d\u0442\u043e JSON-\u0441\u0442\u0440\u043e\u043a\u0430, \u0443 GigaChat \u043e\u0431\u044a\u0435\u043a\u0442. \u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 <code>JSON.parse(arguments)<\/code>, \u043d\u0430 GigaChat \u043f\u0430\u0434\u0430\u0435\u0442. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0449\u0438\u0442\u0430:<\/p>\n<pre><code class=\"javascript\">const args = typeof call.arguments === 'string' ? JSON.parse(call.arguments) : call.arguments;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<p>\u0426\u0438\u043a\u043b \u0430\u0433\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 OpenAI, \u0431\u0435\u0437 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043d\u0430 GigaChat \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0430\u0433\u0435\u043d\u0442\u0430\u0445 \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u044f \u0435\u0433\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u0430 \u0432 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 (\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439, \u043e\u0442\u0432\u0435\u0442 \u043f\u043e \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439) \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<\/p>\n<h3>6. \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0447\u0435\u0440\u0435\u0437 \u0447\u0430\u0442<\/h3>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0435\u0442. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0440\u0438\u0441\u0443\u0435\u0442 \u0447\u0430\u0442: \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 <code>\"function_call\": \"auto\"<\/code> \u0438 \u043f\u0440\u043e\u0441\u044c\u0431\u043e\u0439 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c. \u0412 \u043e\u0442\u0432\u0435\u0442\u0435 \u043d\u0435 \u0444\u0430\u0439\u043b, \u0430 \u0442\u0435\u0433 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435:<\/p>\n<pre><code>&lt;img src=\"27055233-d11d-4bab-af8e-8ce1b6b33bb0\" fuse=\"true\"\/&gt;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/20\/b7\/b5\/20b7b5f87893735bc52a17f56c8bcacd.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/20\/b7\/b5\/20b7b5f87893735bc52a17f56c8bcacd.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/20\/b7\/b5\/20b7b5f87893735bc52a17f56c8bcacd.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>id \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0438\u0434\u0438\u0442 HTML-\u0442\u0435\u0433 \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438:<\/p>\n<pre><code class=\"javascript\">const id = content.match(\/&lt;img[^&gt;]*src=\"([^\"]+)\"\/)?.[1];const image = await (await gigachat(`\/files\/${id}\/content`, { headers: { Accept: 'application\/jpg' } })).arrayBuffer();<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><span class=\"sc-logo-wrapper icon-only\"><\/span><\/a><\/div><\/pre>\n<\/p>\n<h3>\u0427\u0435\u043a-\u043b\u0438\u0441\u0442<\/h3>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/extt\/97\/4d\/23\/974d2354c2ac6218f657051df4dc2622.png\" width=\"1600\" height=\"900\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/extt\/97\/4d\/23\/974d2354c2ac6218f657051df4dc2622.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/extt\/97\/4d\/23\/974d2354c2ac6218f657051df4dc2622.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0447\u0430\u0441. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u00ab\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0437\u0430 \u0434\u0435\u043d\u044c\u00bb \u0432 \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043d\u0435\u0434\u0435\u043b\u044e, \u0435\u0441\u043b\u0438 \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043e \u043d\u0438\u0445 \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432 \u043b\u043e\u0433\u0430\u0445. \u042d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0431\u0440\u0430\u043d, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0438\u0445 \u0437\u0430\u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>\u041a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 GigaChat API \u0432\u044b \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438? \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0434\u043e\u043f\u043e\u043b\u043d\u044e.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1112158\/\">https:\/\/habr.com\/ru\/articles\/1112158\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u042f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u043b GigaChat \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u043d\u0430 Node.js, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 OpenAI-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c\u0438. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0445\u0432\u0430\u0442\u0438\u0442 \u0441\u043c\u0435\u043d\u0438\u0442\u044c base URL \u0438 \u043a\u043b\u044e\u0447. \u041d\u0430 \u0434\u0435\u043b\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 \u043d\u0430\u0431\u0440\u0430\u043b\u043e\u0441\u044c \u0448\u0435\u0441\u0442\u044c, \u0438 \u043a\u0430\u0436\u0434\u043e\u0435 \u043b\u043e\u043c\u0430\u0435\u0442 \u043a\u043e\u0434, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 OpenAI. \u041d\u0438\u0436\u0435 \u043e\u043d\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443: \u0447\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438\u043b\u0435\u0442\u0430\u0435\u0442 \u0438 \u043a\u0430\u043a \u044f \u044d\u0442\u043e \u043e\u0431\u043e\u0448\u0451\u043b. \u0421 \u043a\u043e\u0434\u043e\u043c.1. \u0422\u043e\u043a\u0435\u043d \u0436\u0438\u0432\u0451\u0442 30 \u043c\u0438\u043d\u0443\u0442\u0412 \u043b\u0438\u0447\u043d\u043e\u043c \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0435 GigaChat API \u0432\u044b\u0434\u0430\u0451\u0442\u0441\u044f \u00ab\u043a\u043b\u044e\u0447 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438\u00bb: \u0432 \u043d\u0451\u043c \u0443\u0436\u0435 \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u044b Client ID \u0438 \u0441\u0435\u043a\u0440\u0435\u0442. \u0412 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u043d \u043d\u0435 \u0445\u043e\u0434\u0438\u0442. \u0415\u0433\u043e \u043c\u0435\u043d\u044f\u044e\u0442 \u043d\u0430 \u0442\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0445\u043e\u0441\u0442, \u0438 \u0442\u043e\u043a\u0435\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 30 \u043c\u0438\u043d\u0443\u0442.\u0414\u0432\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0432\u0440\u0435\u043c\u044f. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a RqUID \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u043e\u0432\u044b\u043c uuid4 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u043c\u0435\u043d, \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 400. \u0410 scope \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0442\u044c \u0441 \u0442\u0430\u0440\u0438\u0444\u043e\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0432\u0435\u0434\u0451\u043d \u043f\u0440\u043e\u0435\u043a\u0442: GIGACHAT_API_PERS, GIGACHAT_API_B2B \u0438\u043b\u0438 GIGACHAT_API_CORP.import { randomUUID } from &#8216;node:crypto&#8217;;async function fetchToken() {  const res = await fetch(&#8216;https:\/\/ngw.devices.sberbank.ru:9443\/api\/v2\/oauth&#8217;, {    method: &#8216;POST&#8217;,    headers: {      Authorization: `Basic ${process.env.GIGACHAT_AUTH_KEY}`,      RqUID: randomUUID(),      &#8216;Content-Type&#8217;: &#8216;application\/x-www-form-urlencoded&#8217;,      Accept: &#8216;application\/json&#8217;,    },    body: &#8216;scope=GIGACHAT_API_PERS&#8217;,    dispatcher: gigachatAgent, \/\/ \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435  });  if (!res.ok) throw new Error(`oauth ${res.status}: ${await res.text()}`);  return (await res.json()).access_token;}\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e expires_at \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u0430 \u0438\u043b\u0438 \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u043a\u043e\u0433\u0434\u0430 API \u043e\u0442\u0432\u0435\u0442\u0438\u0442 401. \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u043e\u043d \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438 \u0447\u0430\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0443\u0442. \u0412\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0434\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 \u043e\u0434\u043d\u0443 \u043e\u0431\u0451\u0440\u0442\u043a\u0443:const BASE = &#8216;https:\/\/gigachat.devices.sberbank.ru\/api\/v1&#8217;;let token = null;async function gigachat(path, init = {}, retry = true) {  token ??= await fetchToken();  const res = await fetch(BASE + path, {    &#8230;init,    headers: { &#8230;init.headers, Authorization: `Bearer ${token}` },    dispatcher: gigachatAgent,  });  if (res.status === 401 &amp;&amp; retry) {    token = await fetchToken();    return gigachat(path, init, false);  }  return res;}2. \u0421\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b\u0421\u0435\u0440\u0432\u0435\u0440\u044b GigaChat \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u044b \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b, Russian Trusted Root CA. \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0441\u043f\u0438\u0441\u043a\u0430\u0445 \u0434\u043e\u0432\u0435\u0440\u0438\u044f \u0435\u0433\u043e \u043d\u0435\u0442, \u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0430\u0434\u0430\u0435\u0442:CERTIFICATE_VERIFY_FAILED: self-signed certificate in certificate chain\u042d\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u043e\u0438\u0445 \u0445\u043e\u0441\u0442\u043e\u0432: \u0438 OAuth, \u0438 API. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, &#8212; \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443, \u043d\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043d\u0446\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e GigaChat. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f Node \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442: Node \u0431\u0435\u0440\u0451\u0442 \u0441\u0432\u043e\u0439 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u0445 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u0442. \u0410 \u0442\u0430\u043c, \u0433\u0434\u0435 \u0447\u0438\u0442\u0430\u044e\u0442, \u043a\u043e\u0440\u0435\u043d\u044c \u041c\u0438\u043d\u0446\u0438\u0444\u0440\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0441\u0430\u0439\u0442\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435.\u042f \u0434\u0435\u0440\u0436\u0443 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u0440\u044f\u0434\u043e\u043c \u0441 \u043a\u043e\u0434\u043e\u043c \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f GigaChat. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e \u043d\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044e\u0442. \u0424\u0430\u0439\u043b \u0431\u0435\u0440\u0451\u0442\u0441\u044f \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432 \u043d\u0430 \u0413\u043e\u0441\u0443\u0441\u043b\u0443\u0433\u0430\u0445, \u0430 \u043d\u0435 \u043f\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438: \u044d\u0442\u043e \u044f\u043a\u043e\u0440\u044c \u0434\u043e\u0432\u0435\u0440\u0438\u044f, \u0435\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0436\u043d\u043e.import { readFileSync } from &#8216;node:fs&#8217;;import { Agent } from &#8216;undici&#8217;;\/\/ \u0422\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a GigaChat: \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u0430\u043c \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442,\/\/ \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0431\u0435\u0440\u0451\u043c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0440\u044f\u0434\u043e\u043c \u0441 \u043a\u043e\u0434\u043e\u043c.const gigachatAgent = new Agent({  connect: { ca: readFileSync(new URL(&#8216;.\/russian_trusted_root_ca.pem&#8217;, import.meta.url)) },});3. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0435 \u0432\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u0423 OpenAI-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 API \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0438\u0434\u0451\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f: image_url \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0438\u043b\u0438 data:. \u0423 GigaChat \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f. \u0424\u0430\u0439\u043b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043e\u0442\u0432\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0435\u0433\u043e id, \u0438 \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e id \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 attachments.\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: \u043e\u0434\u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0434\u043e 10 \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441, \u0434\u043e 15 \u041c\u0411 \u043d\u0430 \u0444\u0430\u0439\u043b. \u0424\u043e\u0440\u043c\u0430\u0442\u044b \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u044b JPEG, PNG, TIFF \u0438 BMP. WebP \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0435\u0442 \u0441 \u043e\u0442\u0432\u0435\u0442\u043e\u043c File format is not supported, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435 JPEG \u0438 \u043d\u0435 PNG, \u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e \u0434\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u0422\u0438\u043f \u0444\u0430\u0439\u043b\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u043f\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u0431\u0430\u0439\u0442\u0430\u043c, \u0430 \u043d\u0435 \u043f\u043e \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043e: Telegram, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0434\u0430\u0451\u0442 \u0444\u0430\u0439\u043b\u044b \u043a\u0430\u043a application\/octet-stream.\u0424\u0430\u0439\u043b \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430, \u043f\u043e\u043a\u0430 \u0435\u0433\u043e \u043d\u0435 \u0443\u0434\u0430\u043b\u044f\u0442. \u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0431\u0438\u0440\u0430\u0442\u044c, \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043e\u0441\u0435\u0434\u0430\u0435\u0442 \u0442\u0430\u043c \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430:async function askAboutImage(buf, mime, question) {  const form = new FormData();  form.append(&#8216;file&#8217;, new Blob([buf], { type: mime }), mime === &#8216;image\/png&#8217; ? &#8216;image.png&#8217; : &#8216;image.jpg&#8217;);  form.append(&#8216;purpose&#8217;, &#8216;general&#8217;);  const { id } = await (await gigachat(&#8216;\/files&#8217;, { method: &#8216;POST&#8217;, body: form })).json();  try {    const res = await gigachat(&#8216;\/chat\/completions&#8217;, {      method: &#8216;POST&#8217;,      headers: { &#8216;Content-Type&#8217;: &#8216;application\/json&#8217; },      body: JSON.stringify({        model: &#8216;GigaChat-2-Max&#8217;,        messages: [{ role: &#8216;user&#8217;, content: question, attachments: [id] }],      }),    });    return (await res.json()).choices[0].message.content;  } finally {    \/\/ \u041e\u0448\u0438\u0431\u043a\u0443 \u0443\u0431\u043e\u0440\u043a\u0438 \u0433\u043b\u043e\u0442\u0430\u0435\u043c: \u043e\u0442\u0432\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u0430\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u0444\u0430\u0439\u043b \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435    await gigachat(`\/files\/${id}\/delete`, { method: &#8216;POST&#8217; }).catch(() =&gt; {});  }}4. \u041e\u0442\u0432\u0435\u0442 \u043f\u043e JSON-\u0441\u0445\u0435\u043c\u0435\u0421\u0445\u0435\u043c\u0443 \u043e\u0442\u0432\u0435\u0442\u0430 GigaChat \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442, \u043d\u043e \u0436\u0434\u0451\u0442 \u0435\u0451 \u043d\u0435 \u0442\u0430\u043c, \u0433\u0434\u0435 OpenAI. \u0423 OpenAI \u0441\u0445\u0435\u043c\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 response_format.json_schema.schema, \u0443 GigaChat \u043b\u0435\u0436\u0438\u0442 \u043f\u0440\u044f\u043c\u043e \u0432 response_format.schema. \u0417\u0430\u043f\u0440\u043e\u0441 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 OpenAI GigaChat \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442:Empty schema with json format type is not supported\u0415\u0441\u043b\u0438 \u043a\u043e\u0434 \u0443\u0436\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0434 OpenAI, \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430:function toGigaChatResponseFormat(rf) {  if (rf?.type !== &#8216;json_schema&#8217;) return rf;  const { schema, strict } = rf.json_schema;  return { type: &#8216;json_schema&#8217;, schema, strict };}\u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 required \u0438 strict \u043c\u043e\u0434\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 JSON, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u044f \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e \u0441\u0445\u0435\u043c\u043e\u0439 \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435. \u0412 \/v2\/chat\/completions \u043f\u043e\u043b\u0435 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u043e \u0432 model_options.response_format.5. functions \u0432\u043c\u0435\u0441\u0442\u043e tools\u0412 \/v1 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443. \u0412\u043c\u0435\u0441\u0442\u043e tools \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 functions, \u0432\u043c\u0435\u0441\u0442\u043e tool_calls \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 function_call, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0441 \u0440\u043e\u043b\u044c\u044e function, \u0430 \u043d\u0435 tool. \u0423 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u043e\u043b\u044f: few_shot_examples \u0438 return_parameters.\u0421\u0430\u043c\u0430\u044f \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 &#8212; arguments. \u0423 OpenAI \u044d\u0442\u043e JSON-\u0441\u0442\u0440\u043e\u043a\u0430, \u0443 GigaChat \u043e\u0431\u044a\u0435\u043a\u0442. \u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 JSON.parse(arguments), \u043d\u0430 GigaChat \u043f\u0430\u0434\u0430\u0435\u0442. \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0449\u0438\u0442\u0430:const args = typeof call.arguments === &#8216;string&#8217; ? JSON.parse(call.arguments) : call.arguments;\u0426\u0438\u043a\u043b \u0430\u0433\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 OpenAI, \u0431\u0435\u0437 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u043d\u0430 GigaChat \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0430\u0433\u0435\u043d\u0442\u0430\u0445 \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u044f \u0435\u0433\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u0430 \u0432 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 (\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f, \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0435\u0439, \u043e\u0442\u0432\u0435\u0442 \u043f\u043e \u0431\u0430\u0437\u0435 \u0437\u043d\u0430\u043d\u0438\u0439) \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u0435\u0437 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432.6. \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u0447\u0435\u0440\u0435\u0437 \u0447\u0430\u0442\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a \u043d\u0435\u0442. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0440\u0438\u0441\u0443\u0435\u0442 \u0447\u0430\u0442: \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 &#171;function_call&#187;: &#171;auto&#187; \u0438 \u043f\u0440\u043e\u0441\u044c\u0431\u043e\u0439 \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c. \u0412 \u043e\u0442\u0432\u0435\u0442\u0435 \u043d\u0435 \u0444\u0430\u0439\u043b, \u0430 \u0442\u0435\u0433 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435:&lt;img src=&#187;27055233-d11d-4bab-af8e-8ce1b6b33bb0&#8243; fuse=&#187;true&#187;\/&gt;id \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0443\u0432\u0438\u0434\u0438\u0442 HTML-\u0442\u0435\u0433 \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438:const id = content.match(\/&lt;img[^&gt;]*src=&#187;([^&#187;]+)&#187;\/)?.[1];const image = await (await gigachat(`\/files\/${id}\/content`, { headers: { Accept: &#8216;application\/jpg&#8217; } })).arrayBuffer();\u0427\u0435\u043a-\u043b\u0438\u0441\u0442\u041f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430 \u0447\u0430\u0441. \u0412\u043c\u0435\u0441\u0442\u0435 \u043e\u043d\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u00ab\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0437\u0430 \u0434\u0435\u043d\u044c\u00bb \u0432 \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043d\u0435\u0434\u0435\u043b\u044e, \u0435\u0441\u043b\u0438 \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043e \u043d\u0438\u0445 \u043f\u043e \u043e\u0448\u0438\u0431\u043a\u0430\u043c \u0432 \u043b\u043e\u0433\u0430\u0445. \u042d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0431\u0440\u0430\u043d, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0438\u0445 \u0437\u0430\u0440\u0430\u043d\u0435\u0435.\u041a\u0430\u043a\u0438\u0435 \u0435\u0449\u0451 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 GigaChat API \u0432\u044b \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0438? \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0434\u043e\u043f\u043e\u043b\u043d\u044e.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1112158\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-504740","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504740"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/504740\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}