diff options
Diffstat (limited to 'packages/web/src/content/docs/ru/sdk.mdx')
| -rw-r--r-- | packages/web/src/content/docs/ru/sdk.mdx | 114 |
1 files changed, 93 insertions, 21 deletions
diff --git a/packages/web/src/content/docs/ru/sdk.mdx b/packages/web/src/content/docs/ru/sdk.mdx index 1269d9fc0..0afdea1b6 100644 --- a/packages/web/src/content/docs/ru/sdk.mdx +++ b/packages/web/src/content/docs/ru/sdk.mdx @@ -117,6 +117,78 @@ try { --- +## Структурированный вывод + +Вы можете запросить структурированный вывод JSON от модели, указав `format` со схемой JSON. Модель будет использовать инструмент `StructuredOutput` для возврата проверенного JSON, соответствующего вашей схеме. + +### Основное использование + +```typescript +const result = await client.session.prompt({ + path: { id: sessionId }, + body: { + parts: [{ type: "text", text: "Research Anthropic and provide company info" }], + format: { + type: "json_schema", + schema: { + type: "object", + properties: { + company: { type: "string", description: "Company name" }, + founded: { type: "number", description: "Year founded" }, + products: { + type: "array", + items: { type: "string" }, + description: "Main products", + }, + }, + required: ["company", "founded"], + }, + }, + }, +}) + +// Access the structured output +console.log(result.data.info.structured_output) +// { company: "Anthropic", founded: 2021, products: ["Claude", "Claude API"] } +``` + +### Типы форматов вывода + +| Тип | Описание | +| ------------- | ------------------------------------------------------------------------- | +| `text` | По умолчанию. Стандартный текстовый ответ (без структурированного вывода) | +| `json_schema` | Возвращает проверенный JSON, соответствующий предоставленной схеме | + +### Формат схемы JSON + +При использовании `type: 'json_schema'`, укажите: + +| Поле | Тип | Описание | +| ------------ | --------------- | ---------------------------------------------------------------------- | +| `type` | `'json_schema'` | Обязательно. Указывает режим схемы JSON | +| `schema` | `object` | Обязательно. Объект JSON Schema, определяющий структуру вывода | +| `retryCount` | `number` | Необязательно. Количество повторных попыток проверки (по умолчанию: 2) | + +### Обработка ошибок + +Если модель не может выдать действительный структурированный вывод после всех повторных попыток, ответ будет включать `StructuredOutputError`: + +```typescript +if (result.data.info.error?.name === "StructuredOutputError") { + console.error("Failed to produce structured output:", result.data.info.error.message) + console.error("Attempts:", result.data.info.error.retries) +} +``` + +### Лучшие практики + +1. **Предоставляйте четкие описания** в свойствах вашей схемы, чтобы помочь модели понять, какие данные извлекать +2. **Используйте `required`**, чтобы указать, какие поля должны присутствовать +3. **Делайте схемы сфокусированными** — сложные вложенные схемы могут быть труднее для правильного заполнения моделью +4. **Устанавливайте соответствующий `retryCount`** — увеличивайте для сложных схем, уменьшайте для простых + +--- + ## API SDK предоставляет все серверные API через типобезопасный клиент. @@ -226,27 +298,27 @@ const { providers, default: defaults } = await client.config.providers() ### Сессии -| Метод | Описание | Примечания | -| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> | -| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> | -| `session.create({ body })` | Create session | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.delete({ path })` | Delete session | Returns `boolean` | -| `session.update({ path, body })` | Update session properties | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` | -| `session.abort({ path })` | Abort a running session | Returns `boolean` | -| `session.share({ path })` | Share session | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.unshare({ path })` | Unshare session | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.summarize({ path, body })` | Summarize session | Returns `boolean` | -| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` | -| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` | -| `session.prompt({ path, body })` | Send prompt message | `body.noReply: true` returns UserMessage (context only). Default returns <a href={typesUrl}><code>AssistantMessage</code></a> with AI response | -| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` | -| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> | -| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> | -| `session.unrevert({ path })` | Restore reverted messages | Returns <a href={typesUrl}><code>Session</code></a> | -| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` | +| Метод | Описание | Примечания | +| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `session.list()` | List sessions | Returns <a href={typesUrl}><code>Session[]</code></a> | +| `session.get({ path })` | Get session | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.children({ path })` | List child sessions | Returns <a href={typesUrl}><code>Session[]</code></a> | +| `session.create({ body })` | Create session | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.delete({ path })` | Delete session | Returns `boolean` | +| `session.update({ path, body })` | Update session properties | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` | +| `session.abort({ path })` | Abort a running session | Returns `boolean` | +| `session.share({ path })` | Share session | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.unshare({ path })` | Unshare session | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.summarize({ path, body })` | Summarize session | Returns `boolean` | +| `session.messages({ path })` | List messages in a session | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}[]` | +| `session.message({ path })` | Get message details | Returns `{ info: `<a href={typesUrl}><code>Message</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` | +| `session.prompt({ path, body })` | Send prompt message | `body.noReply: true` возвращает UserMessage (только контекст). По умолчанию возвращает <a href={typesUrl}><code>AssistantMessage</code></a> с ответом ИИ. Поддерживает `body.outputFormat` для [структурированного вывода](#структурированный-вывод) | +| `session.command({ path, body })` | Send command to session | Returns `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>Part[]</code></a>`}` | +| `session.shell({ path, body })` | Run a shell command | Returns <a href={typesUrl}><code>AssistantMessage</code></a> | +| `session.revert({ path, body })` | Revert a message | Returns <a href={typesUrl}><code>Session</code></a> | +| `session.unrevert({ path })` | Restore reverted messages | Returns <a href={typesUrl}><code>Session</code></a> | +| `postSessionByIdPermissionsByPermissionId({ path, body })` | Respond to a permission request | Returns `boolean` | --- |
