openapi: "3.0.1"
info:
  title: "Rasa Platform - Model CI/CD"
  version: "1.0.0"
  description: >-
    Rasa Platform model CI/CD endpoints
servers:
  - url: http://demo-bot.rasa.com/api
    description: Demo
paths:
  /projects/{project_id}:
    post:
      tags:
        - Models
      summary: Create a project
      operationId: postProject
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      responses:
        200:
          description: Newly created project
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Project'
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/models:
    post:
      tags:
        - Models
      summary: Train a model
      operationId: trainModel
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      responses:
        200:
          description: Confirmation of model training
        401:
          $ref: '#/components/responses/UnauthorizedError'
    get:
      tags:
        - Models
      summary: Get available models
      operationId: getAvailableModels
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
        - in: query
          name: offset
          schema:
            default: 0
            type: number
        - in: query
          name: limit
          schema:
            default: null
            type: number
      responses:
        200:
          description: Available models
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    model:
                      type: string
                    version:
                      type: string
                    is_compatible:
                      type: boolean
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/models/active:
    get:
      tags:
        - Models
      summary: Get the active model
      operationId: getActiveModel
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      responses:
        200:
          description: Active model
          content:
            application/json:
              schema:
                type: object
                properties:
                  active_model:
                    type: string
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/models/{model_name}:
    put:
      tags:
        - Models
      summary: Set active model
      operationId: setActiveModel
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
        - in: path
          name: model_name
          schema:
            type: string
          required: true
      responses:
        200:
          description: Result of setting a new active model
          content:
            application/json:
              schema:
                type: object
                properties:
                  unloaded_models:
                    type: array
                    items:
                      type: string
                  model_set:
                    type: string
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/evaluations:
    get:
      tags:
        - Evaluations
      summary: Get model evaluations
      operationId: getEvaluations
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      responses:
        200:
          description: Model evaluations
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    project_id:
                      type: string
                    model:
                      type: string
                    intent_evaluation:
                      type: object
                      $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/evaluations/{model}:
    put:
      tags:
        - Evaluations
      summary: Start a model evaluation
      operationId: startEvaluation
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
        - in: path
          name: model
          schema:
            type: string
          required: true
      responses:
        200:
          description: Model evaluation
          content:
            application/json:
              schema:
                type: object
                properties:
                  intent_evaluation:
                    type: object
                    $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'
    get:
      tags:
        - Evaluations
      summary: Retrieve a model evaluation
      operationId: getEvaluation
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
        - in: path
          name: model
          schema:
            type: string
          required: true
      responses:
        200:
          description: Model evaluation
          content:
            application/json:
              schema:
                type: object
                properties:
                  intent_evaluation:
                    type: object
                    $ref: '#/components/schemas/EvaluationResult'
        401:
          $ref: '#/components/responses/UnauthorizedError'
        404:
          description: Evaluation result could not be found
    delete:
      tags:
        - Evaluations
      summary: Delete a model evaluation
      operationId: deleteEvaluation
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
        - in: path
          name: model
          schema:
            type: string
          required: true
      responses:
        204:
          description: Deleted model evaluation
          content:
            text/plain:
              schema:
                type: string
        401:
          $ref: '#/components/responses/UnauthorizedError'
  /projects/{project_id}/settings:
    get:
      tags:
        - Settings
      summary: Fetch NLU config
      operationId: getConfig
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      responses:
        200:
          description: Configuration of NLU
          content:
            application/json:
              schema:
                type: object
                properties:
                  nlu_config:
                    description: YAML string
                    type: string
        400:
          description: could not find settings
        401:
          $ref: '#/components/responses/UnauthorizedError'
    put:
      tags:
        - Settings
      summary: Save NLU config
      operationId: saveConfig
      parameters:
        - in: path
          name: project_id
          schema:
            type: string
          required: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                nlu_config:
                  description: YAML string
                  type: string
      responses:
        200:
          description: Saved configuration of NLU
          content:
            application/json:
              schema:
                type: object
                properties:
                  nlu_config:
                    description: YAML string
                    type: string
        400:
          description: could not find settings
        401:
          $ref: '#/components/responses/UnauthorizedError'
security:
  - bearerAuth: []
components:
  responses:
    UnauthorizedError:
      description: Access token is missing or invalid
      content:
        application/json:
          schema:
            type: object
            properties:
              exception:
                type: string
              reasons:
                oneOf:
                  - type: string
                  - type: array
                    items:
                      type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Project:
      type: object
      properties:
        project_id:
          type: string
        role:
          type: string
    Suggestion:
      type: object
      properties:
        user_input:
          type: object
          properties:
            text:
              type: string
            intent:
              type: object
              properties:
                name:
                  type: string
                confidence:
                  type: number
            entities:
              type: array
              items:
                type: object
        project_id:
          type: string
        model:
          type: string
        time:
          type: number
        team:
          type: string
    EvaluationResult:
      type: object
      properties:
        report:
          type: string
        f1_score:
          type: integer
        accuracy:
          type: integer
        predictions:
          type: array
          items:
            type: object
            properties:
              text:
                type: string
              confidence:
                type: integer
              intent:
                type: string
              predicted:
                type: string
        precision:
          type: integer
