Skip to content

Commit

Permalink
refactor: Enhance JSDoc
Browse files Browse the repository at this point in the history
This commit enhances the type definitions by adding JSDoc comments and
using typia's tags for more precise types. It also updates the
documentation to reflect these changes, improving the clarity and
understanding of the code.
  • Loading branch information
ryoppippi committed Aug 8, 2024
1 parent d2cd075 commit 6a0b5d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ Converts JSON Schema generated by Typia to OpenAI ResponseFormat for [Structured
```ts

import { typiaJsonToOpenAIResponse } from "@ryoppippi/typiautil/openai";
import typia from "typia";
import typia, { tags } from "typia";
import OpenAI from "openai";

/** add description as a JSDoc */
type Output = {
id: string;
name: string;
/** id of the entity */
id: string & tags.Type<'uint32'>;

/** name of the entity */
name: string & tags.MinLength<1>;
}

const client = new OpenAI({})
Expand Down
32 changes: 18 additions & 14 deletions openai/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ export function typiaJsonToOpenAIJsonSchema(
* import typia from "typia";
* import OpenAI from "openai";
*
* /** add description as a JSDoc \*\/
* type Output = {
* id: string;
* name: string;
* /** id of the entity \*\/
* id: string & tags.Type<'uint32'>;
*
* /** name of the entity \*\/
* name: string & tags.MinLength<1>;
* }
*
* const client = new OpenAI({})
* const client = new OpenAI({})
*
* const jsonSchema = typia.json.application<[Output]>();
* const chat = await client.chat.completions.create({
* model: "gpt-4o-mini",
* response_format: typiaJsonToOpenAIResponse({ jsonSchema }),
* messages: [
* {
* role: "system",
* content: "Extract information and return as the structured data following schema",
* },
* ],
* });
* const jsonSchema = typia.json.application<[Output]>();
* const chat = await client.chat.completions.create({
* model: "gpt-4o-mini",
* response_format: typiaJsonToOpenAIResponse({ jsonSchema }),
* messages: [
* {
* role: "system",
* content: "Extract information and return as the structured data following schema",
* },
* ],
* });
* ```
*/
export function typiaJsonToOpenAIResponse(
Expand Down

0 comments on commit 6a0b5d0

Please sign in to comment.