Function Calling - Returns The Array Enum String

I’m using the GPT function call to extract some of the parameters I want, but it’s not working properly when I’m using array type with enum string.
My JSON schema looks like this:

    parameters: {
      type: "object",
      properties: {
        projects: {
          type: "array",
          description: "the project information list extracted from the mail text",
          items: {
            type: "object",
            properties: {
              category: {
                type: "array",
                items: {
                  type: "string",
                  enum: %w[WEB/オープン系アプリケーション 汎用系 ネイティブアプリ 制御、組込系 データベース ネットワーク サーバー セキュリティ 社内SE RPA SAP AI・機械学習 データアナリスト その他],
                }
              },
              workspace: {
                type: "array",
                items: {
                  type: "string",
                  enum: %w[ITコンサル ITアーキテクト PM/PMO ウェブディレクター プロダクトマネージャー システム要件定義 システム基本設計 システム詳細設計 システム開発 システム運用、保守 バックエンド開発 フロントエンド開発 QA、テスト インフラ設計、構築 インフラ運用、保守 テクニカルサポート・ヘルプデスク データ収集、加工、分析 プリセールス・セールスエンジニア その他]
                }
              }
            }
          }
        }
      },
      required: %w[projects]
    }

Is there something wrong with the schema I wrote? Or does GPT not currently support that?
output:
JSON.parse(resp.dig("choices", 0, "message", "function_call", "arguments"))

    "category"=>"制御、組込系",
    "workspace"=>"システム要件定義",

How many enum do you want to have?
There are not many commas (,) so the string looks very long. Very long text confuses me and the AI.
Also, each string needs quotes (").

This is what ChatGPT thinks are your enum options:

"enum": [
    "ITコンサル",
    "ITアーキテクト",
    "PM/PMO",
    "ウェブディレクター",
    "プロダクトマネージャー",
    "システム要件定義",
    "システム基本設計",
    "システム詳細設計",
    "システム開発",
    "システム運用、保守",
    "バックエンド開発",
    "フロントエンド開発",
    "QA、テスト",
    "インフラ設計、構築",
    "インフラ運用、保守",
    "テクニカルサポート・ヘルプデスク",
    "データ収集、加工、分析",
    "プリセールス・セールスエンジニア",
    "その他"
]

I want GPT to return at least one of the enum strings based on the semantics of the email text,

%w[WEB/オープン系アプリケーション 汎用系 ネイティブアプリ 制御、組込系 データベース ネットワーク サーバー セキュリティ 社内SE RPA SAP AI・機械学習 データアナリスト その他]

This is Ruby’s short form for array, which is actually equal to
["WEB/オープン系アプリケーション", "汎用系", "ネイティブアプリ", "制御、組込系", "データベース", "ネットワーク", "サーバー", "セキュリティ", "社内SE", "RPA", "SAP", "AI・機械学習", "データアナリスト", "その他"]

The important part is how your input becomes the language that the GPT AI can see.
The API expects to see a particular object type, and then that is re-written for the AI.

enum should be sent in a form which python can understand, because the examples from OpenAI are like python.

The API performs translation from the JSON object to a special encoding. What the AI actually sees:

items?: "WEB/オープン系アプリケーション" | "汎用系" | "ネイティブアプリ" | "制御 | 組込系" | "データベース", "ネッ....

In the enum, you have some double-width Japanese spaces and some single-width narrow spaces. You can try replacing all spaces with English spaces " ". This will ensure the API doesn’t have problems.

Function parameters can also have a description in the object. This will tell the AI how to choose which enum.

If the system message and document are always Japanese, I think the function description would be best in Japanese also.

category: {
                type: "array",
                items: {
                  type: "string",
                  enum: ["WEB/オープン系....],
                }

Above, you don’t need a items array inside workspace. You make an array, but an array is not necessary. The AI will only return one enum. At the second level sub-array, you can’t use a description either.

This is typical:

“職務の説明”: {
“type”: “string”,
“enum”: [“…”],
“description”: “文書に表示されている最適な職務の説明を選んでください。”,
},

Good luck. If the long enum still is a problem (which is longer and more AI tokens in Japanese than English words tokens), you may to give up on that idea. Just use “string” and let the AI write the job description type that it wants. Then another classification AI call could choose the best enum from a list.

1 Like