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}/models/nlu:
    get:
      tags:
      - Models
      summary: Get NLU models
      operationId: getModels
      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: Model list
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Model'
        401:
          $ref: '#/components/responses/UnauthorizedError'
    post:
      tags:
      - Models
      summary: Upload a zipped Rasa NLU model
      parameters:
      - in: path
        name: project_id
        schema:
          type: string
        required: true
      - in: formData
        name: upfile
        schema:
          type: file
        description: The file to upload.
      responses:
        204:
          description: Upload OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No model found
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/jobs:
    post:
      tags:
      - Jobs, Model
      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'


  /projects/{project_id}/models/nlu/tags/{tag}:
    get:
      tags:
      - model
      summary: Get a Rasa NLU model with tag
      parameters:
      - in: path
        name: project_id
        schema:
          type: string
        required: true
      - in: query
        name: tag
        description: Tag to fetch
        schema:
          type: string
        required: true
      responses:
        200:
          description: Zipped Rasa NLU model
          content:
            application/octet-stream:
              schema:
                type: string
        404:
          description: No model found for tag
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/{model}:
    delete:
      tags:
      - model
      summary: Delete a Rasa NLU model
      parameters:
      - in: path
        name: project_id
        schema:
          type: string
        required: true
      - in: path
        name: model
        schema:
          type: string
        required: true
      responses:
        204:
          description: Delete OK
          content:
            text/plain:
              schema:
                type: string
        404:
          description: Model could not be deleted
        401:
          $ref: '#/components/responses/UnauthorizedError'

  /projects/{project_id}/models/nlu/{model}/tags/{tag}:
    put:
      tags:
      - model
      summary: Tag a Rasa NLU model
      parameters:
      - in: path
        name: project_id
        schema:
          type: string
        required: true
      - in: path
        name: model
        schema:
          type: string
        required: true
      - in: path
        name: tag
        schema:
          type: string
        required: true
      responses:
        200:
          description: Tag created on model
          content:
            text/plain:
              schema:
                type: string
        404:
          description: No tag found
        401:
          $ref: '#/components/responses/UnauthorizedError'
    delete:
      tags:
      - model
      summary: Delete a tag of a Rasa NLU model
      parameters:
      - in: path
        name: project_id
        schema:
          type: string
        required: true
      - in: path
        name: model
        schema:
          type: string
        required: true
      - in: path
        name: tag
        description: Tag to be deleted
        schema:
          type: string
        required: true
      responses:
        204:
          description: Deleted OK
          content:
            text/plain:
              schema:
                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:
    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
    Model:
      type: object
      properties:
        project:
          type: string
        model:
          type: string
        path:
          type: string
        hash:
          type: string
        tags:
          type: array
          items:
            type: string
        timestamp:
          type: number
        version:
          type: string
