From d6194df824d5b20208b51d6fc2f4f987776a9027 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Mon, 16 Dec 2024 01:27:15 -0500 Subject: [PATCH] Bulk Message Creation Endpoint (#82) * fix: increase db pool limit and optimize crud requests * fix: Sentry tracing and fly concurrency * feat: Add alembic and indexes * feat: Batch insert method * fix: Pydantic Validation * fix: Added Pydantic based API validation and Associated Test Cases * chore: Update Changelog * fix(docs): Update Docs with new API Method and OpenAPI Spec * chore(ci): Add Environment Variable for Anthropic --- .github/workflows/unittest.yml | 1 + CHANGELOG.md | 4 + .../create-batch-messages-for-session.mdx | 3 + docs/mint.json | 3 +- docs/openapi.json | 3434 ++++++++++++++ docs/openapi.yml | 4016 ----------------- docs/package.json | 2 +- src/crud.py | 34 + src/models.py | 2 +- src/routers/collections.py | 15 +- src/routers/documents.py | 2 - src/routers/messages.py | 144 +- src/routers/sessions.py | 2 - src/routers/users.py | 1 - src/schemas.py | 66 +- tests/routes/test_apps.py | 14 + tests/routes/test_messages.py | 98 + tests/routes/test_sessions.py | 2 +- tests/routes/test_validation_api.py | 516 +++ tests/test_schema_validations.py | 218 + 20 files changed, 4494 insertions(+), 4083 deletions(-) create mode 100644 docs/api-reference/endpoint/messages/create-batch-messages-for-session.mdx create mode 100644 docs/openapi.json delete mode 100644 docs/openapi.yml create mode 100644 tests/routes/test_validation_api.py create mode 100644 tests/test_schema_validations.py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 6c47961..4b7b757 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -51,6 +51,7 @@ jobs: SENTRY_ENABLED: false OPENTELEMETRY_ENABLED: false OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8986711..92a0695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Alembic for handling database migrations - Additional indexes for reading Messages and Metamessages +### Changed + +- API validation using Pydantic + ### Fixed - Dialectic Streaming Endpoint properly sends text in `StreamingResponse` diff --git a/docs/api-reference/endpoint/messages/create-batch-messages-for-session.mdx b/docs/api-reference/endpoint/messages/create-batch-messages-for-session.mdx new file mode 100644 index 0000000..b747040 --- /dev/null +++ b/docs/api-reference/endpoint/messages/create-batch-messages-for-session.mdx @@ -0,0 +1,3 @@ +--- +openapi: post /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/batch +--- \ No newline at end of file diff --git a/docs/mint.json b/docs/mint.json index b874e4e..14ecc0f 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -118,6 +118,7 @@ "pages": [ "api-reference/endpoint/messages/get-messages", "api-reference/endpoint/messages/create-message-for-session", + "api-reference/endpoint/messages/create-batch-messages-for-session", "api-reference/endpoint/messages/get-message", "api-reference/endpoint/messages/update-message" ] @@ -160,7 +161,7 @@ "github": "https://github.com/plastic-labs", "linkedin": "https://www.linkedin.com/company/plasticlabs" }, - "openapi": ["/openapi.yml"], + "openapi": ["/openapi.json"], "analytics": { "posthog": { "apiKey": "phc_1yrzzcgywqXGcerkkI4g7C0YfyPMcAKNOOvGcjTCiUk" diff --git a/docs/openapi.json b/docs/openapi.json new file mode 100644 index 0000000..c54295e --- /dev/null +++ b/docs/openapi.json @@ -0,0 +1,3434 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "Honcho API", + "summary": "An API for adding personalization to AI Apps", + "description": "This API is used to store data and get insights about users for AI\n applications", + "contact": { + "name": "Plastic Labs", + "url": "https://plasticlabs.ai/", + "email": "hello@plasticlabs.ai" + }, + "version": "0.0.15" + }, + "servers": [ + { + "url": "http://127.0.0.1:8000", + "description": "Local Development Server" + }, + { "url": "https:/demo.honcho.dev", "description": "Demo Server" } + ], + "paths": { + "/v1/apps/{app_id}": { + "get": { + "tags": ["apps"], + "summary": "Get App", + "description": "Get an App by ID", + "operationId": "get_app_v1_apps__app_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/App" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const app = await client.apps.get('app_id');\n\n console.log(app.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\napp = client.apps.get(\n \"app_id\",\n)\nprint(app.id)" + } + ] + }, + "put": { + "tags": ["apps"], + "summary": "Update App", + "description": "Update an App", + "operationId": "update_app_v1_apps__app_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AppUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/App" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const app = await client.apps.update('app_id');\n\n console.log(app.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\napp = client.apps.update(\n app_id=\"app_id\",\n)\nprint(app.id)" + } + ] + } + }, + "/v1/apps/name/{name}": { + "get": { + "tags": ["apps"], + "summary": "Get App By Name", + "description": "Get an App by Name", + "operationId": "get_app_by_name_v1_apps_name__name__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Name" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/App" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const app = await client.apps.getByName('name');\n\n console.log(app.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\napp = client.apps.get_by_name(\n \"name\",\n)\nprint(app.id)" + } + ] + } + }, + "/v1/apps": { + "post": { + "tags": ["apps"], + "summary": "Create App", + "description": "Create a new App", + "operationId": "create_app_v1_apps_post", + "requestBody": { + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AppCreate" } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/App" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "security": [{ "HTTPBearer": [] }, {}], + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const app = await client.apps.create({ name: 'x' });\n\n console.log(app.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\napp = client.apps.create(\n name=\"x\",\n)\nprint(app.id)" + } + ] + } + }, + "/v1/apps/get_or_create/{name}": { + "get": { + "tags": ["apps"], + "summary": "Get Or Create App", + "description": "Get or Create an App", + "operationId": "get_or_create_app_v1_apps_get_or_create__name__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Name" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/App" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const app = await client.apps.getOrCreate('name');\n\n console.log(app.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\napp = client.apps.get_or_create(\n \"name\",\n)\nprint(app.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users": { + "post": { + "tags": ["users"], + "summary": "Create User", + "description": "Create a new User", + "operationId": "create_user_v1_apps__app_id__users_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/UserCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const user = await client.apps.users.create('app_id', { name: 'x' });\n\n console.log(user.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nuser = client.apps.users.create(\n app_id=\"app_id\",\n name=\"x\",\n)\nprint(user.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/list": { + "post": { + "tags": ["users"], + "summary": "Get Users", + "description": "Get All Users for an App", + "operationId": "get_users_v1_apps__app_id__users_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "type": "boolean", + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/UserGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_User_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const user of client.apps.users.list('app_id')) {\n console.log(user.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.list(\n app_id=\"app_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/name/{name}": { + "get": { + "tags": ["users"], + "summary": "Get User By Name", + "description": "Get a User by name", + "operationId": "get_user_by_name_v1_apps__app_id__users_name__name__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "name", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Name" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const user = await client.apps.users.getByName('app_id', 'name');\n\n console.log(user.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nuser = client.apps.users.get_by_name(\n name=\"name\",\n app_id=\"app_id\",\n)\nprint(user.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}": { + "get": { + "tags": ["users"], + "summary": "Get User", + "description": "Get a User by ID", + "operationId": "get_user_v1_apps__app_id__users__user_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const user = await client.apps.users.get('app_id', 'user_id');\n\n console.log(user.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nuser = client.apps.users.get(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\nprint(user.id)" + } + ] + }, + "put": { + "tags": ["users"], + "summary": "Update User", + "description": "Update a User's name and/or metadata", + "operationId": "update_user_v1_apps__app_id__users__user_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/UserUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const user = await client.apps.users.update('app_id', 'user_id');\n\n console.log(user.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nuser = client.apps.users.update(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\nprint(user.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/get_or_create/{name}": { + "get": { + "tags": ["users"], + "summary": "Get Or Create User", + "description": "Get a User or create a new one by the input name", + "operationId": "get_or_create_user_v1_apps__app_id__users_get_or_create__name__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "name", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Name" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/User" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const user = await client.apps.users.getOrCreate('app_id', 'name');\n\n console.log(user.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nuser = client.apps.users.get_or_create(\n name=\"name\",\n app_id=\"app_id\",\n)\nprint(user.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/list": { + "post": { + "tags": ["sessions"], + "summary": "Get Sessions", + "description": "Get All Sessions for a User", + "operationId": "get_sessions_v1_apps__app_id__users__user_id__sessions_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/SessionGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Session_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const session of client.apps.users.sessions.list('app_id', 'user_id')) {\n console.log(session.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.sessions.list(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions": { + "post": { + "tags": ["sessions"], + "summary": "Create Session", + "description": "Create a Session for a User", + "operationId": "create_session_v1_apps__app_id__users__user_id__sessions_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/SessionCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Session" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const session = await client.apps.users.sessions.create('app_id', 'user_id');\n\n console.log(session.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nsession = client.apps.users.sessions.create(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\nprint(session.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}": { + "put": { + "tags": ["sessions"], + "summary": "Update Session", + "description": "Update the metadata of a Session", + "operationId": "update_session_v1_apps__app_id__users__user_id__sessions__session_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/SessionUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Session" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const session = await client.apps.users.sessions.update('app_id', 'user_id', 'session_id', {\n metadata: { foo: 'bar' },\n });\n\n console.log(session.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nsession = client.apps.users.sessions.update(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n metadata={\n \"foo\": \"bar\"\n },\n)\nprint(session.id)" + } + ] + }, + "delete": { + "tags": ["sessions"], + "summary": "Delete Session", + "description": "Delete a session by marking it as inactive", + "operationId": "delete_session_v1_apps__app_id__users__user_id__sessions__session_id__delete", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { "application/json": { "schema": {} } } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const session = await client.apps.users.sessions.delete('app_id', 'user_id', 'session_id');\n\n console.log(session);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nsession = client.apps.users.sessions.delete(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(session)" + } + ] + }, + "get": { + "tags": ["sessions"], + "summary": "Get Session", + "description": "Get a specific session for a user by ID", + "operationId": "get_session_v1_apps__app_id__users__user_id__sessions__session_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Session" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const session = await client.apps.users.sessions.get('app_id', 'user_id', 'session_id');\n\n console.log(session.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nsession = client.apps.users.sessions.get(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(session.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat": { + "post": { + "tags": ["sessions"], + "summary": "Chat", + "description": "Chat with the Dialectic API", + "operationId": "chat_v1_apps__app_id__users__user_id__sessions__session_id__chat_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AgentQuery" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AgentChat" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const agentChat = await client.apps.users.sessions.chat('app_id', 'user_id', 'session_id', {\n queries: 'string',\n });\n\n console.log(agentChat.content);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nagent_chat = client.apps.users.sessions.chat(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n queries=\"string\",\n)\nprint(agent_chat.content)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat/stream": { + "post": { + "tags": ["sessions"], + "summary": "Get Chat Stream", + "description": "Stream Results from the Dialectic API", + "operationId": "get_chat_stream_v1_apps__app_id__users__user_id__sessions__session_id__chat_stream_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/AgentQuery" } + } + } + }, + "responses": { + "200": { + "description": "Chat stream", + "content": { + "application/json": { "schema": {} }, + "text/event-stream": { + "schema": { "type": "string", "format": "binary" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const response = await client.apps.users.sessions.stream('app_id', 'user_id', 'session_id', {\n queries: 'string',\n });\n\n console.log(response);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nresponse = client.apps.users.sessions.stream(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n queries=\"string\",\n)\nprint(response)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/clone": { + "get": { + "tags": ["sessions"], + "summary": "Clone Session", + "description": "Clone a session for a user, optionally will deep clone metamessages as well", + "operationId": "clone_session_v1_apps__app_id__users__user_id__sessions__session_id__clone_get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "message_id", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Message Id" + } + }, + { + "name": "deep_copy", + "in": "query", + "required": false, + "schema": { + "type": "boolean", + "default": false, + "title": "Deep Copy" + } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Session" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const session = await client.apps.users.sessions.clone('app_id', 'user_id', 'session_id');\n\n console.log(session.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nsession = client.apps.users.sessions.clone(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(session.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages": { + "post": { + "tags": ["messages"], + "summary": "Create Message For Session", + "description": "Adds a message to a session", + "operationId": "create_message_for_session_v1_apps__app_id__users__user_id__sessions__session_id__messages_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MessageCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Message" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const message = await client.apps.users.sessions.messages.create('app_id', 'user_id', 'session_id', {\n content: 'content',\n is_user: true,\n });\n\n console.log(message.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmessage = client.apps.users.sessions.messages.create(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n content=\"content\",\n is_user=True,\n)\nprint(message.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/batch": { + "post": { + "tags": ["messages"], + "summary": "Create Batch Messages For Session", + "description": "Bulk create messages for a session while maintaining order. Maximum 100 messages per batch.", + "operationId": "create_batch_messages_for_session_v1_apps__app_id__users__user_id__sessions__session_id__messages_batch_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MessageBatchCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Message" }, + "title": "Response Create Batch Messages For Session V1 Apps App Id Users User Id Sessions Session Id Messages Batch Post" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const messages = await client.apps.users.sessions.messages.batch('app_id', 'user_id', 'session_id', {\n messages: [{ content: 'content', is_user: true }],\n });\n\n console.log(messages);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmessages = client.apps.users.sessions.messages.batch(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n messages=[{\n \"content\": \"content\",\n \"is_user\": True,\n }],\n)\nprint(messages)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/list": { + "post": { + "tags": ["messages"], + "summary": "Get Messages", + "description": "Get all messages for a session", + "operationId": "get_messages_v1_apps__app_id__users__user_id__sessions__session_id__messages_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MessageGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Message_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const message of client.apps.users.sessions.messages.list('app_id', 'user_id', 'session_id')) {\n console.log(message.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.sessions.messages.list(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/{message_id}": { + "get": { + "tags": ["messages"], + "summary": "Get Message", + "description": "Get a Message by ID", + "operationId": "get_message_v1_apps__app_id__users__user_id__sessions__session_id__messages__message_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "message_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Message Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Message" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const message = await client.apps.users.sessions.messages.get(\n 'app_id',\n 'user_id',\n 'session_id',\n 'message_id',\n );\n\n console.log(message.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmessage = client.apps.users.sessions.messages.get(\n message_id=\"message_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n session_id=\"session_id\",\n)\nprint(message.id)" + } + ] + }, + "put": { + "tags": ["messages"], + "summary": "Update Message", + "description": "Update the metadata of a Message", + "operationId": "update_message_v1_apps__app_id__users__user_id__sessions__session_id__messages__message_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "message_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Message Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MessageUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Message" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const message = await client.apps.users.sessions.messages.update(\n 'app_id',\n 'user_id',\n 'session_id',\n 'message_id',\n { metadata: { foo: 'bar' } },\n );\n\n console.log(message.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmessage = client.apps.users.sessions.messages.update(\n message_id=\"message_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n session_id=\"session_id\",\n metadata={\n \"foo\": \"bar\"\n },\n)\nprint(message.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages": { + "post": { + "tags": ["metamessages"], + "summary": "Create Metamessage", + "description": "Adds a message to a session", + "operationId": "create_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MetamessageCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Metamessage" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const metamessage = await client.apps.users.sessions.metamessages.create(\n 'app_id',\n 'user_id',\n 'session_id',\n { content: 'content', message_id: 'message_id', metamessage_type: 'x' },\n );\n\n console.log(metamessage.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmetamessage = client.apps.users.sessions.metamessages.create(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n content=\"content\",\n message_id=\"message_id\",\n metamessage_type=\"x\",\n)\nprint(metamessage.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages/list": { + "post": { + "tags": ["metamessages"], + "summary": "Get Metamessages", + "description": "Get all messages for a session", + "operationId": "get_metamessages_v1_apps__app_id__users__user_id__sessions__session_id__metamessages_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MetamessageGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Metamessage_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const metamessage of client.apps.users.sessions.metamessages.list(\n 'app_id',\n 'user_id',\n 'session_id',\n )) {\n console.log(metamessage.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.sessions.metamessages.list(\n session_id=\"session_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages/{metamessage_id}": { + "get": { + "tags": ["metamessages"], + "summary": "Get Metamessage", + "description": "Get a specific Metamessage by ID", + "operationId": "get_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages__metamessage_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "metamessage_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Metamessage Id" } + }, + { + "name": "message_id", + "in": "query", + "required": true, + "schema": { "type": "string", "title": "Message Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Metamessage" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const metamessage = await client.apps.users.sessions.metamessages.get(\n 'app_id',\n 'user_id',\n 'session_id',\n 'metamessage_id',\n { message_id: 'message_id' },\n );\n\n console.log(metamessage.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmetamessage = client.apps.users.sessions.metamessages.get(\n metamessage_id=\"metamessage_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n session_id=\"session_id\",\n message_id=\"message_id\",\n)\nprint(metamessage.id)" + } + ] + }, + "put": { + "tags": ["metamessages"], + "summary": "Update Metamessage", + "description": "Update's the metadata of a metamessage", + "operationId": "update_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages__metamessage_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "session_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Session Id" } + }, + { + "name": "metamessage_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Metamessage Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/MetamessageUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Metamessage" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const metamessage = await client.apps.users.sessions.metamessages.update(\n 'app_id',\n 'user_id',\n 'session_id',\n 'metamessage_id',\n { message_id: 'message_id' },\n );\n\n console.log(metamessage.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\nmetamessage = client.apps.users.sessions.metamessages.update(\n metamessage_id=\"metamessage_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n session_id=\"session_id\",\n message_id=\"message_id\",\n)\nprint(metamessage.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/metamessages/list": { + "post": { + "tags": ["metamessages"], + "summary": "Get Metamessages By User", + "description": "Paginate through the user metamessages for a user", + "operationId": "get_metamessages_by_user_v1_apps__app_id__users__user_id__metamessages_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/MetamessageGetUserLevel" + } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Metamessage_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const metamessage of client.apps.users.metamessages.list('app_id', 'user_id')) {\n console.log(metamessage.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.metamessages.list(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/list": { + "post": { + "tags": ["collections"], + "summary": "Get Collections", + "description": "Get All Collections for a User", + "operationId": "get_collections_v1_apps__app_id__users__user_id__collections_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/CollectionGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Collection_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const collection of client.apps.users.collections.list('app_id', 'user_id')) {\n console.log(collection.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.collections.list(\n user_id=\"user_id\",\n app_id=\"app_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/name/{name}": { + "get": { + "tags": ["collections"], + "summary": "Get Collection By Name", + "description": "Get a Collection by Name", + "operationId": "get_collection_by_name_v1_apps__app_id__users__user_id__collections_name__name__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "name", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Name" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Collection" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const collection = await client.apps.users.collections.getByName('app_id', 'user_id', 'name');\n\n console.log(collection.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ncollection = client.apps.users.collections.get_by_name(\n name=\"name\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(collection.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/{collection_id}": { + "get": { + "tags": ["collections"], + "summary": "Get Collection By Id", + "description": "Get a Collection by ID", + "operationId": "get_collection_by_id_v1_apps__app_id__users__user_id__collections__collection_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Collection" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const collection = await client.apps.users.collections.get('app_id', 'user_id', 'collection_id');\n\n console.log(collection.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ncollection = client.apps.users.collections.get(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(collection.id)" + } + ] + }, + "put": { + "tags": ["collections"], + "summary": "Update Collection", + "description": "Update a Collection's name or metadata", + "operationId": "update_collection_v1_apps__app_id__users__user_id__collections__collection_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/CollectionUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Collection" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const collection = await client.apps.users.collections.update('app_id', 'user_id', 'collection_id');\n\n console.log(collection.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ncollection = client.apps.users.collections.update(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(collection.id)" + } + ] + }, + "delete": { + "tags": ["collections"], + "summary": "Delete Collection", + "description": "Delete a Collection and its documents", + "operationId": "delete_collection_v1_apps__app_id__users__user_id__collections__collection_id__delete", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { "application/json": { "schema": {} } } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const collection = await client.apps.users.collections.delete('app_id', 'user_id', 'collection_id');\n\n console.log(collection);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ncollection = client.apps.users.collections.delete(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\nprint(collection)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections": { + "post": { + "tags": ["collections"], + "summary": "Create Collection", + "description": "Create a new Collection", + "operationId": "create_collection_v1_apps__app_id__users__user_id__collections_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/CollectionCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Collection" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const collection = await client.apps.users.collections.create('app_id', 'user_id', { name: 'x' });\n\n console.log(collection.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ncollection = client.apps.users.collections.create(\n user_id=\"user_id\",\n app_id=\"app_id\",\n name=\"x\",\n)\nprint(collection.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/list": { + "post": { + "tags": ["documents"], + "summary": "Get Documents", + "description": "Get all of the Documents in a Collection", + "operationId": "get_documents_v1_apps__app_id__users__user_id__collections__collection_id__documents_list_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + }, + { + "name": "reverse", + "in": "query", + "required": false, + "schema": { + "anyOf": [{ "type": "boolean" }, { "type": "null" }], + "default": false, + "title": "Reverse" + } + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "minimum": 1, + "description": "Page number", + "default": 1, + "title": "Page" + }, + "description": "Page number" + }, + { + "name": "size", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "maximum": 100, + "minimum": 1, + "description": "Page size", + "default": 50, + "title": "Size" + }, + "description": "Page size" + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/DocumentGet" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Page_Document_" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n // Automatically fetches more pages as needed.\n for await (const document of client.apps.users.collections.documents.list(\n 'app_id',\n 'user_id',\n 'collection_id',\n )) {\n console.log(document.id);\n }\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\npage = client.apps.users.collections.documents.list(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n)\npage = page.items[0]\nprint(page.id)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/{document_id}": { + "get": { + "tags": ["documents"], + "summary": "Get Document", + "description": "Get a document by ID", + "operationId": "get_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__get", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + }, + { + "name": "document_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Document Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Document" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const document = await client.apps.users.collections.documents.get(\n 'app_id',\n 'user_id',\n 'collection_id',\n 'document_id',\n );\n\n console.log(document.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ndocument = client.apps.users.collections.documents.get(\n document_id=\"document_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n collection_id=\"collection_id\",\n)\nprint(document.id)" + } + ] + }, + "put": { + "tags": ["documents"], + "summary": "Update Document", + "description": "Update the content and/or the metadata of a Document", + "operationId": "update_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__put", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + }, + { + "name": "document_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Document Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/DocumentUpdate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Document" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const document = await client.apps.users.collections.documents.update(\n 'app_id',\n 'user_id',\n 'collection_id',\n 'document_id',\n );\n\n console.log(document.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ndocument = client.apps.users.collections.documents.update(\n document_id=\"document_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n collection_id=\"collection_id\",\n)\nprint(document.id)" + } + ] + }, + "delete": { + "tags": ["documents"], + "summary": "Delete Document", + "description": "Delete a Document by ID", + "operationId": "delete_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__delete", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + }, + { + "name": "document_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Document Id" } + } + ], + "responses": { + "200": { + "description": "Successful Response", + "content": { "application/json": { "schema": {} } } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const document = await client.apps.users.collections.documents.delete(\n 'app_id',\n 'user_id',\n 'collection_id',\n 'document_id',\n );\n\n console.log(document);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ndocument = client.apps.users.collections.documents.delete(\n document_id=\"document_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n collection_id=\"collection_id\",\n)\nprint(document)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/query": { + "post": { + "tags": ["documents"], + "summary": "Query Documents", + "description": "Cosine Similarity Search for Documents", + "operationId": "query_documents_v1_apps__app_id__users__user_id__collections__collection_id__documents_query_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/DocumentQuery" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { "$ref": "#/components/schemas/Document" }, + "title": "Response Query Documents V1 Apps App Id Users User Id Collections Collection Id Documents Query Post" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const documents = await client.apps.users.collections.documents.query(\n 'app_id',\n 'user_id',\n 'collection_id',\n { query: 'x' },\n );\n\n console.log(documents);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ndocuments = client.apps.users.collections.documents.query(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n query=\"x\",\n)\nprint(documents)" + } + ] + } + }, + "/v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents": { + "post": { + "tags": ["documents"], + "summary": "Create Document", + "description": "Embed text as a vector and create a Document", + "operationId": "create_document_v1_apps__app_id__users__user_id__collections__collection_id__documents_post", + "security": [{ "HTTPBearer": [] }, {}], + "parameters": [ + { + "name": "app_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "App Id" } + }, + { + "name": "user_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "User Id" } + }, + { + "name": "collection_id", + "in": "path", + "required": true, + "schema": { "type": "string", "title": "Collection Id" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/DocumentCreate" } + } + } + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/Document" } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/HTTPValidationError" } + } + } + } + }, + "x-codeSamples": [ + { + "lang": "JavaScript", + "source": "import Honcho from 'honcho-ai';\n\nconst client = new Honcho({\n apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted\n});\n\nasync function main() {\n const document = await client.apps.users.collections.documents.create(\n 'app_id',\n 'user_id',\n 'collection_id',\n { content: 'x' },\n );\n\n console.log(document.id);\n}\n\nmain();" + }, + { + "lang": "Python", + "source": "import os\nfrom honcho import Honcho\n\nclient = Honcho(\n api_key=os.environ.get(\"HONCHO_API_KEY\"), # This is the default and can be omitted\n)\ndocument = client.apps.users.collections.documents.create(\n collection_id=\"collection_id\",\n app_id=\"app_id\",\n user_id=\"user_id\",\n content=\"x\",\n)\nprint(document.id)" + } + ] + } + } + }, + "components": { + "schemas": { + "AgentChat": { + "properties": { "content": { "type": "string", "title": "Content" } }, + "type": "object", + "required": ["content"], + "title": "AgentChat" + }, + "AgentQuery": { + "properties": { + "queries": { + "anyOf": [ + { "type": "string" }, + { "items": { "type": "string" }, "type": "array" } + ], + "title": "Queries" + } + }, + "type": "object", + "required": ["queries"], + "title": "AgentQuery" + }, + "App": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "name": { "type": "string", "title": "Name" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + } + }, + "type": "object", + "required": ["id", "name", "metadata", "created_at"], + "title": "App", + "exclude": ["h_metadata", "public_id"] + }, + "AppCreate": { + "properties": { + "name": { + "type": "string", + "maxLength": 100, + "minLength": 1, + "title": "Name" + }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["name"], + "title": "AppCreate" + }, + "AppUpdate": { + "properties": { + "name": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Name" + }, + "metadata": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Metadata" + } + }, + "type": "object", + "title": "AppUpdate" + }, + "Collection": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "name": { "type": "string", "title": "Name" }, + "user_id": { "type": "string", "title": "User Id" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + } + }, + "type": "object", + "required": ["id", "name", "user_id", "metadata", "created_at"], + "title": "Collection", + "exclude": ["h_metadata", "public_id"] + }, + "CollectionCreate": { + "properties": { + "name": { + "type": "string", + "maxLength": 100, + "minLength": 1, + "title": "Name" + }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["name"], + "title": "CollectionCreate" + }, + "CollectionGet": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + } + }, + "type": "object", + "title": "CollectionGet" + }, + "CollectionUpdate": { + "properties": { + "name": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Name" + }, + "metadata": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Metadata" + } + }, + "type": "object", + "title": "CollectionUpdate" + }, + "Document": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "content": { "type": "string", "title": "Content" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + }, + "collection_id": { "type": "string", "title": "Collection Id" } + }, + "type": "object", + "required": [ + "id", + "content", + "metadata", + "created_at", + "collection_id" + ], + "title": "Document", + "exclude": ["h_metadata", "public_id"] + }, + "DocumentCreate": { + "properties": { + "content": { + "type": "string", + "maxLength": 100000, + "minLength": 1, + "title": "Content" + }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["content"], + "title": "DocumentCreate" + }, + "DocumentGet": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + } + }, + "type": "object", + "title": "DocumentGet" + }, + "DocumentQuery": { + "properties": { + "query": { + "type": "string", + "maxLength": 1000, + "minLength": 1, + "title": "Query" + }, + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + }, + "top_k": { + "type": "integer", + "maximum": 50, + "minimum": 1, + "title": "Top K", + "default": 5 + } + }, + "type": "object", + "required": ["query"], + "title": "DocumentQuery" + }, + "DocumentUpdate": { + "properties": { + "metadata": { + "anyOf": [ + { + "type": "object", + "maxProperties": 10000, + "additionalProperties": true + }, + { "type": "null" } + ], + "title": "Metadata" + }, + "content": { + "anyOf": [ + { "type": "string", "maxLength": 100000, "minLength": 1 }, + { "type": "null" } + ], + "title": "Content" + } + }, + "type": "object", + "title": "DocumentUpdate" + }, + "HTTPValidationError": { + "properties": { + "detail": { + "items": { "$ref": "#/components/schemas/ValidationError" }, + "type": "array", + "title": "Detail" + } + }, + "type": "object", + "title": "HTTPValidationError" + }, + "Message": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "content": { "type": "string", "title": "Content" }, + "is_user": { "type": "boolean", "title": "Is User" }, + "session_id": { "type": "string", "title": "Session Id" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + } + }, + "type": "object", + "required": [ + "id", + "content", + "is_user", + "session_id", + "metadata", + "created_at" + ], + "title": "Message", + "exclude": ["h_metadata", "public_id"] + }, + "MessageBatchCreate": { + "properties": { + "messages": { + "items": { "$ref": "#/components/schemas/MessageCreate" }, + "type": "array", + "maxItems": 100, + "title": "Messages" + } + }, + "type": "object", + "required": ["messages"], + "title": "MessageBatchCreate", + "description": "Schema for batch message creation with a max of 100 messages" + }, + "MessageCreate": { + "properties": { + "content": { + "type": "string", + "maxLength": 50000, + "minLength": 0, + "title": "Content" + }, + "is_user": { "type": "boolean", "title": "Is User" }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["content", "is_user"], + "title": "MessageCreate" + }, + "MessageGet": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + } + }, + "type": "object", + "title": "MessageGet" + }, + "MessageUpdate": { + "properties": { + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + } + }, + "type": "object", + "required": ["metadata"], + "title": "MessageUpdate" + }, + "Metamessage": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "metamessage_type": { "type": "string", "title": "Metamessage Type" }, + "content": { "type": "string", "title": "Content" }, + "message_id": { "type": "string", "title": "Message Id" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + } + }, + "type": "object", + "required": [ + "id", + "metamessage_type", + "content", + "message_id", + "metadata", + "created_at" + ], + "title": "Metamessage", + "exclude": ["h_metadata", "public_id"] + }, + "MetamessageCreate": { + "properties": { + "metamessage_type": { + "type": "string", + "maxLength": 50, + "minLength": 1, + "title": "Metamessage Type" + }, + "content": { + "type": "string", + "maxLength": 50000, + "minLength": 0, + "title": "Content" + }, + "message_id": { "type": "string", "title": "Message Id" }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["metamessage_type", "content", "message_id"], + "title": "MetamessageCreate" + }, + "MetamessageGet": { + "properties": { + "metamessage_type": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Metamessage Type" + }, + "message_id": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Message Id" + }, + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + } + }, + "type": "object", + "title": "MetamessageGet" + }, + "MetamessageGetUserLevel": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + }, + "metamessage_type": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Metamessage Type" + } + }, + "type": "object", + "title": "MetamessageGetUserLevel" + }, + "MetamessageUpdate": { + "properties": { + "message_id": { "type": "string", "title": "Message Id" }, + "metamessage_type": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Metamessage Type" + }, + "metadata": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Metadata" + } + }, + "type": "object", + "required": ["message_id"], + "title": "MetamessageUpdate" + }, + "Page_Collection_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/Collection" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[Collection]" + }, + "Page_Document_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/Document" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[Document]" + }, + "Page_Message_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/Message" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[Message]" + }, + "Page_Metamessage_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/Metamessage" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[Metamessage]" + }, + "Page_Session_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/Session" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[Session]" + }, + "Page_User_": { + "properties": { + "items": { + "items": { "$ref": "#/components/schemas/User" }, + "type": "array", + "title": "Items" + }, + "total": { "type": "integer", "minimum": 0, "title": "Total" }, + "page": { "type": "integer", "minimum": 1, "title": "Page" }, + "size": { "type": "integer", "minimum": 1, "title": "Size" }, + "pages": { "type": "integer", "minimum": 0, "title": "Pages" } + }, + "type": "object", + "required": ["items", "total", "page", "size"], + "title": "Page[User]" + }, + "Session": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "is_active": { "type": "boolean", "title": "Is Active" }, + "user_id": { "type": "string", "title": "User Id" }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + } + }, + "type": "object", + "required": ["id", "is_active", "user_id", "metadata", "created_at"], + "title": "Session", + "exclude": ["h_metadata", "public_id"] + }, + "SessionCreate": { + "properties": { + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "title": "SessionCreate" + }, + "SessionGet": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + }, + "is_active": { + "type": "boolean", + "title": "Is Active", + "default": false + } + }, + "type": "object", + "title": "SessionGet" + }, + "SessionUpdate": { + "properties": { + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + } + }, + "type": "object", + "required": ["metadata"], + "title": "SessionUpdate" + }, + "User": { + "properties": { + "id": { "type": "string", "title": "Id" }, + "name": { "type": "string", "title": "Name" }, + "app_id": { "type": "string", "title": "App Id" }, + "created_at": { + "type": "string", + "format": "date-time", + "title": "Created At" + }, + "metadata": { + "type": "object", + "title": "Metadata", + "additionalProperties": true + } + }, + "type": "object", + "required": ["id", "name", "app_id", "created_at", "metadata"], + "title": "User", + "exclude": ["h_metadata", "public_id"] + }, + "UserCreate": { + "properties": { + "name": { + "type": "string", + "maxLength": 100, + "minLength": 1, + "title": "Name" + }, + "metadata": { + "type": "object", + "title": "Metadata", + "default": {}, + "additionalProperties": true + } + }, + "type": "object", + "required": ["name"], + "title": "UserCreate" + }, + "UserGet": { + "properties": { + "filter": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Filter" + } + }, + "type": "object", + "title": "UserGet" + }, + "UserUpdate": { + "properties": { + "name": { + "anyOf": [{ "type": "string" }, { "type": "null" }], + "title": "Name" + }, + "metadata": { + "anyOf": [ + { "type": "object", "additionalProperties": true }, + { "type": "null" } + ], + "title": "Metadata" + } + }, + "type": "object", + "title": "UserUpdate" + }, + "ValidationError": { + "properties": { + "loc": { + "items": { "anyOf": [{ "type": "string" }, { "type": "integer" }] }, + "type": "array", + "title": "Location" + }, + "msg": { "type": "string", "title": "Message" }, + "type": { "type": "string", "title": "Error Type" } + }, + "type": "object", + "required": ["loc", "msg", "type"], + "title": "ValidationError" + } + }, + "securitySchemes": { "HTTPBearer": { "type": "http", "scheme": "bearer" } } + } +} diff --git a/docs/openapi.yml b/docs/openapi.yml deleted file mode 100644 index c8e8162..0000000 --- a/docs/openapi.yml +++ /dev/null @@ -1,4016 +0,0 @@ -components: - schemas: - AgentChat: - properties: - content: - title: Content - type: string - required: - - content - title: AgentChat - type: object - AgentQuery: - properties: - queries: - anyOf: - - type: string - - items: - type: string - type: array - title: Queries - required: - - queries - title: AgentQuery - type: object - App: - exclude: - - h_metadata - - public_id - properties: - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - metadata: - additionalProperties: true - title: Metadata - type: object - name: - title: Name - type: string - required: - - id - - name - - metadata - - created_at - title: App - type: object - AppCreate: - properties: - metadata: - additionalProperties: true - default: {} - title: Metadata - type: object - name: - title: Name - type: string - required: - - name - title: AppCreate - type: object - AppUpdate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - name: - anyOf: - - type: string - - type: 'null' - title: Name - title: AppUpdate - type: object - Collection: - exclude: - - h_metadata - - public_id - properties: - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - metadata: - additionalProperties: true - title: Metadata - type: object - name: - title: Name - type: string - user_id: - title: User Id - type: string - required: - - id - - name - - user_id - - metadata - - created_at - title: Collection - type: object - CollectionCreate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - default: {} - title: Metadata - name: - title: Name - type: string - required: - - name - title: CollectionCreate - type: object - CollectionGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - title: CollectionGet - type: object - CollectionUpdate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - name: - anyOf: - - type: string - - type: 'null' - title: Name - title: CollectionUpdate - type: object - Document: - exclude: - - h_metadata - - public_id - properties: - collection_id: - title: Collection Id - type: string - content: - title: Content - type: string - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - metadata: - additionalProperties: true - title: Metadata - type: object - required: - - id - - content - - metadata - - created_at - - collection_id - title: Document - type: object - DocumentCreate: - properties: - content: - title: Content - type: string - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - default: {} - title: Metadata - required: - - content - title: DocumentCreate - type: object - DocumentGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - title: DocumentGet - type: object - DocumentQuery: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - query: - title: Query - type: string - top_k: - default: 5 - title: Top K - type: integer - required: - - query - title: DocumentQuery - type: object - DocumentUpdate: - properties: - content: - anyOf: - - type: string - - type: 'null' - title: Content - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - title: DocumentUpdate - type: object - HTTPValidationError: - properties: - detail: - items: - $ref: '#/components/schemas/ValidationError' - title: Detail - type: array - title: HTTPValidationError - type: object - Message: - exclude: - - h_metadata - - public_id - properties: - content: - title: Content - type: string - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - is_user: - title: Is User - type: boolean - metadata: - additionalProperties: true - title: Metadata - type: object - session_id: - title: Session Id - type: string - required: - - id - - content - - is_user - - session_id - - metadata - - created_at - title: Message - type: object - MessageCreate: - properties: - content: - title: Content - type: string - is_user: - title: Is User - type: boolean - metadata: - additionalProperties: true - default: {} - title: Metadata - type: object - required: - - content - - is_user - title: MessageCreate - type: object - MessageGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - title: MessageGet - type: object - MessageUpdate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - title: MessageUpdate - type: object - Metamessage: - exclude: - - h_metadata - - public_id - properties: - content: - title: Content - type: string - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - message_id: - title: Message Id - type: string - metadata: - additionalProperties: true - title: Metadata - type: object - metamessage_type: - title: Metamessage Type - type: string - required: - - id - - metamessage_type - - content - - message_id - - metadata - - created_at - title: Metamessage - type: object - MetamessageCreate: - properties: - content: - title: Content - type: string - message_id: - title: Message Id - type: string - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - default: {} - title: Metadata - metamessage_type: - title: Metamessage Type - type: string - required: - - metamessage_type - - content - - message_id - title: MetamessageCreate - type: object - MetamessageGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - message_id: - anyOf: - - type: string - - type: 'null' - title: Message Id - metamessage_type: - anyOf: - - type: string - - type: 'null' - title: Metamessage Type - title: MetamessageGet - type: object - MetamessageGetUserLevel: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - metamessage_type: - anyOf: - - type: string - - type: 'null' - title: Metamessage Type - title: MetamessageGetUserLevel - type: object - MetamessageUpdate: - properties: - message_id: - title: Message Id - type: string - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - metamessage_type: - anyOf: - - type: string - - type: 'null' - title: Metamessage Type - required: - - message_id - title: MetamessageUpdate - type: object - Page_Collection_: - properties: - items: - items: - $ref: '#/components/schemas/Collection' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[Collection] - type: object - Page_Document_: - properties: - items: - items: - $ref: '#/components/schemas/Document' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[Document] - type: object - Page_Message_: - properties: - items: - items: - $ref: '#/components/schemas/Message' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[Message] - type: object - Page_Metamessage_: - properties: - items: - items: - $ref: '#/components/schemas/Metamessage' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[Metamessage] - type: object - Page_Session_: - properties: - items: - items: - $ref: '#/components/schemas/Session' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[Session] - type: object - Page_User_: - properties: - items: - items: - $ref: '#/components/schemas/User' - title: Items - type: array - page: - minimum: 1 - title: Page - type: integer - pages: - minimum: 0 - title: Pages - type: integer - size: - minimum: 1 - title: Size - type: integer - total: - minimum: 0 - title: Total - type: integer - required: - - items - - total - - page - - size - title: Page[User] - type: object - Session: - exclude: - - h_metadata - - public_id - properties: - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - is_active: - title: Is Active - type: boolean - metadata: - additionalProperties: true - title: Metadata - type: object - user_id: - title: User Id - type: string - required: - - id - - is_active - - user_id - - metadata - - created_at - title: Session - type: object - SessionCreate: - properties: - metadata: - additionalProperties: true - default: {} - title: Metadata - type: object - title: SessionCreate - type: object - SessionGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - is_active: - default: false - title: Is Active - type: boolean - title: SessionGet - type: object - SessionUpdate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - title: SessionUpdate - type: object - User: - exclude: - - h_metadata - - public_id - properties: - app_id: - title: App Id - type: string - created_at: - format: date-time - title: Created At - type: string - id: - title: Id - type: string - metadata: - additionalProperties: true - title: Metadata - type: object - name: - title: Name - type: string - required: - - id - - name - - app_id - - created_at - - metadata - title: User - type: object - UserCreate: - properties: - metadata: - additionalProperties: true - default: {} - title: Metadata - type: object - name: - title: Name - type: string - required: - - name - title: UserCreate - type: object - UserGet: - properties: - filter: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Filter - title: UserGet - type: object - UserUpdate: - properties: - metadata: - anyOf: - - additionalProperties: true - type: object - - type: 'null' - title: Metadata - name: - anyOf: - - type: string - - type: 'null' - title: Name - title: UserUpdate - type: object - ValidationError: - properties: - loc: - items: - anyOf: - - type: string - - type: integer - title: Location - type: array - msg: - title: Message - type: string - type: - title: Error Type - type: string - required: - - loc - - msg - - type - title: ValidationError - type: object - securitySchemes: - HTTPBearer: - scheme: bearer - type: http -info: - contact: - email: hello@plasticlabs.ai - name: Plastic Labs - url: https://plasticlabs.ai/ - description: |- - This API is used to store data and get insights about users for AI - applications - summary: An API for adding personalization to AI Apps - title: Honcho API - version: 0.0.14 -openapi: 3.1.0 -paths: - /v1/apps: - post: - description: Create a new App - operationId: create_app_v1_apps_post - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/AppCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/App' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create App - tags: - - apps - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const app = await client.apps.create({ name: 'name' }); - - console.log(app.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - app = client.apps.create( - name="name", - ) - print(app.id) - /v1/apps/get_or_create/{name}: - get: - description: Get or Create an App - operationId: get_or_create_app_v1_apps_get_or_create__name__get - parameters: - - in: path - name: name - required: true - schema: - title: Name - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/App' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Or Create App - tags: - - apps - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const app = await client.apps.getOrCreate('name'); - - console.log(app.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - app = client.apps.get_or_create( - "name", - ) - print(app.id) - /v1/apps/name/{name}: - get: - description: Get an App by Name - operationId: get_app_by_name_v1_apps_name__name__get - parameters: - - in: path - name: name - required: true - schema: - title: Name - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/App' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get App By Name - tags: - - apps - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const app = await client.apps.getByName('name'); - - console.log(app.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - app = client.apps.get_by_name( - "name", - ) - print(app.id) - /v1/apps/{app_id}: - get: - description: Get an App by ID - operationId: get_app_v1_apps__app_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/App' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get App - tags: - - apps - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const app = await client.apps.get('app_id'); - - console.log(app.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - app = client.apps.get( - "app_id", - ) - print(app.id) - put: - description: Update an App - operationId: update_app_v1_apps__app_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/AppUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/App' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update App - tags: - - apps - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const app = await client.apps.update('app_id'); - - console.log(app.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - app = client.apps.update( - app_id="app_id", - ) - print(app.id) - /v1/apps/{app_id}/users: - post: - description: Create a new User - operationId: create_user_v1_apps__app_id__users_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UserCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create User - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const user = await client.apps.users.create('app_id', { name: 'name' }); - - console.log(user.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - user = client.apps.users.create( - app_id="app_id", - name="name", - ) - print(user.id) - /v1/apps/{app_id}/users/get_or_create/{name}: - get: - description: Get a User or create a new one by the input name - operationId: get_or_create_user_v1_apps__app_id__users_get_or_create__name__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: name - required: true - schema: - title: Name - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Or Create User - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const user = await client.apps.users.getOrCreate('app_id', 'name'); - - console.log(user.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - user = client.apps.users.get_or_create( - name="name", - app_id="app_id", - ) - print(user.id) - /v1/apps/{app_id}/users/list: - post: - description: Get All Users for an App - operationId: get_users_v1_apps__app_id__users_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: query - name: reverse - required: false - schema: - default: false - title: Reverse - type: boolean - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UserGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_User_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Users - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const user of client.apps.users.list('app_id')) { - console.log(user.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.list( - app_id="app_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/name/{name}: - get: - description: Get a User by name - operationId: get_user_by_name_v1_apps__app_id__users_name__name__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: name - required: true - schema: - title: Name - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get User By Name - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const user = await client.apps.users.getByName('app_id', 'name'); - - console.log(user.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - user = client.apps.users.get_by_name( - name="name", - app_id="app_id", - ) - print(user.id) - /v1/apps/{app_id}/users/{user_id}: - get: - description: Get a User by ID - operationId: get_user_v1_apps__app_id__users__user_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get User - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const user = await client.apps.users.get('app_id', 'user_id'); - - console.log(user.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - user = client.apps.users.get( - user_id="user_id", - app_id="app_id", - ) - print(user.id) - put: - description: Update a User's name and/or metadata - operationId: update_user_v1_apps__app_id__users__user_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UserUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update User - tags: - - users - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const user = await client.apps.users.update('app_id', 'user_id'); - - console.log(user.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - user = client.apps.users.update( - user_id="user_id", - app_id="app_id", - ) - print(user.id) - /v1/apps/{app_id}/users/{user_id}/collections: - post: - description: Create a new Collection - operationId: create_collection_v1_apps__app_id__users__user_id__collections_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CollectionCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Collection' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create Collection - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const collection = await client.apps.users.collections.create('app_id', 'user_id', { name: 'name' }); - - console.log(collection.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - collection = client.apps.users.collections.create( - user_id="user_id", - app_id="app_id", - name="name", - ) - print(collection.id) - /v1/apps/{app_id}/users/{user_id}/collections/list: - post: - description: Get All Collections for a User - operationId: get_collections_v1_apps__app_id__users__user_id__collections_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CollectionGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Collection_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Collections - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const collection of client.apps.users.collections.list('app_id', 'user_id')) { - console.log(collection.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.collections.list( - user_id="user_id", - app_id="app_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/collections/name/{name}: - get: - description: Get a Collection by Name - operationId: get_collection_by_name_v1_apps__app_id__users__user_id__collections_name__name__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: name - required: true - schema: - title: Name - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Collection' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Collection By Name - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const collection = await client.apps.users.collections.getByName('app_id', 'user_id', 'name'); - - console.log(collection.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - collection = client.apps.users.collections.get_by_name( - name="name", - app_id="app_id", - user_id="user_id", - ) - print(collection.id) - /v1/apps/{app_id}/users/{user_id}/collections/{collection_id}: - delete: - description: Delete a Collection and its documents - operationId: delete_collection_v1_apps__app_id__users__user_id__collections__collection_id__delete - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - responses: - '200': - content: - application/json: - schema: {} - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Delete Collection - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const collection = await client.apps.users.collections.delete('app_id', 'user_id', 'collection_id'); - - console.log(collection); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - collection = client.apps.users.collections.delete( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - ) - print(collection) - get: - description: Get a Collection by ID - operationId: get_collection_by_id_v1_apps__app_id__users__user_id__collections__collection_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Collection' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Collection By Id - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const collection = await client.apps.users.collections.get('app_id', 'user_id', 'collection_id'); - - console.log(collection.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - collection = client.apps.users.collections.get( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - ) - print(collection.id) - put: - description: Update a Collection's name or metadata - operationId: update_collection_v1_apps__app_id__users__user_id__collections__collection_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CollectionUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Collection' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update Collection - tags: - - collections - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const collection = await client.apps.users.collections.update('app_id', 'user_id', 'collection_id'); - - console.log(collection.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - collection = client.apps.users.collections.update( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - ) - print(collection.id) - /v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents: - post: - description: Embed text as a vector and create a Document - operationId: create_document_v1_apps__app_id__users__user_id__collections__collection_id__documents_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/DocumentCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Document' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create Document - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const document = await client.apps.users.collections.documents.create( - 'app_id', - 'user_id', - 'collection_id', - { content: 'content' }, - ); - - console.log(document.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - document = client.apps.users.collections.documents.create( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - content="content", - ) - print(document.id) - /v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/list: - post: - description: Get all of the Documents in a Collection - operationId: get_documents_v1_apps__app_id__users__user_id__collections__collection_id__documents_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/DocumentGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Document_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Documents - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const document of client.apps.users.collections.documents.list( - 'app_id', - 'user_id', - 'collection_id', - )) { - console.log(document.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.collections.documents.list( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/query: - post: - description: Cosine Similarity Search for Documents - operationId: query_documents_v1_apps__app_id__users__user_id__collections__collection_id__documents_query_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/DocumentQuery' - required: true - responses: - '200': - content: - application/json: - schema: - items: - $ref: '#/components/schemas/Document' - title: >- - Response Query Documents V1 Apps App Id Users User Id Collections Collection Id - Documents Query Post - type: array - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Query Documents - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const documents = await client.apps.users.collections.documents.query( - 'app_id', - 'user_id', - 'collection_id', - { query: 'query' }, - ); - - console.log(documents); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - documents = client.apps.users.collections.documents.query( - collection_id="collection_id", - app_id="app_id", - user_id="user_id", - query="query", - ) - print(documents) - /v1/apps/{app_id}/users/{user_id}/collections/{collection_id}/documents/{document_id}: - delete: - description: Delete a Document by ID - operationId: >- - delete_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__delete - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - - in: path - name: document_id - required: true - schema: - title: Document Id - type: string - responses: - '200': - content: - application/json: - schema: {} - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Delete Document - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const document = await client.apps.users.collections.documents.delete( - 'app_id', - 'user_id', - 'collection_id', - 'document_id', - ); - - console.log(document); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - document = client.apps.users.collections.documents.delete( - document_id="document_id", - app_id="app_id", - user_id="user_id", - collection_id="collection_id", - ) - print(document) - get: - description: Get a document by ID - operationId: get_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - - in: path - name: document_id - required: true - schema: - title: Document Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Document' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Document - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const document = await client.apps.users.collections.documents.get( - 'app_id', - 'user_id', - 'collection_id', - 'document_id', - ); - - console.log(document.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - document = client.apps.users.collections.documents.get( - document_id="document_id", - app_id="app_id", - user_id="user_id", - collection_id="collection_id", - ) - print(document.id) - put: - description: Update the content and/or the metadata of a Document - operationId: >- - update_document_v1_apps__app_id__users__user_id__collections__collection_id__documents__document_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: collection_id - required: true - schema: - title: Collection Id - type: string - - in: path - name: document_id - required: true - schema: - title: Document Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/DocumentUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Document' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update Document - tags: - - documents - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const document = await client.apps.users.collections.documents.update( - 'app_id', - 'user_id', - 'collection_id', - 'document_id', - ); - - console.log(document.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - document = client.apps.users.collections.documents.update( - document_id="document_id", - app_id="app_id", - user_id="user_id", - collection_id="collection_id", - ) - print(document.id) - /v1/apps/{app_id}/users/{user_id}/metamessages/list: - post: - description: Paginate through the user metamessages for a user - operationId: get_metamessages_by_user_v1_apps__app_id__users__user_id__metamessages_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MetamessageGetUserLevel' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Metamessage_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Metamessages By User - tags: - - metamessages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const metamessage of client.apps.users.metamessages.list('app_id', 'user_id')) { - console.log(metamessage.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.metamessages.list( - user_id="user_id", - app_id="app_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/sessions: - post: - description: Create a Session for a User - operationId: create_session_v1_apps__app_id__users__user_id__sessions_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/SessionCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Session' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create Session - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const session = await client.apps.users.sessions.create('app_id', 'user_id'); - - console.log(session.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - session = client.apps.users.sessions.create( - user_id="user_id", - app_id="app_id", - ) - print(session.id) - /v1/apps/{app_id}/users/{user_id}/sessions/list: - post: - description: Get All Sessions for a User - operationId: get_sessions_v1_apps__app_id__users__user_id__sessions_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/SessionGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Session_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Sessions - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const session of client.apps.users.sessions.list('app_id', 'user_id')) { - console.log(session.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.sessions.list( - user_id="user_id", - app_id="app_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}: - delete: - description: Delete a session by marking it as inactive - operationId: delete_session_v1_apps__app_id__users__user_id__sessions__session_id__delete - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - responses: - '200': - content: - application/json: - schema: {} - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Delete Session - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const session = await client.apps.users.sessions.delete('app_id', 'user_id', 'session_id'); - - console.log(session); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - session = client.apps.users.sessions.delete( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - print(session) - get: - description: Get a specific session for a user by ID - operationId: get_session_v1_apps__app_id__users__user_id__sessions__session_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Session' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Session - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const session = await client.apps.users.sessions.get('app_id', 'user_id', 'session_id'); - - console.log(session.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - session = client.apps.users.sessions.get( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - print(session.id) - put: - description: Update the metadata of a Session - operationId: update_session_v1_apps__app_id__users__user_id__sessions__session_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/SessionUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Session' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update Session - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const session = await client.apps.users.sessions.update('app_id', 'user_id', 'session_id'); - - console.log(session.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - session = client.apps.users.sessions.update( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - print(session.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat: - post: - description: Chat with the Dialectic API - operationId: chat_v1_apps__app_id__users__user_id__sessions__session_id__chat_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/AgentQuery' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/AgentChat' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Chat - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const agentChat = await client.apps.users.sessions.chat('app_id', 'user_id', 'session_id', { - queries: 'string', - }); - - console.log(agentChat.content); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - agent_chat = client.apps.users.sessions.chat( - session_id="session_id", - app_id="app_id", - user_id="user_id", - queries="string", - ) - print(agent_chat.content) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/chat/stream: - post: - description: Stream Results from the Dialectic API - operationId: get_chat_stream_v1_apps__app_id__users__user_id__sessions__session_id__chat_stream_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/AgentQuery' - required: true - responses: - '200': - content: - application/json: - schema: {} - text/event-stream: - schema: - format: binary - type: string - description: Chat stream - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Chat Stream - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const response = await client.apps.users.sessions.stream('app_id', 'user_id', 'session_id', { - queries: 'string', - }); - - console.log(response); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - response = client.apps.users.sessions.stream( - session_id="session_id", - app_id="app_id", - user_id="user_id", - queries="string", - ) - print(response) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/clone: - get: - description: Clone a session for a user, optionally will deep clone metamessages as well - operationId: clone_session_v1_apps__app_id__users__user_id__sessions__session_id__clone_get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: query - name: message_id - required: false - schema: - anyOf: - - type: string - - type: 'null' - title: Message Id - - in: query - name: deep_copy - required: false - schema: - default: false - title: Deep Copy - type: boolean - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Session' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Clone Session - tags: - - sessions - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const session = await client.apps.users.sessions.clone('app_id', 'user_id', 'session_id'); - - console.log(session.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - session = client.apps.users.sessions.clone( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - print(session.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages: - post: - description: Adds a message to a session - operationId: create_message_for_session_v1_apps__app_id__users__user_id__sessions__session_id__messages_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MessageCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Message' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create Message For Session - tags: - - messages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const message = await client.apps.users.sessions.messages.create('app_id', 'user_id', 'session_id', { - content: 'content', - is_user: true, - }); - - console.log(message.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - message = client.apps.users.sessions.messages.create( - session_id="session_id", - app_id="app_id", - user_id="user_id", - content="content", - is_user=True, - ) - print(message.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/list: - post: - description: Get all messages for a session - operationId: get_messages_v1_apps__app_id__users__user_id__sessions__session_id__messages_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MessageGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Message_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Messages - tags: - - messages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const message of client.apps.users.sessions.messages.list('app_id', 'user_id', 'session_id')) { - console.log(message.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.sessions.messages.list( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/messages/{message_id}: - get: - description: Get a Message by ID - operationId: get_message_v1_apps__app_id__users__user_id__sessions__session_id__messages__message_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: path - name: message_id - required: true - schema: - title: Message Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Message' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Message - tags: - - messages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const message = await client.apps.users.sessions.messages.get( - 'app_id', - 'user_id', - 'session_id', - 'message_id', - ); - - console.log(message.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - message = client.apps.users.sessions.messages.get( - message_id="message_id", - app_id="app_id", - user_id="user_id", - session_id="session_id", - ) - print(message.id) - put: - description: Update the metadata of a Message - operationId: update_message_v1_apps__app_id__users__user_id__sessions__session_id__messages__message_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: path - name: message_id - required: true - schema: - title: Message Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MessageUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Message' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update Message - tags: - - messages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const message = await client.apps.users.sessions.messages.update( - 'app_id', - 'user_id', - 'session_id', - 'message_id', - ); - - console.log(message.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - message = client.apps.users.sessions.messages.update( - message_id="message_id", - app_id="app_id", - user_id="user_id", - session_id="session_id", - ) - print(message.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages: - post: - description: Adds a message to a session - operationId: create_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MetamessageCreate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Metamessage' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Create Metamessage - tags: - - metamessages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const metamessage = await client.apps.users.sessions.metamessages.create( - 'app_id', - 'user_id', - 'session_id', - { content: 'content', message_id: 'message_id', metamessage_type: 'metamessage_type' }, - ); - - console.log(metamessage.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - metamessage = client.apps.users.sessions.metamessages.create( - session_id="session_id", - app_id="app_id", - user_id="user_id", - content="content", - message_id="message_id", - metamessage_type="metamessage_type", - ) - print(metamessage.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages/list: - post: - description: Get all messages for a session - operationId: get_metamessages_v1_apps__app_id__users__user_id__sessions__session_id__metamessages_list_post - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: query - name: reverse - required: false - schema: - anyOf: - - type: boolean - - type: 'null' - default: false - title: Reverse - - description: Page number - in: query - name: page - required: false - schema: - default: 1 - description: Page number - minimum: 1 - title: Page - type: integer - - description: Page size - in: query - name: size - required: false - schema: - default: 50 - description: Page size - maximum: 100 - minimum: 1 - title: Size - type: integer - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MetamessageGet' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Page_Metamessage_' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Metamessages - tags: - - metamessages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - // Automatically fetches more pages as needed. - for await (const metamessage of client.apps.users.sessions.metamessages.list( - 'app_id', - 'user_id', - 'session_id', - )) { - console.log(metamessage.id); - } - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - page = client.apps.users.sessions.metamessages.list( - session_id="session_id", - app_id="app_id", - user_id="user_id", - ) - page = page.items[0] - print(page.id) - /v1/apps/{app_id}/users/{user_id}/sessions/{session_id}/metamessages/{metamessage_id}: - get: - description: Get a specific Metamessage by ID - operationId: >- - get_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages__metamessage_id__get - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: path - name: metamessage_id - required: true - schema: - title: Metamessage Id - type: string - - in: query - name: message_id - required: true - schema: - title: Message Id - type: string - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Metamessage' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Get Metamessage - tags: - - metamessages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const metamessage = await client.apps.users.sessions.metamessages.get( - 'app_id', - 'user_id', - 'session_id', - 'metamessage_id', - { message_id: 'message_id' }, - ); - - console.log(metamessage.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - metamessage = client.apps.users.sessions.metamessages.get( - metamessage_id="metamessage_id", - app_id="app_id", - user_id="user_id", - session_id="session_id", - message_id="message_id", - ) - print(metamessage.id) - put: - description: Update's the metadata of a metamessage - operationId: >- - update_metamessage_v1_apps__app_id__users__user_id__sessions__session_id__metamessages__metamessage_id__put - parameters: - - in: path - name: app_id - required: true - schema: - title: App Id - type: string - - in: path - name: user_id - required: true - schema: - title: User Id - type: string - - in: path - name: session_id - required: true - schema: - title: Session Id - type: string - - in: path - name: metamessage_id - required: true - schema: - title: Metamessage Id - type: string - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/MetamessageUpdate' - required: true - responses: - '200': - content: - application/json: - schema: - $ref: '#/components/schemas/Metamessage' - description: Successful Response - '422': - content: - application/json: - schema: - $ref: '#/components/schemas/HTTPValidationError' - description: Validation Error - security: - - HTTPBearer: [] - - {} - summary: Update Metamessage - tags: - - metamessages - x-codeSamples: - - lang: JavaScript - source: |- - import Honcho from 'honcho-ai'; - - const client = new Honcho({ - apiKey: process.env['HONCHO_API_KEY'], // This is the default and can be omitted - }); - - async function main() { - const metamessage = await client.apps.users.sessions.metamessages.update( - 'app_id', - 'user_id', - 'session_id', - 'metamessage_id', - { message_id: 'message_id' }, - ); - - console.log(metamessage.id); - } - - main(); - - lang: Python - source: |- - import os - from honcho import Honcho - - client = Honcho( - api_key=os.environ.get("HONCHO_API_KEY"), # This is the default and can be omitted - ) - metamessage = client.apps.users.sessions.metamessages.update( - metamessage_id="metamessage_id", - app_id="app_id", - user_id="user_id", - session_id="session_id", - message_id="message_id", - ) - print(metamessage.id) -servers: - - description: Local Development Server - url: http://127.0.0.1:8000 - - description: Demo Server - url: https:/demo.honcho.dev diff --git a/docs/package.json b/docs/package.json index 121be15..e8ba319 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,7 +5,7 @@ "main": ".pnp.js", "scripts": { "dev": "mintlify dev", - "openapi": "npx @mintlify/scraping openapi-file openapi.yml -o api-reference/endpoint", + "openapi": "npx @mintlify/scraping openapi-file openapi.json -o api-reference/endpoint", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", diff --git a/src/crud.py b/src/crud.py index a368c5c..18babd7 100644 --- a/src/crud.py +++ b/src/crud.py @@ -421,6 +421,40 @@ async def create_message( return honcho_message +async def create_messages( + db: AsyncSession, + messages: list[schemas.MessageCreate], + app_id: str, + user_id: str, + session_id: str, +) -> list[models.Message]: + """Bulk create messages for a session while maintaining order""" + # Verify session exists and belongs to user + honcho_session = await get_session( + db, app_id=app_id, session_id=session_id, user_id=user_id + ) + if honcho_session is None: + raise ValueError("Session not found or does not belong to user") + + # Create list of message records + message_records = [ + { + "session_id": session_id, + "is_user": message.is_user, + "content": message.content, + "h_metadata": message.metadata, + } + for message in messages + ] + + # Bulk insert messages and return them in order + stmt = insert(models.Message).returning(models.Message) + result = await db.execute(stmt, message_records) + await db.commit() + + return list(result.scalars().all()) + + async def get_messages( db: AsyncSession, app_id: str, diff --git a/src/models.py b/src/models.py index 0ee3ac7..e78dfd0 100644 --- a/src/models.py +++ b/src/models.py @@ -69,7 +69,7 @@ class User(Base): ) def __repr__(self) -> str: - return f"User(id={self.id}, app_id={self.app_id}, created_at={self.created_at}, h_metadata={self.h_metadata})" + return f"User(id={self.id}, app_id={self.app_id}, public_id={self.public_id} created_at={self.created_at}, h_metadata={self.h_metadata})" class Session(Base): diff --git a/src/routers/collections.py b/src/routers/collections.py index aa5ad59..77f1281 100644 --- a/src/routers/collections.py +++ b/src/routers/collections.py @@ -76,11 +76,11 @@ async def create_collection( db=db, ): """Create a new Collection""" - if collection.name == "honcho": - raise HTTPException( - status_code=406, - detail="error invalid collection configuration - honcho is a reserved name", - ) + # if collection.name == "honcho": + # raise HTTPException( + # status_code=406, + # detail="error invalid collection configuration - honcho is a reserved name", + # ) try: return await crud.create_collection( db, collection=collection, app_id=app_id, user_id=user_id @@ -106,11 +106,6 @@ async def update_collection( status_code=406, detail="error invalid collection configuration - atleast 1 field must be provided", ) - if collection.name is not None and collection.name == "honcho": - raise HTTPException( - status_code=406, - detail="error invalid collection configuration - honcho is a reserved name", - ) try: honcho_collection = await crud.update_collection( db, diff --git a/src/routers/documents.py b/src/routers/documents.py index e021143..1d34095 100644 --- a/src/routers/documents.py +++ b/src/routers/documents.py @@ -85,8 +85,6 @@ async def query_documents( try: top_k = options.top_k - if top_k is not None and top_k > 50: - top_k = 50 # TODO see if we need to paginate this filter = options.filter if options.filter == {}: filter = None diff --git a/src/routers/messages.py b/src/routers/messages.py index cfbb773..5acca92 100644 --- a/src/routers/messages.py +++ b/src/routers/messages.py @@ -1,8 +1,9 @@ -from typing import Optional +from typing import Optional, List from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException from fastapi_pagination import Page from fastapi_pagination.ext.sqlalchemy import paginate +from sqlalchemy.sql import insert from src import crud, schemas from src.db import SessionLocal @@ -17,35 +18,83 @@ ) -async def enqueue(payload: dict): +async def enqueue(payload: dict | list[dict]): async with SessionLocal() as db: - # Get Session and Check metadata - session = await crud.get_session( - db, - app_id=payload["app_id"], - user_id=payload["user_id"], - session_id=payload["session_id"], - ) - # Check if metadata has a "deriver" key - if session is not None: - deriver_disabled = session.h_metadata.get("deriver_disabled") - if deriver_disabled is not None and deriver_disabled is not False: - print("=====================") - print(f"Deriver is not enabled on session {payload['session_id']}") - print("=====================") - # If deriver is not enabled, do not enqueue - return - else: - # Session doesn't exist return - return try: - processed_payload = { - k: str(v) if isinstance(v, str) else v for k, v in payload.items() - } - item = QueueItem(payload=processed_payload, session_id=session.id) - db.add(item) - await db.commit() - return + if isinstance(payload, list): + if not payload: # Empty list check + return + print("Payload:\n", payload) + + # Check session once since all messages are for same session + session = await crud.get_session( + db, + app_id=payload[0]["app_id"], + user_id=payload[0]["user_id"], + session_id=payload[0]["session_id"], + ) + print("Session found:", session is not None) + if session: + print("Session metadata:", session.h_metadata) + + if session is None or ( + session.h_metadata.get("deriver_disabled") is not None + and session.h_metadata.get("deriver_disabled") is not False + ): + print("Skipping enqueue due to session check") + return + + # Process all payloads + queue_records = [ + { + "payload": { + k: str(v) if isinstance(v, str) else v for k, v in p.items() + }, + "session_id": session.id, + } + for p in payload + ] + + print("Number of queue records to insert:", len(queue_records)) + + # Use insert to maintain order + stmt = insert(QueueItem).returning(QueueItem) + result = await db.execute(stmt, queue_records) + await db.commit() + print("Queue items inserted successfully") + return + else: + # Original single insert logic + session = await crud.get_session( + db, + app_id=payload["app_id"], + user_id=payload["user_id"], + session_id=payload["session_id"], + ) + if session is not None: + deriver_disabled = session.h_metadata.get("deriver_disabled") + if deriver_disabled is not None and deriver_disabled is not False: + print("=====================") + print( + f"Deriver is not enabled on session {payload['session_id']}" + ) + print("=====================") + return + else: + return + + processed_payload = { + k: str(v) if isinstance(v, str) else v for k, v in payload.items() + } + # Use insert for consistency + stmt = ( + insert(QueueItem) + .values(payload=processed_payload, session_id=session.id) + .returning(QueueItem) + ) + await db.execute(stmt) + await db.commit() + return except Exception as e: print("=====================") print("FAILURE: in enqueue") @@ -87,6 +136,43 @@ async def create_message_for_session( raise HTTPException(status_code=404, detail="Session not found") from None +@router.post("/batch", response_model=List[schemas.Message]) +async def create_batch_messages_for_session( + app_id: str, + user_id: str, + session_id: str, + batch: schemas.MessageBatchCreate, + background_tasks: BackgroundTasks, + db=db, +): + """Bulk create messages for a session while maintaining order. Maximum 100 messages per batch.""" + try: + created_messages = await crud.create_messages( + db, messages=batch.messages, app_id=app_id, user_id=user_id, session_id=session_id + ) + + # Create payloads for all messages + payloads = [ + { + "app_id": app_id, + "user_id": user_id, + "session_id": session_id, + "message_id": message.public_id, + "is_user": message.is_user, + "content": message.content, + "metadata": message.h_metadata, + } + for message in created_messages + ] + + # Enqueue all messages in one call + background_tasks.add_task(enqueue, payloads) # type: ignore + + return created_messages + except ValueError: + raise HTTPException(status_code=404, detail="Session not found") from None + + @router.post("/list", response_model=Page[schemas.Message]) async def get_messages( app_id: str, @@ -143,8 +229,6 @@ async def update_message( db=db, ): """Update the metadata of a Message""" - if message.metadata is None: - raise HTTPException(status_code=400, detail="Message metadata cannot be empty") try: return await crud.update_message( db, diff --git a/src/routers/sessions.py b/src/routers/sessions.py index e2ff8a4..1c700eb 100644 --- a/src/routers/sessions.py +++ b/src/routers/sessions.py @@ -68,8 +68,6 @@ async def update_session( db=db, ): """Update the metadata of a Session""" - if session.metadata is None: - raise HTTPException(status_code=400, detail="Session metadata cannot be empty") try: return await crud.update_session( db, app_id=app_id, user_id=user_id, session_id=session_id, session=session diff --git a/src/routers/users.py b/src/routers/users.py index fcea0eb..d6137f3 100644 --- a/src/routers/users.py +++ b/src/routers/users.py @@ -23,7 +23,6 @@ async def create_user( db=db, ): """Create a new User""" - print("running create_user") try: return await crud.create_user(db, app_id=app_id, user=user) except IntegrityError as e: diff --git a/src/schemas.py b/src/schemas.py index 3df63ad..a2fb23c 100644 --- a/src/schemas.py +++ b/src/schemas.py @@ -1,4 +1,5 @@ import datetime +from typing import Annotated from pydantic import BaseModel, ConfigDict, Field, field_validator @@ -8,7 +9,7 @@ class AppBase(BaseModel): class AppCreate(AppBase): - name: str + name: Annotated[str, Field(min_length=1, max_length=100)] metadata: dict = {} @@ -44,7 +45,7 @@ class UserBase(BaseModel): class UserCreate(UserBase): - name: str + name: Annotated[str, Field(min_length=1, max_length=100)] metadata: dict = {} @@ -54,7 +55,7 @@ class UserGet(UserBase): class UserUpdate(UserBase): name: str | None = None - metadata: dict | None = None + metadata: dict | None = None # Allow user to explicitly set metadata to empty class User(UserBase): @@ -85,7 +86,7 @@ class MessageBase(BaseModel): class MessageCreate(MessageBase): - content: str + content: Annotated[str, Field(min_length=0, max_length=50000)] is_user: bool metadata: dict = {} @@ -95,7 +96,7 @@ class MessageGet(MessageBase): class MessageUpdate(MessageBase): - metadata: dict | None = None + metadata: dict class Message(MessageBase): @@ -136,7 +137,7 @@ class SessionGet(SessionBase): class SessionUpdate(SessionBase): - metadata: dict | None = None + metadata: dict class Session(SessionBase): @@ -169,10 +170,10 @@ class MetamessageBase(BaseModel): class MetamessageCreate(MetamessageBase): - metamessage_type: str - content: str + metamessage_type: Annotated[str, Field(min_length=1, max_length=50)] + content: Annotated[str, Field(min_length=0, max_length=50000)] message_id: str - metadata: dict | None = {} + metadata: dict = {} class MetamessageGet(MetamessageBase): @@ -221,8 +222,14 @@ class CollectionBase(BaseModel): class CollectionCreate(CollectionBase): - name: str - metadata: dict | None = {} + name: Annotated[str, Field(min_length=1, max_length=100)] + metadata: dict = {} + + @field_validator("name") + def validate_name(cls, v): + if v.lower() == "honcho": + raise ValueError("Collection name cannot be 'honcho'") + return v class CollectionGet(CollectionBase): @@ -233,6 +240,12 @@ class CollectionUpdate(CollectionBase): name: str | None = None metadata: dict | None = None + @field_validator("name") + def validate_name(cls, v): + if v is not None and v.lower() == "honcho": + raise ValueError("Collection name cannot be 'honcho'") + return v + class Collection(CollectionBase): public_id: str = Field(exclude=True) @@ -262,8 +275,8 @@ class DocumentBase(BaseModel): class DocumentCreate(DocumentBase): - content: str - metadata: dict | None = {} + content: Annotated[str, Field(min_length=1, max_length=100000)] + metadata: dict = {} class DocumentGet(DocumentBase): @@ -271,14 +284,14 @@ class DocumentGet(DocumentBase): class DocumentQuery(DocumentBase): - query: str + query: Annotated[str, Field(min_length=1, max_length=1000)] filter: dict | None = None - top_k: int = 5 + top_k: int = Field(default=5, ge=1, le=50) class DocumentUpdate(DocumentBase): - metadata: dict | None = None - content: str | None = None + metadata: dict | None = Field(None, max_length=10000) + content: Annotated[str | None, Field(min_length=1, max_length=100000)] = None class Document(DocumentBase): @@ -306,8 +319,25 @@ def internal_to_public(cls, value, info): class AgentQuery(BaseModel): queries: str | list[str] - # collections: str | list[str] = "honcho" + @field_validator('queries') + def validate_queries(cls, v): + MAX_STRING_LENGTH = 10000 + MAX_LIST_LENGTH = 25 + if isinstance(v, str): + if len(v) > MAX_STRING_LENGTH: + raise ValueError('Query too long') + elif isinstance(v, list): + if len(v) > MAX_LIST_LENGTH: + raise ValueError('Too many queries') + if any(len(q) > MAX_STRING_LENGTH for q in v): + raise ValueError('One or more queries too long') + return v class AgentChat(BaseModel): content: str + + +class MessageBatchCreate(BaseModel): + """Schema for batch message creation with a max of 100 messages""" + messages: list[MessageCreate] = Field(..., max_length=100) diff --git a/tests/routes/test_apps.py b/tests/routes/test_apps.py index 801d77f..d72bf69 100644 --- a/tests/routes/test_apps.py +++ b/tests/routes/test_apps.py @@ -17,6 +17,20 @@ def test_create_app(client): assert "id" in data +def test_create_app_no_metadata(client): + name = str(generate_nanoid()) + response = client.post("/v1/apps", json={"name": name}) + print(response) + assert response.status_code == 200 + data = response.json() + print("===================") + print(data) + print("===================") + assert data["name"] == name + assert data["metadata"] == {} + assert "id" in data + + def test_get_or_create_app(client): name = str(generate_nanoid()) response = client.get(f"/v1/apps/name/{name}") diff --git a/tests/routes/test_messages.py b/tests/routes/test_messages.py index 2bc8ee8..d4bff1c 100644 --- a/tests/routes/test_messages.py +++ b/tests/routes/test_messages.py @@ -110,3 +110,101 @@ async def test_update_message(client, db_session, sample_data): assert response.status_code == 200 data = response.json() assert data["metadata"] == {"new_key": "new_value"} + +@pytest.mark.asyncio +async def test_update_message_empty_metadata(client, db_session, sample_data): + test_app, test_user = sample_data + # Create a test session and message + test_session = models.Session(user_id=test_user.public_id) + db_session.add(test_session) + await db_session.commit() + test_message = models.Message( + session_id=test_session.public_id, content="Test message", is_user=True + ) + db_session.add(test_message) + await db_session.commit() + + response = client.put( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{test_session.public_id}/messages/{test_message.public_id}", + json={"metadata": None}, + ) + assert response.status_code == 422 + data = response.json() + print(data) + # assert data["detail"] == "Message metadata cannot be empty" + + +@pytest.mark.asyncio +async def test_create_batch_messages(client, db_session, sample_data): + test_app, test_user = sample_data + # Create a test session + test_session = models.Session(user_id=test_user.public_id) + db_session.add(test_session) + await db_session.commit() + + # Create batch of test messages + test_messages = { + "messages": [ + { + "content": f"Test message {i}", + "is_user": i % 2 == 0, # Alternating user/non-user messages + "metadata": {"batch_index": i} + } for i in range(3) + ] + } + + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{test_session.public_id}/messages/batch", + json=test_messages, + ) + + assert response.status_code == 200 + data = response.json() + + # Verify the response contains all messages + assert len(data) == 3 + + # Verify messages are in the correct order and have correct content + for i, message in enumerate(data): + assert message["content"] == f"Test message {i}" + assert message["is_user"] == (i % 2 == 0) + assert message["metadata"] == {"batch_index": i} + assert "id" in message + assert message["session_id"] == test_session.public_id + + # Verify messages were actually saved to the database + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{test_session.public_id}/messages/list", + json={}, + ) + assert response.status_code == 200 + saved_messages = response.json()["items"] + assert len(saved_messages) == 3 + + +@pytest.mark.asyncio +async def test_create_batch_messages_limit(client, db_session, sample_data): + test_app, test_user = sample_data + test_session = models.Session(user_id=test_user.public_id) + db_session.add(test_session) + await db_session.commit() + + # Create batch with more than 100 messages + test_messages = { + "messages": [ + { + "content": f"Test message {i}", + "is_user": i % 2 == 0, + "metadata": {"batch_index": i} + } for i in range(101) # 101 messages + ] + } + + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{test_session.public_id}/messages/batch", + json=test_messages, + ) + + assert response.status_code == 422 # Validation error + data = response.json() + assert "messages" in data["detail"][0]["loc"] # Error should mention messages field diff --git a/tests/routes/test_sessions.py b/tests/routes/test_sessions.py index a07b641..50e15ae 100644 --- a/tests/routes/test_sessions.py +++ b/tests/routes/test_sessions.py @@ -67,7 +67,7 @@ async def test_empty_update_session(client, db_session, sample_data): f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{test_session.public_id}", json={}, ) - assert response.status_code == 400 + assert response.status_code == 422 @pytest.mark.asyncio diff --git a/tests/routes/test_validation_api.py b/tests/routes/test_validation_api.py new file mode 100644 index 0000000..3d1cbbd --- /dev/null +++ b/tests/routes/test_validation_api.py @@ -0,0 +1,516 @@ +import pytest +from nanoid import generate as generate_nanoid + + +def test_app_validations_api(client): + # Test name too short + response = client.post("/v1/apps", json={"name": "", "metadata": {}}) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test name too long + response = client.post("/v1/apps", json={"name": "a" * 101, "metadata": {}}) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at most 100 characters" + assert error["type"] == "string_too_long" + + # Test invalid metadata type + response = client.post("/v1/apps", json={"name": "test", "metadata": "not a dict"}) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "metadata"] + assert error["type"] == "dict_type" + + +def test_user_validations_api(client, sample_data): + test_app, _ = sample_data + + # Test name too short + response = client.post( + f"/v1/apps/{test_app.public_id}/users", + json={"name": "", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test name too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users", + json={"name": "a" * 101, "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at most 100 characters" + assert error["type"] == "string_too_long" + + +def test_message_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a test session first + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test content too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages", + json={ + "content": "a" * 50001, + "is_user": True, + "metadata": {} + } + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["msg"] == "String should have at most 50000 characters" + assert error["type"] == "string_too_long" + + # Test invalid is_user type + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages", + json={ + "content": "test", + "is_user": "not a bool", + "metadata": {} + } + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "is_user"] + assert error["type"] == "bool_parsing" + + +def test_collection_validations_api(client, sample_data): + test_app, test_user = sample_data + + # Test name too short + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": "", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test name too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": "a" * 101, "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "String should have at most 100 characters" + assert error["type"] == "string_too_long" + + # Test 'honcho' name restriction + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": "honcho", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "Value error, Collection name cannot be 'honcho'" + assert error["type"] == "value_error" + + +def test_document_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a collection first + collection_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": str(generate_nanoid()), "metadata": {}} + ) + collection_id = collection_response.json()["id"] + + # Test content too short + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents", + json={"content": "", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test content too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents", + json={"content": "a" * 100001, "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["msg"] == "String should have at most 100000 characters" + assert error["type"] == "string_too_long" + + +def test_document_query_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a collection first + collection_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": str(generate_nanoid()), "metadata": {}} + ) + collection_id = collection_response.json()["id"] + + # Test query too short + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents/query", + json={"query": "", "top_k": 5} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "query"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test query too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents/query", + json={"query": "a" * 1001, "top_k": 5} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "query"] + assert error["msg"] == "String should have at most 1000 characters" + assert error["type"] == "string_too_long" + + # Test top_k too small + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents/query", + json={"query": "test", "top_k": 0} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "top_k"] + assert error["msg"] == "Input should be greater than or equal to 1" + assert error["type"] == "greater_than_equal" + + # Test top_k too large + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents/query", + json={"query": "test", "top_k": 51} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "top_k"] + assert error["msg"] == "Input should be less than or equal to 50" + assert error["type"] == "less_than_equal" + + +def test_message_batch_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a test session first + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test batch too large + messages = [ + { + "content": f"test message {i}", + "is_user": True, + "metadata": {} + } + for i in range(101) # Create 101 messages + ] + + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages/batch", + json={"messages": messages} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "messages"] + assert "List should have at most 100 items after validation" in error["msg"] + assert error["type"] == "too_long" + + +def test_metamessage_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create session and message first + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + message_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages", + json={"content": "test message", "is_user": True, "metadata": {}} + ) + message_id = message_response.json()["id"] + + # Test metamessage_type too short + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/metamessages", + json={ + "metamessage_type": "", + "content": "test content", + "message_id": message_id, + "metadata": {} + } + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "metamessage_type"] + assert error["msg"] == "String should have at least 1 character" + assert error["type"] == "string_too_short" + + # Test metamessage_type too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/metamessages", + json={ + "metamessage_type": "a" * 51, + "content": "test content", + "message_id": message_id, + "metadata": {} + } + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "metamessage_type"] + assert error["msg"] == "String should have at most 50 characters" + assert error["type"] == "string_too_long" + + # Test content too long + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/metamessages", + json={ + "metamessage_type": "test_type", + "content": "a" * 50001, + "message_id": message_id, + "metadata": {} + } + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["msg"] == "String should have at most 50000 characters" + assert error["type"] == "string_too_long" + + +def test_collection_update_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a collection first + collection_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": str(generate_nanoid()), "metadata": {}} + ) + collection_id = collection_response.json()["id"] + + # Test honcho name in update + response = client.put( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}", + json={"name": "honcho", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["msg"] == "Value error, Collection name cannot be 'honcho'" + assert error["type"] == "value_error" + + +def test_document_update_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create collection and document first + collection_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"name": str(generate_nanoid()), "metadata": {}} + ) + collection_id = collection_response.json()["id"] + + document_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents", + json={"content": "test content", "metadata": {}} + ) + document_id = document_response.json()["id"] + + # Test content too long in update + response = client.put( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/{collection_id}/documents/{document_id}", + json={"content": "a" * 100001, "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["msg"] == "String should have at most 100000 characters" + assert error["type"] == "string_too_long" + + +def test_session_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a test session first + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test invalid metadata type + response = client.put( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}", + json={"metadata": "not a dict"} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "metadata"] + assert error["type"] == "dict_type" + + # Test empty update + response = client.put( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}", + json={} + ) + assert response.status_code == 422 + + +def test_agent_query_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a session first since agent queries are likely session-based + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test valid string query (under 10000 chars) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": "a" * 9999} + ) + assert response.status_code == 200 + + # Test string query too long (over 10000 chars) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": "a" * 10001} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "queries"] + assert error["msg"] == "Value error, Query too long" + assert error["type"] == "value_error" + + # Test valid list query (under 25 items, each under 10000 chars) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": ["a" * 9999 for _ in range(25)]} + ) + assert response.status_code == 200 + + # Test list too long (over 25 items) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": ["test" for _ in range(26)]} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "queries"] + assert error["type"] == "value_error" + + # Test list item too long (item over 10000 chars) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": ["a" * 10001]} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "queries"] + assert error["msg"] == "Value error, One or more queries too long" + assert error["type"] == "value_error" + + # Test that strings over 20 chars are allowed + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/chat", + json={"queries": "a" * 100} # 100 chars should be fine + ) + assert response.status_code == 200 + + +def test_required_field_validations_api(client, sample_data): + test_app, test_user = sample_data + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test missing required content in message + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages", + json={"is_user": True, "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "content"] + assert error["type"] == "missing" + + # Test missing required is_user in message + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages", + json={"content": "test", "metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "is_user"] + assert error["type"] == "missing" + + # Test missing required name in collection + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections", + json={"metadata": {}} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "name"] + assert error["type"] == "missing" + + +def test_filter_validations_api(client, sample_data): + test_app, test_user = sample_data + # Create a session first + session_response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions", + json={"metadata": {}} + ) + session_id = session_response.json()["id"] + + # Test invalid filter type in message list (at session level) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/sessions/{session_id}/messages/list", + json={"filter": "not a dict"} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "filter"] + assert error["type"] == "dict_type" + + # Test invalid filter type in collection list (at user level) + response = client.post( + f"/v1/apps/{test_app.public_id}/users/{test_user.public_id}/collections/list", + json={"filter": "not a dict"} + ) + assert response.status_code == 422 + error = response.json()["detail"][0] + assert error["loc"] == ["body", "filter"] + assert error["type"] == "dict_type" diff --git a/tests/test_schema_validations.py b/tests/test_schema_validations.py new file mode 100644 index 0000000..39ab358 --- /dev/null +++ b/tests/test_schema_validations.py @@ -0,0 +1,218 @@ +import pytest +from pydantic import ValidationError +from src.schemas import ( + AppCreate, + UserCreate, + MessageCreate, + MetamessageCreate, + CollectionCreate, + DocumentCreate, + DocumentQuery, + MessageBatchCreate, +) + + +class TestAppValidations: + def test_valid_app_create(self): + app = AppCreate(name="test", metadata={}) + assert app.name == "test" + assert app.metadata == {} + + def test_app_name_too_short(self): + with pytest.raises(ValidationError) as exc_info: + AppCreate(name="", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_app_name_too_long(self): + with pytest.raises(ValidationError) as exc_info: + AppCreate(name="a" * 101, metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + def test_app_invalid_metadata_type(self): + with pytest.raises(ValidationError) as exc_info: + AppCreate(name="test", metadata="not a dict") + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "dict_type" + + +class TestUserValidations: + def test_valid_user_create(self): + user = UserCreate(name="test", metadata={}) + assert user.name == "test" + assert user.metadata == {} + + def test_user_name_too_short(self): + with pytest.raises(ValidationError) as exc_info: + UserCreate(name="", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_user_name_too_long(self): + with pytest.raises(ValidationError) as exc_info: + UserCreate(name="a" * 101, metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + +class TestMessageValidations: + def test_valid_message_create(self): + msg = MessageCreate(content="test", is_user=True, metadata={}) + assert msg.content == "test" + assert msg.is_user is True + assert msg.metadata == {} + + def test_message_content_too_long(self): + with pytest.raises(ValidationError) as exc_info: + MessageCreate(content="a" * 50001, is_user=True, metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + def test_message_invalid_is_user_type(self): + with pytest.raises(ValidationError) as exc_info: + MessageCreate(content="test", is_user="not a bool", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "bool_parsing" + + +class TestMetamessageValidations: + def test_valid_metamessage_create(self): + meta = MetamessageCreate( + metamessage_type="test", + content="test content", + message_id="123", + metadata={}, + ) + assert meta.metamessage_type == "test" + assert meta.content == "test content" + assert meta.message_id == "123" + + def test_metamessage_type_too_short(self): + with pytest.raises(ValidationError) as exc_info: + MetamessageCreate( + metamessage_type="", + content="test", + message_id="123", + metadata={}, + ) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_metamessage_type_too_long(self): + with pytest.raises(ValidationError) as exc_info: + MetamessageCreate( + metamessage_type="a" * 51, + content="test", + message_id="123", + metadata={}, + ) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + def test_metamessage_content_too_long(self): + with pytest.raises(ValidationError) as exc_info: + MetamessageCreate( + metamessage_type="test", + content="a" * 50001, + message_id="123", + metadata={}, + ) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + +class TestCollectionValidations: + def test_valid_collection_create(self): + collection = CollectionCreate(name="test", metadata={}) + assert collection.name == "test" + assert collection.metadata == {} + + def test_collection_name_too_short(self): + with pytest.raises(ValidationError) as exc_info: + CollectionCreate(name="", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_collection_name_too_long(self): + with pytest.raises(ValidationError) as exc_info: + CollectionCreate(name="a" * 101, metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + def test_collection_name_honcho(self): + with pytest.raises(ValidationError) as exc_info: + CollectionCreate(name="honcho", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "value_error" + + +class TestDocumentValidations: + def test_valid_document_create(self): + doc = DocumentCreate(content="test content", metadata={}) + assert doc.content == "test content" + assert doc.metadata == {} + + def test_document_content_too_short(self): + with pytest.raises(ValidationError) as exc_info: + DocumentCreate(content="", metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_document_content_too_long(self): + with pytest.raises(ValidationError) as exc_info: + DocumentCreate(content="a" * 100001, metadata={}) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + +class TestDocumentQueryValidations: + def test_valid_document_query(self): + query = DocumentQuery(query="test query", top_k=5) + assert query.query == "test query" + assert query.top_k == 5 + + def test_query_too_short(self): + with pytest.raises(ValidationError) as exc_info: + DocumentQuery(query="", top_k=5) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_short" + + def test_query_too_long(self): + with pytest.raises(ValidationError) as exc_info: + DocumentQuery(query="a" * 1001, top_k=5) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "string_too_long" + + def test_top_k_too_small(self): + with pytest.raises(ValidationError) as exc_info: + DocumentQuery(query="test", top_k=0) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "greater_than_equal" + + def test_top_k_too_large(self): + with pytest.raises(ValidationError) as exc_info: + DocumentQuery(query="test", top_k=51) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "less_than_equal" + + +class TestMessageBatchValidations: + def test_valid_message_batch(self): + batch = MessageBatchCreate( + messages=[ + MessageCreate(content="test", is_user=True, metadata={}) + ] + ) + assert len(batch.messages) == 1 + + def test_message_batch_too_large(self): + with pytest.raises(ValidationError) as exc_info: + MessageBatchCreate( + messages=[ + MessageCreate(content="test", is_user=True, metadata={}) + for _ in range(101) + ] + ) + error_dict = exc_info.value.errors()[0] + assert error_dict["type"] == "too_long" \ No newline at end of file