### Start Open Assistant API Application Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Starts the main Python application for the Open Assistant API. This command assumes the environment and dependencies are correctly set up. ```sh python main.py ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Command to install project dependencies using Poetry. The `--no-root` flag is used, suggesting that the project itself is not intended to be installed as a package directly during local development. ```shell poetry install --no-root ``` -------------------------------- ### Install Poetry Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Provides instructions for installing Poetry, a Python dependency management tool. It shows two methods: using a curl command to download and execute an installation script, or using pip. ```shell curl -sSL https://install.python-poetry.org | python3 - ``` ```shell pip install poetry ``` -------------------------------- ### Copy Environment Example Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md This command copies the example environment file to a new file named `.env`. This is a common practice for setting up application configurations, allowing users to customize settings without modifying the original example. ```shell cp .env.example .env ``` -------------------------------- ### Execute Example Script for Open Assistant API Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Demonstrates how to run an example Python script that utilizes the Open Assistant API. It includes installing the 'openai' library and setting the PYTHONPATH environment variable. ```sh # !pip install openai export PYTHONPATH=$(pwd) python examples/run_assistant.py ``` -------------------------------- ### Initialize Database with Alembic Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Initializes the database schema and applies the latest migrations using Alembic. This command is crucial for the initial setup and version upgrades of the database. ```sh alembic upgrade head ``` -------------------------------- ### Assistant Creation Example Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Example demonstrating how to create an assistant using the official OpenAI Python client library with the Open Assistant API. ```APIDOC ## POST /api/v1/assistants ### Description Creates an assistant with specified name, instructions, and model. ### Method POST ### Endpoint /api/v1/assistants ### Parameters #### Request Body - **name** (string) - Required - The name of the assistant. - **instructions** (string) - Required - The instructions for the assistant. - **model** (string) - Required - The model to use for the assistant (e.g., "gpt-4-1106-preview"). ### Request Example ```python import openai client = openai.OpenAI( base_url="http://127.0.0.1:8086/api/v1", api_key="xxx" ) assistant = client.beta.assistants.create( name="demo", instructions="You are a helpful assistant.", model="gpt-4-1106-preview" ) ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier of the created assistant. - **name** (string) - The name of the assistant. - **instructions** (string) - The instructions for the assistant. - **model** (string) - The model used by the assistant. #### Response Example ```json { "id": "asst_abc123", "name": "demo", "instructions": "You are a helpful assistant.", "model": "gpt-4-1106-preview" } ``` ``` -------------------------------- ### Deploy Open Assistant API with Docker Compose Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Deploys the application using Docker Compose. This command starts the services defined in the docker-compose.yml file, including the built API image. ```sh docker compose up -d ``` -------------------------------- ### Start Celery Scheduler Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Starts the Celery worker to handle background tasks and scheduling for the application. It configures the worker with a specific concurrency and log level. ```sh celery -A worker.celery_app worker -c 1 --loglevel DEBUG ``` -------------------------------- ### Open Assistant API Usage Example Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md This section demonstrates how to use the Open Assistant API with the official OpenAI Python client library. It shows the basic setup for creating an assistant. ```APIDOC ## OpenAI Python Client Example ### Description This code snippet shows how to initialize the OpenAI Python client to interact with the Open Assistant API. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example ```python import openai client = openai.OpenAI( base_url="http://127.0.0.1:8086/api/v1", api_key="xxx" ) assistant = client.beta.assistants.create( name="demo", instructions="You are a helpful assistant.", model="gpt-4-1106-preview" ) ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### Deploy Middleware (MySQL, Redis, MinIO) Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Deploys essential middleware services like MySQL, Redis, and MinIO using Docker Compose. This is a prerequisite for running the application. ```sh docker compose -f docker-compose.middleware.yml up -d ``` -------------------------------- ### Build Docker Image for Open Assistant API Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Builds a Docker image for the Open Assistant API, tagging it as 'open-assistant-api'. This image can then be used for deployment. ```sh docker build -t open-assistant-api . ``` -------------------------------- ### Create Assistant using OpenAI Python Client Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Demonstrates how to create an AI assistant using the official OpenAI Python library. It requires the 'openai' library to be installed and specifies the base URL and API key for the Open Assistant API. ```python import openai client = openai.OpenAI( base_url="http://127.0.0.1:8086/api/v1", api_key="xxx" ) assistant = client.beta.assistants.create( name="demo", instructions="You are a helpful assistant.", model="gpt-4-1106-preview" ) ``` -------------------------------- ### Check Code Specification with Make Lint Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Executes the linting process defined in the Makefile to check for code style compliance and potential errors before submission. ```sh make lint ``` -------------------------------- ### Configure API Keys in .env Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Illustrates how to set essential API keys within the `.env` file for services like OpenAI. This configuration is crucial for the application to interact with external services. ```shell # openai api_key OPENAI_API_KEY= ``` -------------------------------- ### Format Code with Make Format Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Applies automatic code formatting according to the project's specifications, as defined in the Makefile. This ensures code consistency across the project. ```sh make format ``` -------------------------------- ### Generate Database Migration Script with Alembic Source: https://github.com/mlt-oss/open-assistant-api/blob/main/docs/CONTRIBUTING.md Generates a new database migration script based on changes detected in the database models. This is used when the DB model is modified. ```sh alembic revision --autogenerate ``` -------------------------------- ### 配置 Docker Compose 环境变量 Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md 配置 Open Assistant API 的 Docker Compose 文件中的环境变量。主要包括 OpenAI API 密钥(支持 OneAPI)和可选的 Bing 搜索密钥。这些变量用于连接后端服务和启用特定功能。 ```sh # openai api_key (支持 OneAPI api_key) OPENAI_API_KEY= # bing search key (非必填) BING_SUBSCRIPTION_KEY= ``` -------------------------------- ### Configure API Keys for Open Assistant API Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Shows how to set environment variables for API keys required by the Open Assistant API. This includes the OpenAI API key (or OneAPI key) and an optional Bing search key. ```sh # openai api_key (supports OneAPI api_key) OPENAI_API_KEY= # bing search key (optional) BING_SUBSCRIPTION_KEY= ``` -------------------------------- ### Configure RAG Engine for Open Assistant API Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Details the configuration for integrating the R2R RAG engine with the Open Assistant API. This involves setting environment variables for the file service module and R2R connection details. ```sh # RAG config # FILE_SERVICE_MODULE=app.services.file.impl.oss_file.OSSFileService FILE_SERVICE_MODULE=app.services.file.impl.r2r_file.R2RFileService R2R_BASE_URL=http:// R2R_USERNAME= R2R_PASSWORD= ``` -------------------------------- ### Environment Variables Configuration Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md Configuration details for running the Open Assistant API using Docker Compose, including API keys and RAG engine settings. ```APIDOC ## Environment Variables Configuration ### Description Configuration environment variables required for running the Open Assistant API with Docker Compose. ### Method N/A ### Endpoint N/A ### Parameters #### Environment Variables - **OPENAI_API_KEY** (string) - Required - The API key for accessing OpenAI or compatible services. - **BING_SUBSCRIPTION_KEY** (string) - Optional - The subscription key for Bing search. - **FILE_SERVICE_MODULE** (string) - Optional - Specifies the file service implementation (e.g., `app.services.file.impl.r2r_file.R2RFileService`). - **R2R_BASE_URL** (string) - Conditional (if FILE_SERVICE_MODULE is R2R) - The base URL for the R2R engine. - **R2R_USERNAME** (string) - Conditional (if FILE_SERVICE_MODULE is R2R) - The username for R2R authentication. - **R2R_PASSWORD** (string) - Conditional (if FILE_SERVICE_MODULE is R2R) - The password for R2R authentication. - **APP_AUTH_ENABLE** (boolean) - Optional - Enables or disables application-level authentication. - **APP_AUTH_ADMIN_TOKEN** (string) - Conditional (if APP_AUTH_ENABLE is true) - The admin token for authentication management. ### Request Example ```sh # openai api_key (支持 OneAPI api_key) OPENAI_API_KEY= # bing search key (非必填) BING_SUBSCRIPTION_KEY= # RAG 配置 FILE_SERVICE_MODULE=app.services.file.impl.r2r_file.R2RFileService R2R_BASE_URL=http:// R2R_USERNAME= R2R_PASSWORD= ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### Tool Integration Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md Information on how to integrate tools with assistants to enhance LLM capabilities, including connecting to external systems and services. ```APIDOC ## Tool Integration ### Description Details on integrating external tools with assistants to provide LLMs with the ability to interact with the external world, such as executing code or accessing specific information sources. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Token Authentication Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README.md Information on how to authenticate requests using Bearer tokens for user isolation and SaaS deployment. ```APIDOC ## Authentication ### Description Requests to the API can be authenticated using Bearer tokens for user isolation. ### Method All methods ### Endpoint All endpoints ### Parameters #### Request Headers - **Authorization** (string) - Required - The Bearer token for authentication (e.g., `Authorization: Bearer ***`). ### Notes - Admin token is configured via `APP_AUTH_ADMIN_TOKEN` and defaults to "admin". - When creating a token, specify the base URL and API key of the large model. ``` -------------------------------- ### 通过 Token 进行 API 认证 Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md 展示了如何通过 Bearer token 进行 API 认证,这满足了 SaaS 部署的用户隔离需求。认证信息需要放在请求头中,格式为 `Authorization: Bearer ***`。管理员 token 配置为 `APP_AUTH_ADMIN_TOKEN`。 ```sh Authorization: Bearer *** ``` -------------------------------- ### 配置 R2R RAG 引擎环境变量 Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md 配置用于 R2R RAG 引擎的环境变量,以替换默认的 RAG 实现。需要指定 R2R 的基础 URL、用户名和密码。此外,还需要设置 FILE_SERVICE_MODULE 为 R2R 实现。 ```sh # RAG 配置 # FILE_SERVICE_MODULE=app.services.file.impl.oss_file.OSSFileService FILE_SERVICE_MODULE=app.services.file.impl.r2r_file.R2RFileService R2R_BASE_URL=http:// R2R_USERNAME= R2R_PASSWORD= ``` -------------------------------- ### Authentication Source: https://github.com/mlt-oss/open-assistant-api/blob/main/README_CN.md Details on how authentication is handled, including Bearer tokens and admin token usage for SaaS deployment. ```APIDOC ## Authentication ### Description Explains the authentication mechanism used by the Open Assistant API, focusing on token-based authentication for user isolation and SaaS deployment. ### Method N/A ### Endpoint N/A ### Parameters #### Authentication Headers - **Authorization** (string) - Required - Format: `Bearer ***`, where `***` is the user's token. #### Environment Variables - **APP_AUTH_ENABLE** (boolean) - Optional - Enables or disables application-level authentication. - **APP_AUTH_ADMIN_TOKEN** (string) - Conditional (if APP_AUTH_ENABLE is true) - The admin token required for validating related APIs and token management. ### Request Example `Authorization: Bearer ***` ### Response N/A ### Response Example N/A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.