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

先到这里

相关推荐
Rain5093 分钟前
mini-cc 的 MCP 协议:给 AI 装个 USB-C 接口
c语言·开发语言·前端·人工智能·架构·node.js·ai编程
华科大胡子24 分钟前
AI开发者的网络卡点:Anthropic连接超时
开发语言·php
磊 子1 小时前
STL无序关联容器—unorded_set+unorded_map
开发语言·c++
AI人工智能+电脑小能手1 小时前
【大白话说Java面试题 第84题】【Mysql篇】第14题:为什么用 InnoDB 存储引擎的表建议用整型的自增主键?
java·开发语言·数据库·mysql·面试
丷丩1 小时前
MapLibre GL JS第27课:添加COG栅格源
javascript·map·mapbox·maplibre gl js
YikNjy2 小时前
break和continue
java·开发语言·算法
秋92 小时前
java项目中cpu飙升排查及解决方法
java·开发语言
野生技术架构师2 小时前
牛客网2026最新大厂Java高频面试题精选(附标准答案)
java·开发语言
PH = 72 小时前
JAVA的SPI机制
java·开发语言
IT猿手2 小时前
多目标优化算法:多目标蛇优化算法(Multiple Objective Snake Optimizer,MOSO)(提供MATLAB代码)
开发语言·算法·matlab·动态路径规划·光伏模型参数估计