Skip to content

Commit

Permalink
Merge pull request #125 from samchon/feat/separate
Browse files Browse the repository at this point in the history
`ILlmFunction.ISeparated.llm` to be not null.
  • Loading branch information
samchon authored Jan 13, 2025
2 parents 0d31c4f + 04d3073 commit 3c4d258
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/composers/llm/ChatGptSchemaComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ export namespace ChatGptSchemaComposer {
});
if (llm === null || human === null)
return {
llm: llm as IChatGptSchema.IParameters | null,
llm: (llm as IChatGptSchema.IParameters | null) ?? {
type: "object",
properties: {} as Record<string, IChatGptSchema>,
required: [],
additionalProperties: false,
$defs: {},
},
human: human as IChatGptSchema.IParameters | null,
};
const output: ILlmFunction.ISeparated<"chatgpt"> = {
Expand Down
9 changes: 5 additions & 4 deletions src/composers/llm/ClaudeSchemaComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export namespace ClaudeSchemaComposer {
export const separateParameters = (props: {
predicate: (schema: IClaudeSchema) => boolean;
parameters: IClaudeSchema.IParameters;
}): ILlmFunction.ISeparated<"claude"> =>
LlmSchemaV3_1Composer.separateParameters(
props,
) as any as ILlmFunction.ISeparated<"claude">;
}): ILlmFunction.ISeparated<"claude"> => {
const separated: ILlmFunction.ISeparated<"3.1"> =
LlmSchemaV3_1Composer.separateParameters(props);
return separated as any as ILlmFunction.ISeparated<"claude">;
};
}
17 changes: 10 additions & 7 deletions src/composers/llm/GeminiSchemaComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ export namespace GeminiSchemaComposer {
export const separateParameters = (props: {
predicate: (schema: IGeminiSchema) => boolean;
parameters: IGeminiSchema.IParameters;
}): ILlmFunction.ISeparated<"gemini"> =>
LlmSchemaV3Composer.separateParameters(
props as {
predicate: (schema: ILlmSchemaV3) => boolean;
parameters: ILlmSchemaV3.IParameters;
},
) as any as ILlmFunction.ISeparated<"gemini">;
}): ILlmFunction.ISeparated<"gemini"> => {
const separated: ILlmFunction.ISeparated<"3.0"> =
LlmSchemaV3Composer.separateParameters(
props as {
predicate: (schema: ILlmSchemaV3) => boolean;
parameters: ILlmSchemaV3.IParameters;
},
);
return separated as any as ILlmFunction.ISeparated<"gemini">;
};
}

const isOneOf =
Expand Down
10 changes: 9 additions & 1 deletion src/composers/llm/LlmSchemaV3Composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ export namespace LlmSchemaV3Composer {
predicate: props.predicate,
schema: props.parameters,
});
return { llm, human } as ILlmFunction.ISeparated<"3.0">;
return {
llm: (llm as ILlmSchemaV3.IParameters | null) ?? {
type: "object",
properties: {},
additionalProperties: false,
required: [],
},
human: human as ILlmSchemaV3.IParameters | null,
};
};

const separateStation = (props: {
Expand Down
8 changes: 7 additions & 1 deletion src/composers/llm/LlmSchemaV3_1Composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ export namespace LlmSchemaV3_1Composer {
});
if (llm === null || human === null)
return {
llm: llm as ILlmSchemaV3_1.IParameters | null,
llm: (llm as ILlmSchemaV3_1.IParameters | null) ?? {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: human as ILlmSchemaV3_1.IParameters | null,
};
const output: ILlmFunction.ISeparated<"3.1"> = {
Expand Down
5 changes: 4 additions & 1 deletion src/structures/IHttpLlmFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ export namespace IHttpLlmFunction {
export interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*
* Even though no property exists in the LLM side, the `llm` property
* would have at least empty object type.
*/
llm: ILlmSchema.ModelParameters[Model] | null;
llm: ILlmSchema.ModelParameters[Model];

/**
* Parameters that would be composed by the human.
Expand Down
5 changes: 4 additions & 1 deletion src/structures/ILlmFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ export namespace ILlmFunction {
export interface ISeparated<Model extends ILlmSchema.Model> {
/**
* Parameters that would be composed by the LLM.
*
* Even though no property exists in the LLM side, the `llm` property
* would have at least empty object type.
*/
llm: ILlmSchema.ModelParameters[Model] | null;
llm: ILlmSchema.ModelParameters[Model];

/**
* Parameters that would be composed by the human.
Expand Down
8 changes: 7 additions & 1 deletion test/features/llm/validate_llm_parameters_separate_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ const validate_llm_parameters_separate_array = <Model extends ILlmSchema.Model>(
human: null,
});
TestValidator.equals("upload")(separator(upload))({
llm: null,
llm: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: upload,
});
TestValidator.equals("combined")(separator(combined))({
Expand Down
8 changes: 7 additions & 1 deletion test/features/llm/validate_llm_parameters_separate_nested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ const validate_llm_parameters_separate_nested = <
human: null,
});
TestValidator.equals("upload")(separator(upload))({
llm: null,
llm: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: upload,
});
TestValidator.equals("combined")(separator(combined))({
Expand Down
8 changes: 7 additions & 1 deletion test/features/llm/validate_llm_parameters_separate_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ const validate_llm_parameters_separate_object = <
human: null,
});
TestValidator.equals("upload")(separator(upload))({
llm: null,
llm: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: upload,
});
TestValidator.equals("combined")(separator(combined))({
Expand Down
8 changes: 7 additions & 1 deletion test/features/llm/validate_llm_parameters_separate_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const validate_llm_parameters_separate_ref = <
human: null,
});
TestValidator.equals("upload")(separator(upload))({
llm: null,
llm: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: upload,
});
TestValidator.equals("combined")({
Expand Down
8 changes: 7 additions & 1 deletion test/features/llm/validate_llm_schema_separate_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ const validate_llm_schema_separate_string = <Model extends ILlmSchema.Model>(
human: null,
});
TestValidator.equals("upload")(separator(upload))({
llm: null,
llm: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {},
},
human: upload,
});
};
Expand Down

0 comments on commit 3c4d258

Please sign in to comment.