Skip to content

Commit

Permalink
try using method and path when operationId is undefined ChatGPTNextWe…
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Sep 27, 2024
1 parent 93ff7d2 commit 07d089a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/store/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nanoid } from "nanoid";
import { createPersistStore } from "../utils/store";
import { getClientConfig } from "../config/client";
import yaml from "js-yaml";
import { adapter } from "../utils";
import { adapter, getOperationId } from "../utils";
import { useAccessStore } from "./access";

const isApp = getClientConfig()?.isApp;
Expand Down Expand Up @@ -116,15 +116,15 @@ export const FunctionToolService = {
return {
type: "function",
function: {
name: o.operationId,
name: getOperationId(o),
description: o.description || o.summary,
parameters: parameters,
},
} as FunctionToolItem;
}),
funcs: operations.reduce((s, o) => {
// @ts-ignore
s[o.operationId] = function (args) {
s[getOperationId(o)] = function (args) {
const parameters: Record<string, any> = {};
if (o.parameters instanceof Array) {
o.parameters.forEach((p) => {
Expand All @@ -139,8 +139,8 @@ export const FunctionToolService = {
} else if (authLocation == "body") {
args[headerName] = tokenValue;
}
// @ts-ignore
return api.client[o.operationId](
// @ts-ignore if o.operationId is null, then using o.path and o.method
return api.client.paths[o.path][o.method](
parameters,
args,
api.axiosConfigDefaults,
Expand Down Expand Up @@ -253,6 +253,7 @@ export const usePluginStore = createPersistStore(
.catch((e) => item),
),
).then((builtinPlugins: any) => {
return;
builtinPlugins
.filter((item: any) => item?.content)
.forEach((item: any) => {
Expand Down
12 changes: 12 additions & 0 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,15 @@ export function safeLocalStorage(): {
},
};
}

export function getOperationId(operation: {
operationId?: string;
method: string;
path: string;
}) {
// pattern '^[a-zA-Z0-9_-]+$'
return (
operation?.operationId ||
`${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}`
);
}

0 comments on commit 07d089a

Please sign in to comment.