dotCMS / dotCMS/core

Implement `dotAIService` Method for Structured Outputs with Strong typing

Open
#31,473 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Team : Falcon Type : Task
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Parent Issue

#31332

Description

A new method should be added to dotAIService to interact with the OpenAI API’s Structured Outputs endpoint, ensuring type safety and schema validation.

Example
Image
Implementation
const mySchema = z
  .object({
    myString: z.string().min(5),
    myUnion: z.union([z.number(), z.boolean()]),
    myOptions: z.enum(["Salmon", "Tuna", "Trout"])
  })
  .describe("My neat object schema");

this.dotAiService.structuredOutput({
   prompt: "---"
   schema: mySchema
})
Task
Requirements:
  1. Zod for Strong Typing:

    • Use zod to define the schema, ensuring strong typing.
    • Convert the zod schema to a standard JSON schema using zod-to-json-schema to prevent invalid schemas and typos.
Image

Even Zod is the official library in the JavaScript SDK for handling schemas

  1. Handling OpenAI API Responses:

    • The method should correctly send requests using the generated JSON schema.
    • It must handle cases where OpenAI returns a refusal response:
      • If OpenAI refuses the request due to safety reasons, the API response will include a refusal field that does not conform to the provided schema.
      • The method should gracefully handle this case by properly detecting and processing refusals.
Image
  1. Validation and Error Handling:

    • Validate input data against the zod schema before sending the request.
    • Ensure that any unexpected response formats are handled appropriately.
References:
Proposed Objective

Core Features

Proposed Priority

Priority 3 - Average

Acceptance Criteria

Acceptance Criteria

  • [ ] A new method in dotAIService is implemented.
  • [ ] The method uses zod for schema validation and zod-to-json-schema for conversion.
  • [ ] The method correctly processes API responses, including handling refusal cases.
  • [ ] Unit tests cover valid and refusal responses.
External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin by locating the dotAIService entry point and reviewing parent issue #31332 alongside the linked Structured Outputs documentation. Done means the new method validates Zod schemas, handles valid and refusal responses, and has unit tests covering both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.