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那边还有问题,继续调试

先到这里

相关推荐
半个落月18 分钟前
从递归到快速排序:用 JavaScript 把分治思想讲明白
javascript·算法·面试
小兔崽子去哪了37 分钟前
Vue3 + Pinia 集成 IGV.js 实现 BAM 文件在线浏览
javascript·vue.js·后端
小月土星1 小时前
JavaScript 快速排序:从 pivot、双指针到分治思想
javascript·算法·面试
小月土星1 小时前
JavaScript 递归入门:从 1 到 n 求和,再到数组扁平化
javascript·算法·面试
还有多久拿退休金2 小时前
一个 var 让整个团队加班到凌晨——JS 闭包的那些暗坑
前端·javascript
weedsfly2 小时前
用了 React/Vue 之后,这些 DOM 操作的坑你踩过几个?
前端·javascript
Asize2 小时前
Ajax 入门:从 JSON 序列化到 XMLHttpRequest
前端·javascript·前端框架
铁皮饭盒3 小时前
@kognitivedev/rag, 用js做AI Agent开发
javascript·后端
kyriewen15 小时前
别再 console.log 了:5 个 Chrome DevTools 调试技巧,用过就回不去了
前端·javascript·面试
To_OC17 小时前
LC 1 两数之和:面试第一道必考题,暴力解法直接被面试官 pass
javascript·算法·leetcode