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

js输出总是取不到要取的字段 #1909

Closed
1 of 5 tasks
ppkitty opened this issue Jul 2, 2024 · 12 comments
Closed
1 of 5 tasks

js输出总是取不到要取的字段 #1909

ppkitty opened this issue Jul 2, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@ppkitty
Copy link

ppkitty commented Jul 2, 2024

例行检查

  • [ x] 我已确认目前没有类似 issue
  • 我已完整查看过项目 README,以及项目文档
  • 我使用了自己的 key,并确认我的 key 是可正常使用的
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

你的版本

  • 公有云版本
  • [ x] 私有部署版本, 具体版本号:

问题描述, 日志截图
用js模块取json里面的值,输出为:
{
"codeReturn": {
"result": "pending"
},
"log": ""
}
js模块中自定义输出放了2个:codeReturn(any类型),result(string类型),codeReturn可以拿到结果,结果为:
{
"result": "pending"
}
但result总是取不到

复现步骤

预期结果

相关截图

@ppkitty ppkitty added the bug Something isn't working label Jul 2, 2024
@c121914yu
Copy link
Collaborator

这是个啥?

@ppkitty
Copy link
Author

ppkitty commented Jul 2, 2024

找到原因了,result要在js代码中赋值,打扰了

@ppkitty ppkitty closed this as completed Jul 2, 2024
@c121914yu
Copy link
Collaborator

~ok,,下次麻烦直接贴图和代码,这表述看着怪怪的。

@ppkitty
Copy link
Author

ppkitty commented Jul 2, 2024

不好意思,刚看错了,还是有问题。以下是js代码:
function main({ json }) {
let statusValue = "";
try {
const json1 = JSON.parse(json);
if (json && json1.results && json1.results.length > 0) {
statusValue = json1.results[0].status;
} else {
statusValue = "Invalid JSON structure";
}
} catch (error) {
statusValue = "Error processing JSON:" + error.message;
}
return {
result: statusValue
};
}
js模块自定义输出为:

  • result:string
  • codeReturn: any
    运行后,自定义输出的result总是取不到,而自定义输出codeReturn为:
    {
    "codeReturn": {
    "result": "pending"
    },
    "log": ""
    }
    自定义输出的两个值:
  • result:为空
  • codeReturn:
    {
    "result": "pending"
    }
    我就想取这个pending,怎么也取不到,下一步的判断就没法进行,即便用codeReturn包含“pending”都不能识别到

@ppkitty ppkitty reopened this Jul 2, 2024
@c121914yu
Copy link
Collaborator

return {
result: statusValue
};
不就只有一个输出么~ codeReturn是啥乱七八糟的

@ppkitty
Copy link
Author

ppkitty commented Jul 2, 2024

在调试中看输出结果就长这样:
{
"codeReturn": {
"result": "pending"
},
"log": ""
}
也不知道哪里出了问题。之前都可以取出来,唯一变化是中间我们尝试装了npm的2个库,装了之后输出就变成这样了:
npm install es6-promise
npm install compromise

@c121914yu
Copy link
Collaborator

直接写 result 就能提了

@ppkitty
Copy link
Author

ppkitty commented Jul 2, 2024

如果是自定义输出字段就是提不出来result(始终为空),只能提出codeReturn。尝试再加一个js模块从codeReturn提取result,给我的结果依然是这个格式:
{
"codeReturn": {
"result": "pending"
},
"log": ""
}

@c121914yu
Copy link
Collaborator

c121914yu commented Jul 2, 2024

没看懂,我写个 result 就能提出来了
image
image

@ppkitty
Copy link
Author

ppkitty commented Jul 3, 2024

今天升级到4.8.5就好了,之前输出格式一直有问题

@c121914yu
Copy link
Collaborator

今天升级到4.8.5就好了,之前输出格式一直有问题

严重怀疑,是不是你 sandbox 和 fastgpt 版本不一致

@ppkitty
Copy link
Author

ppkitty commented Jul 4, 2024

是的,后来跟负责搭建系统的同事确认了

@ppkitty ppkitty closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants