Skip to main content
OpenAIのGPTsについて詳しくはこちらをご覧ください。

チャットボットアプリの作成

1

APIキーの発行

Python SDKからQAIPにアクセスするためのAPIキーを発行します。
詳しくはこちらをご参照ください。
2

新規GPTの作成

GPT Editorで新規にGPTを作成する
  • 「構成」タブをクリックしてGPTの設定パネルを表示
  • 「名前」にGPT名を入力する
  • 「指示」に適当な内容を入力する
指示の例
このGPTは提供されたAPIの "/search" と "/tags" を使用して、ユーザーからの質問・問い合わせに回答します。

### 検索クエリの最適化
- ユーザーの入力を分析し、適切な検索クエリに変換します。
- 関連キーワードの追加や同義語展開を行い、検索結果の精度を向上させます。

### 検索範囲の調整
- タグ一覧APIを使用して、関連するタグを取得します。
- ユーザーの質問内容に基づいて、関連性の高いタグを選択し、検索APIに渡します。
- デフォルトの `limit` 値を 20 に設定し、検索範囲を広げます。
- 目的の情報が得られなかった場合、最大 50 まで増やして再検索します。

### 再検索の戦略改善
- 目的の情報が見つからなかった場合、クエリを変更して再試行します。
- 例えば「製品名」だけで見つからなければ「製品名 + マニュアル」などのパターンを自動調整します。

このように検索戦略を最適化し、より目的の情報を取得しやすくします。
3

アクションの追加

  • 「GPT Editor」の「新しいアクションを作成する」ボタンをクリック
  • 「アクションを追加する」画面で認証欄をクリック
  • 認証ダイアログで認証タイプの「APIキー」を選択
  • 「APIキー」に「1. APIキーを作成」で作成したAPIキーを入力
  • 「認証タイプ」の「カスタム」をクリック
  • 「カスタムヘッダーの名前」に x-api-key を入力
  • 「保存する」ボタンをクリック
4

スキーマの設定

  • スキーマ欄に下記のOpenAPI Specificationをコピー・ペーストする
OpenAPI Specification
openapi: 3.1.0
info:
  title: QAIP APIs
  version: 1.0.0
servers:
  - url: https://developer.qaip.com/api/v1
    description: LLM API base path
tags:
  - name: search
    description: Search content from vectordb
paths:
  /search:
    post:
      summary: Search content
      description: Searches through indexed content using query
      tags:
        - search
      operationId: search
      security:
        - ApiKeyAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - query
              properties:
                query:
                  type: string
                  description: Search query string
                  example: "machine learning and artificial intelligence"
                tags:
                  type: array
                  description: target tag names to be obtained
                  items:
                    type: string
                tag_ids:
                  type: array
                  description: target tag IDs to be obtained
                  items:
                    type: string
                source_types:
                  type: array
                  items:
                    $ref: "#/components/schemas/SourceType"
                file_types:
                  type: array
                  items:
                    $ref: "#/components/schemas/FileType"
                date_from:
                  type: integer
                  description: Start date for content search (Unix timestamp in seconds)
                  example: 1735639200
                  minimum: 1735639200
                date_to:
                  type: integer
                  description: End date for content search (Unix timestamp in seconds)
                  example: 1735639200
                  minimum: 1735639200
                domains:
                  type: array
                  description: Array of domains to search within (supports partial matching)
                  items:
                    type: string
                  example: ["example.com", "blog.example.com"]
                limit:
                  type: integer
                  description: Maximum number of results to return
                  minimum: 1
                  maximum: 100
                  default: 10
                  example: 10
                offset:
                  type: integer
                  description: Number of results to skip
                  minimum: 0
                  default: 0
                  example: 0
      responses:
        "200":
          description: Successful search results
          content:
            application/json:
              schema:
                type: object
                required:
                  - id
                  - created
                  - results
                properties:
                  id:
                    type: string
                    description: A unique identifier for the search request
                    example: "0e157726-bf16-458a-9ef4-8332a344318b"
                  created:
                    type: integer
                    description: The Unix timestamp (in seconds) of when the search was performed
                    example: 1677649420
                  results:
                    type: array
                    description: Array of search results
                    items:
                      $ref: "#/components/schemas/Content"
        "400":
          description: Bad Request - The request was malformed or invalid
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Unauthorized - Authentication failed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: Forbidden - Insufficient permissions
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "429":
          description: Too Many Requests - Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /tags:
    get:
      summary: List tags
      description: Returns the list of tags
      tags:
        - tags
      operationId: listTags
      security:
        - ApiKeyAuth: []
      responses:
        "200":
          description: Successful retrieval of tags
          content:
            application/json:
              schema:
                type: object
                properties:
                  tags:
                    type: array
                    items:
                      $ref: "#/components/schemas/Tag"
        "400":
          description: Bad Request - The request was malformed or invalid
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Unauthorized - Authentication failed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: Forbidden - Insufficient permissions
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "429":
          description: Too Many Requests - Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "500":
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Tag:
      type: object
      required:
        - id
        - name
        - description
      properties:
        id:
          type: string
          description: Tag ID
        name:
          type: string
          description: Tag name
        description:
          type: string
          description: Tag description
    FileType:
      type: string
      description: The type of the source file
      enum:
        - html
        - pdf
        - ppt
        - pptx
        - pptm
        - doc
        - docx
        - docm
        - xls
        - xlsx
        - xlsm
        - md
        - txt
        - notion_page
    SourceType:
      type: string
      description: The type of the source
      enum:
        - crawl
        - local_file
        - google_drive
        - github
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
              description: Human-readable error message
            type:
              type: string
              description: Machine-readable error code
    Content:
      type: object
      required:
        - id
        - text
        - url
        - timestamp
        - file_type
        - page_number
      properties:
        id:
          type: string
          description: Content ID
        text:
          type: string
          description: Content chunk from the source
        url:
          type: string
          description: Source URL of the content
        timestamp:
          type: integer
          description: Unix timestamp when the content was indexed
        file_type:
          $ref: "#/components/schemas/FileType"
        page_number:
          type: integer
          description: Page number for paginated documents like PDFs. Set to 0 for sources without page numbers
          default: 0
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for authentication

security:
  - ApiKeyAuth: []
5

実行してみる

実際にメッセージを打ち込んで回答が返ってきたら成功です🎉