-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from samchon/doc/README
Re-write README document.
- Loading branch information
Showing
6 changed files
with
568 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
HttpLlm, | ||
IHttpLlmApplication, | ||
IHttpLlmFunction, | ||
OpenApi, | ||
OpenApiV3, | ||
OpenApiV3_1, | ||
SwaggerV2, | ||
} from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
|
||
const main = async (): Promise<void> => { | ||
// read swagger document and validate it | ||
const swagger: | ||
| SwaggerV2.IDocument | ||
| OpenApiV3.IDocument | ||
| OpenApiV3_1.IDocument = JSON.parse( | ||
await fs.promises.readFile("swagger.json", "utf8"), | ||
); | ||
typia.assert(swagger); | ||
|
||
// convert to emended OpenAPI document, | ||
// and compose LLM function calling application | ||
const document: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const application: IHttpLlmApplication = HttpLlm.application(document); | ||
|
||
// Let's imagine that LLM has selected a function to call | ||
const func: IHttpLlmFunction | undefined = application.functions.find( | ||
(f) => f.path === "/bbs/articles" && f.method === "post", | ||
); | ||
typia.assertGuard<IHttpLlmFunction>(func); | ||
|
||
// actual execution is by yourself | ||
const article = await HttpLlm.execute({ | ||
connection: { | ||
host: "http://localhost:3000", | ||
}, | ||
application, | ||
function: func, | ||
arguments: [ | ||
"general", | ||
{ | ||
title: "Hello, world!", | ||
body: "Let's imagine that this argument is composed by LLM.", | ||
}, | ||
], | ||
}); | ||
console.log("article", article); | ||
}; | ||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
HttpLlm, | ||
IHttpLlmApplication, | ||
IHttpLlmFunction, | ||
OpenApi, | ||
OpenApiV3, | ||
OpenApiV3_1, | ||
SwaggerV2, | ||
} from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
import { v4 } from "uuid"; | ||
|
||
const main = async (): Promise<void> => { | ||
// read swagger document and validate it | ||
const swagger: | ||
| SwaggerV2.IDocument | ||
| OpenApiV3.IDocument | ||
| OpenApiV3_1.IDocument = JSON.parse( | ||
await fs.promises.readFile("swagger.json", "utf8"), | ||
); | ||
typia.assert(swagger); // recommended | ||
|
||
// convert to emended OpenAPI document, | ||
// and compose LLM function calling application | ||
const document: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const application: IHttpLlmApplication = HttpLlm.application(document, { | ||
keyword: true, | ||
}); | ||
|
||
// Let's imagine that LLM has selected a function to call | ||
const func: IHttpLlmFunction | undefined = application.functions.find( | ||
// (f) => f.name === "llm_selected_fuction_name" | ||
(f) => f.path === "/bbs/articles/{id}" && f.method === "put", | ||
); | ||
if (func === undefined) throw new Error("No matched function exists."); | ||
|
||
// actual execution is by yourself | ||
const article = await HttpLlm.execute({ | ||
connection: { | ||
host: "http://localhost:3000", | ||
}, | ||
application, | ||
function: func, | ||
arguments: [ | ||
{ | ||
section: "general", | ||
id: v4(), | ||
query: { | ||
language: "en-US", | ||
format: "markdown", | ||
}, | ||
body: { | ||
title: "Hello, world!", | ||
body: "Let's imagine that this argument is composed by LLM.", | ||
thumbnail: null, | ||
}, | ||
}, | ||
], | ||
}); | ||
console.log("article", article); | ||
}; | ||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
HttpLlm, | ||
IHttpLlmApplication, | ||
IHttpLlmFunction, | ||
LlmTypeChecker, | ||
OpenApi, | ||
OpenApiV3, | ||
OpenApiV3_1, | ||
SwaggerV2, | ||
} from "@samchon/openapi"; | ||
import fs from "fs"; | ||
import typia from "typia"; | ||
import { v4 } from "uuid"; | ||
|
||
const main = async (): Promise<void> => { | ||
// read swagger document and validate it | ||
const swagger: | ||
| SwaggerV2.IDocument | ||
| OpenApiV3.IDocument | ||
| OpenApiV3_1.IDocument = JSON.parse( | ||
await fs.promises.readFile("swagger.json", "utf8"), | ||
); | ||
typia.assert(swagger); // recommended | ||
|
||
// convert to emended OpenAPI document, | ||
// and compose LLM function calling application | ||
const document: OpenApi.IDocument = OpenApi.convert(swagger); | ||
const application: IHttpLlmApplication = HttpLlm.application(document, { | ||
keyword: false, | ||
separate: (schema) => | ||
LlmTypeChecker.isString(schema) && schema.contentMediaType !== undefined, | ||
}); | ||
|
||
// Let's imagine that LLM has selected a function to call | ||
const func: IHttpLlmFunction | undefined = application.functions.find( | ||
// (f) => f.name === "llm_selected_fuction_name" | ||
(f) => f.path === "/bbs/articles/{id}" && f.method === "put", | ||
); | ||
if (func === undefined) throw new Error("No matched function exists."); | ||
|
||
// actual execution is by yourself | ||
const article = await HttpLlm.execute({ | ||
connection: { | ||
host: "http://localhost:3000", | ||
}, | ||
application, | ||
function: func, | ||
arguments: HttpLlm.mergeParameters({ | ||
function: func, | ||
llm: [ | ||
// LLM composed parameter values | ||
"general", | ||
v4(), | ||
{ | ||
language: "en-US", | ||
format: "markdown", | ||
}, | ||
{ | ||
title: "Hello, world!", | ||
content: "Let's imagine that this argument is composed by LLM.", | ||
}, | ||
], | ||
human: [ | ||
// Human composed parameter values | ||
{ thumbnail: "https://example.com/thumbnail.jpg" }, | ||
], | ||
}), | ||
}); | ||
console.log("article", article); | ||
}; | ||
main().catch(console.error); |