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

先到这里

相关推荐
小磊哥er20 分钟前
深入解构Claude Code - 第 7 篇 · 连接外面的世界
javascript·ai编程
小磊哥er42 分钟前
深入解构Claude Code - 第 6 篇 · 终端里的图形界面
javascript·ai编程
海兰44 分钟前
【应用】基于 Next.js 16 + Python mplfinance的金融K线图与技术指标可视化平台(一)
javascript·python·金融
大衛說1 小时前
《Python 从入门到精通》系列总览与学习路线
开发语言·python·学习
可乐鸡翅yeah_2 小时前
hls.js 内存泄漏实战排查,直播 M3U8 长时间播放异常定位方案
开发语言·javascript·python·django·ecmascript·m3u8·m3u8在线
可乐鸡翅yeah_2 小时前
第三方接口对接 M3U8 流媒体排坑实战,解决外部服务商流兼容难题
前端·javascript·python·django·html·m3u8·m3u8在线
2601_962203512 小时前
Java进阶07集合(续)
java·开发语言
郑州光合科技余经理3 小时前
本地生活服务系统:模块边界与结算字段怎么拆
java·开发语言·前端·后端·系统架构·uni-app·php
默_笙3 小时前
🏠 「LLM Notes」:我用 Next.js + Redis 给自己造了个笔记博客
前端·javascript
来了就未晚3 小时前
Python基础 学习代码存储与命名规范
开发语言·python·学习