Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additionalProperties in Claude and Llama schemas. #1394

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "7.0.0-dev.20241127-6",
"version": "7.0.0-dev.20241128",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -41,7 +41,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"@samchon/openapi": "2.0.0-dev.20241127-2",
"@samchon/openapi": "^2.0.0-dev.20241128",
"commander": "^10.0.0",
"comment-json": "^4.2.3",
"inquirer": "^8.2.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "7.0.0-dev.20241127-6",
"version": "7.0.0-dev.20241128",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "7.0.0-dev.20241127-6"
"typia": "7.0.0-dev.20241128"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.7.0"
Expand Down
56 changes: 55 additions & 1 deletion src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
* humand and LLM sides' parameters into one through {@link HttpLlm.mergeParameters}
* before the actual LLM function call execution.
*
* Here is the list of available `Model` types with their corresponding LLM schema.
* Reading the following list, and determine the `Model` type considering the
* characteristics of the target LLM provider.
*
* - LLM provider schemas
* - `chatgpt`: [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
* - `claude`: [`IClaudeSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IClaudeSchema.ts)
* - `gemini`: [`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts)
* - `llama`: [`ILlamaSchema`](https://github.com/samchon/openapi/blob/master/src/structures/ILlamaSchema.ts)
* - Midldle layer schemas
* - `3.0`: [`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts)
* - `3.1`: [`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts)
*
* @template App Target class or interface type collecting the functions to call
* @template Model LLM schema model
* @template Config Configuration of LLM schema composition
Expand Down Expand Up @@ -74,6 +87,19 @@ export function application(
* humand and LLM sides' parameters into one through {@link HttpLlm.mergeParameters}
* before the actual LLM function call execution.
*
* Here is the list of available `Model` types with their corresponding LLM schema.
* Reading the following list, and determine the `Model` type considering the
* characteristics of the target LLM provider.
*
* - LLM provider schemas
* - `chatgpt`: [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
* - `claude`: [`IClaudeSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IClaudeSchema.ts)
* - `gemini`: [`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts)
* - `llama`: [`ILlamaSchema`](https://github.com/samchon/openapi/blob/master/src/structures/ILlamaSchema.ts)
* - Midldle layer schemas
* - `3.0`: [`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts)
* - `3.1`: [`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts)
*
* @template App Target class or interface type collecting the functions to call
* @template Model LLM schema model
* @template Config Configuration of LLM schema composition
Expand Down Expand Up @@ -117,6 +143,19 @@ export function application(): never {
* text, by filling the parameters from the conversation (maybe chatting text) with user
* (human).
*
* Here is the list of available `Model` types with their corresponding LLM schema.
* Reading the following list, and determine the `Model` type considering the
* characteristics of the target LLM provider.
*
* - LLM provider schemas
* - `chatgpt`: [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
* - `claude`: [`IClaudeSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IClaudeSchema.ts)
* - `gemini`: [`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts)
* - `llama`: [`ILlamaSchema`](https://github.com/samchon/openapi/blob/master/src/structures/ILlamaSchema.ts)
* - Midldle layer schemas
* - `3.0`: [`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts)
* - `3.1`: [`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts)
*
* @template Parameters Target parameters type
* @template Model LLM schema model
* @template Config Configuration of LLM schema composition
Expand Down Expand Up @@ -144,6 +183,19 @@ export function parameters(): never;
* text, by filling the parameters from the conversation (maybe chatting text) with user
* (human).
*
* Here is the list of available `Model` types with their corresponding LLM schema.
* Reading the following list, and determine the `Model` type considering the
* characteristics of the target LLM provider.
*
* - LLM provider schemas
* - `chatgpt`: [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
* - `claude`: [`IClaudeSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IClaudeSchema.ts)
* - `gemini`: [`IGeminiSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IGeminiSchema.ts)
* - `llama`: [`ILlamaSchema`](https://github.com/samchon/openapi/blob/master/src/structures/ILlamaSchema.ts)
* - Midldle layer schemas
* - `3.0`: [`ILlmSchemaV3`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3.ts)
* - `3.1`: [`ILlmSchemaV3_1`](https://github.com/samchon/openapi/blob/master/src/structures/ILlmSchemaV3_1.ts)
*
* @template Parameters Target parameters type
* @template Model LLM schema model
* @template Config Configuration of LLM schema composition
Expand Down Expand Up @@ -174,7 +226,9 @@ export function parameters(): never {
* from a TypeScript type.
*
* The returned {@link ILlmSchema} type would be specified by the `Model` argument,
* and here is the list of available `Model` types with their corresponding LLM schema:
* and here is the list of available `Model` types with their corresponding LLM schema.
* Reading the following list, and determine the `Model` type considering the
* characteristics of the target LLM provider.
*
* - LLM provider schemas
* - `chatgpt`: [`IChatGptSchema`](https://github.com/samchon/openapi/blob/master/src/structures/IChatGptSchema.ts)
Expand Down
4 changes: 3 additions & 1 deletion src/programmers/llm/LlmApplicationProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export namespace LlmApplicationProgrammer {
const object: MetadataObjectType | undefined = metadata.objects[0]?.type;
if (object !== undefined) {
if (object.properties.some((p) => p.key.isSoleLiteral() === false))
output.push("LLM application does not allow dynamic keys.");
output.push(
"LLM application does not allow dynamic keys on class/interface type.",
);
let least: boolean = false;
for (const p of object.properties) {
const value: Metadata = p.value;
Expand Down
5 changes: 4 additions & 1 deletion src/programmers/llm/LlmSchemaProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ export namespace LlmSchemaProgrammer {
)
output.push("LLM schema does not support bigint type.");
if (
(model === "chatgpt" || model === "gemini") &&
metadata.objects.some((o) =>
o.type.properties.some(
(p) => p.key.isSoleLiteral() === false && p.value.size() !== 0,
),
)
)
output.push("LLM schema does not support dynamic property in object.");
output.push(
`LLM schema of "${model}" does not support dynamic property in object.`,
);
if (
metadata.tuples.some((t) =>
t.type.elements.some((e) => e.isRequired() === false),
Expand Down
7 changes: 4 additions & 3 deletions test/build/internal/TestLlmApplicationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export namespace TestLlmApplicationGenerator {
"utf8",
);
if (
v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true ||
v31.includes(`"prefixItems":`) === true
(model === "chatgpt" || model === "gemini") &&
(v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true)
)
continue;
else if (v31.includes(`"prefixItems":`) === true) continue;
else if (model === "gemini") {
// GEMINI DOES NOT SUPPORT UNION TYPE
const json: string = await fs.promises.readFile(
Expand Down
7 changes: 4 additions & 3 deletions test/build/internal/TestLlmParametersGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export namespace TestLlmParametersGenerator {
"utf8",
);
if (
v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true ||
v31.includes(`"prefixItems":`) === true
(model === "chatgpt" || model === "gemini") &&
(v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true)
)
continue;
else if (v31.includes(`"prefixItems":`) === true) continue;
else if (model === "gemini") {
// GEMINI DOES NOT SUPPORT UNION TYPE
const json: string = await fs.promises.readFile(
Expand Down
7 changes: 4 additions & 3 deletions test/build/internal/TestLlmSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export namespace TestLlmSchemaGenerator {
"utf8",
);
if (
v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true ||
v31.includes(`"prefixItems":`) === true
(model === "chatgpt" || model === "gemini") &&
(v31.includes(`"additionalProperties": {`) === true ||
v31.includes(`"additionalProperties": true`) === true)
)
continue;
else if (v31.includes(`"prefixItems":`) === true) continue;
else if (model === "gemini") {
// GEMINI DOES NOT SUPPORT UNION TYPE
const json: string = await fs.promises.readFile(
Expand Down
25 changes: 0 additions & 25 deletions test/generate/output/generate_llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export const parameters = {
},
},
required: ["id", "serial", "name", "established_at", "departments"],
additionalProperties: false,
},
department: {
$ref: "#/$defs/IDepartment",
Expand All @@ -146,11 +145,9 @@ export const parameters = {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
required: ["company", "department", "employee"],
additionalProperties: false,
$defs: {
IDepartment: {
type: "object",
Expand Down Expand Up @@ -199,12 +196,10 @@ export const parameters = {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
},
required: ["id", "code", "sales", "created_at", "children", "employees"],
additionalProperties: false,
},
},
} as __ILlmSchema.IParameters<"claude">;
Expand Down Expand Up @@ -255,11 +250,9 @@ export const application = (() => {
"established_at",
"departments",
],
additionalProperties: false,
},
},
required: ["company"],
additionalProperties: false,
},
},
required: ["props"],
Expand Down Expand Up @@ -312,7 +305,6 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
},
Expand All @@ -324,7 +316,6 @@ export const application = (() => {
"children",
"employees",
],
additionalProperties: false,
},
},
},
Expand Down Expand Up @@ -353,7 +344,6 @@ export const application = (() => {
},
},
required: ["id", "serial", "name", "established_at", "departments"],
additionalProperties: false,
},
strict: true,
},
Expand Down Expand Up @@ -396,14 +386,12 @@ export const application = (() => {
"established_at",
"departments",
],
additionalProperties: false,
},
department: {
$ref: "#/$defs/IDepartment",
},
},
required: ["company", "department"],
additionalProperties: false,
},
},
required: ["props"],
Expand Down Expand Up @@ -456,7 +444,6 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
},
Expand All @@ -468,7 +455,6 @@ export const application = (() => {
"children",
"employees",
],
additionalProperties: false,
},
},
},
Expand Down Expand Up @@ -516,7 +502,6 @@ export const application = (() => {
"established_at",
"departments",
],
additionalProperties: false,
},
department: {
$ref: "#/$defs/IDepartment",
Expand All @@ -543,11 +528,9 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
required: ["company", "department", "employee"],
additionalProperties: false,
},
},
required: ["props"],
Expand Down Expand Up @@ -600,7 +583,6 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
},
Expand All @@ -612,7 +594,6 @@ export const application = (() => {
"children",
"employees",
],
additionalProperties: false,
},
},
},
Expand All @@ -638,7 +619,6 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
strict: true,
},
Expand Down Expand Up @@ -683,7 +663,6 @@ export const application = (() => {
"established_at",
"departments",
],
additionalProperties: false,
},
{
$ref: "#/$defs/IDepartment",
Expand All @@ -710,13 +689,11 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
],
},
},
required: ["entity"],
additionalProperties: false,
},
},
required: ["props"],
Expand Down Expand Up @@ -769,7 +746,6 @@ export const application = (() => {
},
},
required: ["id", "name", "age", "grade", "employeed_at"],
additionalProperties: false,
},
},
},
Expand All @@ -781,7 +757,6 @@ export const application = (() => {
"children",
"employees",
],
additionalProperties: false,
},
},
},
Expand Down
1 change: 0 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@types/cli": "^0.11.25",
"@types/node": "^20.9.4",
"@types/uuid": "^9.0.7",
"@wrtnio/schema": "^2.0.0-dev.20241127-3",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
Expand Down
Loading