XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

fix(Grok): update API payload structure and modeId mapping based on recent website updates

a5b8c70a
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +30 -30
Modified g4f/Provider/needs_auth/Grok.py +30 -30
@@ -123,50 +123,50 @@ class Grok(AsyncAuthedProvider, ProviderModelMixin):
123 123
124 124 @classmethod
125 125 async def _prepare_payload(cls, model: str, message: str) -> Dict[str, Any]:
126 # Map model names to API model names
127 api_model = "grok-latest"
128
129 if model in ["grok-4", "grok-4-heavy", "grok-4-reasoning"]:
130 api_model = model
131 elif model == "grok-3":
132 api_model = "grok-3"
133 elif model in ["grok-3-mini", "grok-3-mini-reasoning"]:
134 api_model = "grok-3-mini"
135 elif model == "grok-2":
136 api_model = "grok-2"
137
138 # Check if it's a reasoning model
139 is_reasoning = model.endswith("-reasoning") or model.endswith("-thinking") or model.endswith("-r1")
140
141 # Enable Big Brain mode for heavy models
142 enable_big_brain = "heavy" in model or "big-brain" in model
143
144 # Enable DeepSearch for Grok 3+ models
145 enable_deep_search = not model.startswith("grok-2")
126 # Map model names to modeId based on new Grok API
127 mode_id = "auto" if "auto" in model else "fast"
146 128
129 if "heavy" in model or "big-brain" in model:
130 mode_id = "heavy"
131 elif "expert" in model:
132 mode_id = "expert"
133 elif "reasoning" in model or "thinking" in model or "r1" in model:
134 mode_id = "reasoning"
135 elif "deepsearch" in model:
136 mode_id = "deepsearch"
137
147 138 return {
148 139 "temporary": True,
149 "modelName": api_model,
150 140 "message": message,
151 141 "fileAttachments": [],
152 142 "imageAttachments": [],
153 143 "disableSearch": False,
154 "enableImageGeneration": model == "grok-2-image" or model == "grok-4",
144 "enableImageGeneration": True,
155 145 "returnImageBytes": False,
156 146 "returnRawGrokInXaiRequest": False,
157 147 "enableImageStreaming": True,
158 148 "imageGenerationCount": 2,
159 149 "forceConcise": False,
160 "toolOverrides": {},
161 150 "enableSideBySide": True,
162 "isPreset": False,
163 151 "sendFinalMetadata": True,
164 "customInstructions": "",
165 "deepsearchPreset": "enabled" if enable_deep_search else "",
166 "isReasoning": is_reasoning,
167 "enableBigBrain": enable_big_brain,
168 "enableLiveSearch": False, # Real-time search for Grok 4
169 "contextWindow": 256000 if model.startswith("grok-4") else 131072, # 256k for Grok 4, 128k for others
152 "disableTextFollowUps": False,
153 "responseMetadata": {},
154 "disableMemory": False,
155 "forceSideBySide": False,
156 "isAsyncChat": False,
157 "disableSelfHarmShortCircuit": False,
158 "collectionIds": [],
159 "disabledConnectorIds": [],
160 "deviceEnvInfo": {
161 "darkModeEnabled": True,
162 "devicePixelRatio": 1.0,
163 "screenWidth": 1920,
164 "screenHeight": 1080,
165 "viewportWidth": 1920,
166 "viewportHeight": 1080
167 },
168 "modeId": mode_id,
169 "linkQuery": False
170 170 }
171 171
172 172 @classmethod