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

先到这里

相关推荐
北冥you鱼几秒前
Go flag 包详解:从命令行解析到实战应用
开发语言·后端·golang
To_OC39 分钟前
LC 22 括号生成:刷完这道题,我终于搞懂回溯剪枝了
javascript·算法·leetcode
小二·42 分钟前
Next.js 15 企业级实战:从项目搭建到CI/CD全链路(App Router + Server Components + Turbopack)
javascript·ci/cd·turbopack
web守墓人43 分钟前
【python】uv解决依赖安装缓慢的问题
开发语言·python·uv
像我这样帅的人丶你还44 分钟前
🚀大文件上传的那些事
前端·javascript·架构
To_OC1 小时前
LC 39 组合总和:回溯入门必刷题,我踩过的两个坑都在这了
javascript·算法·leetcode
橘子星1 小时前
从零理解流式输出 —— 一个 Vue + DeepSeek 的前端实战
前端·javascript·人工智能
geovindu2 小时前
CSharp: Bridge Pattern
开发语言·后端·桥接模式·结构型模式
এ慕ོ冬℘゜2 小时前
深入 JavaScript BOM:掌握 window 对象的窗口控制魔法
开发语言·javascript·ecmascript
2501_941982052 小时前
企业微信二次开发:如何用 Python 搭建通用的 Webhook 实时消息接收
开发语言·python·企业微信