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

Using json5 for parsing arguments #53

Merged
merged 1 commit into from
Aug 21, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
},
"dependencies": {
"@polywrap/client-js": "~0.12.0",
"@polywrap/result": "~0.12.0",
"@polywrap/sys-config-bundle-js": "~0.12.0",
"@polywrap/web3-config-bundle-js": "~0.12.0",
"@polywrap/result": "~0.12.0",
"axios": "^0.26.0",
"figlet": "~1.6.0",
"fuse.js": "^6.6.2",
"json5": "^2.2.3",
"openai": "~3.3.0",
"path-browserify": "1.0.1"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/agents/agent-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Scripts } from "../Scripts";
import { WrapClient } from "../wrap";
import { LlmApi, Chat } from "../llm";
import { trimText } from "./utils";
import JSON5 from "json5";

export interface AgentContext {
globals: Record<string, string>;
Expand Down Expand Up @@ -97,7 +98,7 @@ function processFunctionAndArgs(
let fnArgs;
try {
fnArgs = args
? JSON.parse(args)
? JSON5.parse(args)
: undefined;
} catch(err: any) {
return ResultErr(UNPARSABLE_FUNCTION_ARGS(name, args, err));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
JsEngine_Module,
shimCode
} from "../../../wrap";
import JSON5 from "json5";

export const executeScript: AgentFunction = {
definition: {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const executeScript: AgentFunction = {
args = options.arguments.replace(/\{\{/g, "\\{\\{").replace(/\}\}/g, "\\}\\}");
try {

args = JSON.parse(options.arguments);
args = JSON5.parse(options.arguments);

if (args) {
const replaceVars = (str: string, vars: any) => {
Expand Down
Loading