g4f JavaScript调用报错问题解决

问题1

start .\g4f-official-test.html 进行测试, 测试3: 基础API调用 ❌ 调用失败 测试基础调用 调用失败: Unexpected token '你', "你好!很高兴认识你。"... is not valid JSON

测试的问题是:你好,请简单介绍一下你自己

AI调试,出现问题2

问题2

调用g4f的JavaScript报错:

测试3: 基础API调用

❌ 调用失败

测试基础调用

调用失败: Unexpected token '你', "你好!我是Gemma"... is not valid JSON

从这里可以看到,模型已经返回了ai信息,只是它不是json格式罢了

AI调试过程中

{

"status": "❌ 修复验证失败",

"timestamp": "4/18/2026, 10:09:10 PM",

"errorType": "SyntaxError",

"errorMessage": "Unexpected token '你', \"你好!我是一个由人工\"... is not valid JSON",

"errorDetails": "SyntaxError: Unexpected token '你', \"你好!我是一个由人工\"... is not valid JSON",

"conclusion": "修复可能不完整,需要进一步调试"

}

看来还是json格式这里有问题啊,还以是JavaScript返回的直接就是一个字符串啊!

问题3

22:13:49\] === 修复验证测试失败 === \[22:13:49\] ❌ 测试失败 \[22:13:49\] 错误类型: Error \[22:13:49\] 错误信息: Status 404: The model \`moonshotai/kimi-k2-instruct-0905\` does not exist or you do not have access to it. \[22:13:49\] 错误详情: Error: Status 404: The model \`moonshotai/kimi-k2-instruct-0905\` does not exist or you do not have access to it. at Client._regularCompletion (https://g4f.dev/dist/js/client.js:356:19) at async runFixedTest (file:///G:/codeartswork/aicomm/g4f-fixed-test.html:335:32) 这应该是模型调用问题,换用default模型试试 default也不行 调用失败: Status 400: {"error":"Model 'default' not allowed. Available models: openrouter/free, stepfun/step-3.5-flash:free, arcee-ai/trinity-large-preview:free, upstage/solar-pro-3:free, liquid/lfm-2.5-1.2b-thinking:free, liquid/lfm-2.5-1.2b-instruct:free, nvidia/nemotron-3-nano-30b-a3b:free, arcee-ai/trinity-mini:free, nvidia/nemotron-nano-12b-v2-vl:free, qwen/qwen3-next-80b-a3b-instruct:free, nvidia/nemotron-nano-9b-v2:free, openai/gpt-oss-120b:free, openai/gpt-oss-20b:free, z-ai/glm-4.5-air:free, qwen/qwen3-coder:free, cognitivecomputations/dolphin-mistral-24b-venice-edition:free, google/gemma-3n-e2b-it:free, google/gemma-3n-e4b-it:free, qwen/qwen3-4b:free, mistralai/mistral-small-3.1-24b-instruct:free, google/gemma-3-4b-it:free, google/gemma-3-12b-it:free, google/gemma-3-27b-it:free, meta-llama/llama-3.3-70b-instruct:free, meta-llama/llama-3.2-3b-instruct:free, nousresearch/hermes-3-llama-3.1-405b:free"} 后来发现模型直接留空即可: // 准备请求参数 const requestParams = { model: model || '', // 模型名字位置留空,两个引号即可 messages: [ { role: 'user', content: message } ] }; json那边还有问题,继续调试 先到这里

相关推荐
qqty12172 小时前
基于python语言的网页设计(手把手教你设计一个个人博客网站)
开发语言·python
耿雨飞2 小时前
Python 后端开发技术博客专栏 | 第 02 篇 函数式编程与 Python 魔法 -- 闭包、装饰器、高阶函数
开发语言·python·装饰器·高阶函数·闭包
网域小星球2 小时前
C++ 从 0 入门(五)|C++ 面试必知:静态成员、友元、const 成员(高频考点)
开发语言·c++·面试·静态成员·友元函数
|_⊙2 小时前
C++11 右值引用
开发语言·c++
coder_liluyao2 小时前
JS动画函数的封装(很实用)
javascript
kyriewen2 小时前
代码写成一锅粥?这5种设计模式让你的项目“起死回生”
前端·javascript·设计模式
蓝色的雨2 小时前
基于Babylonjs的WEBGPU渲染器源码架构
前端·javascript
qq_12084093712 小时前
Three.js 与前端框架集成实战:Vue/React 生命周期对齐与热更新避坑
javascript·vue.js·前端框架
donecoding2 小时前
对象模型与内存的“钥匙理论”:TS 切入的 Go 的结构体与指针
javascript·typescript·go