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

XFEstudio/gpt4free

Fix som checks

f11fc4fe
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +10 -71
Modified g4f/gui/server/api.py +1 -1
@@ -40,7 +40,7 @@ class Api:
40 40
41 41 @staticmethod
42 42 def get_provider_models(
43 provider: str, api_key: str = None, base_url: str = None, ignored: list = None
43 provider: str, api_key: "str | None" = None, base_url: "str | None" = None, ignored: "list | None" = None
44 44 ):
45 45 def get_model_data(
46 46 provider: ProviderModelMixin, model: str, default: bool = False
Modified g4f/mcp/pa_downloader.py +1 -1
@@ -259,7 +259,7 @@ def _should_auto_download(workspace: Path) -> bool:
259 259 return True
260 260 try:
261 261 with open(marker, "r") as f:
262 timestamp = float(f.read().strip())
262 timestamp = float(f.read().strip() or "0")
263 263 age = time.time() - timestamp
264 264 except OSError:
265 265 return True
Modified g4f/providers/cache.py +8 -5
@@ -7,7 +7,7 @@ from ..cookies import get_cookies_dir
7 7
8 8
9 9 class FileStorage:
10 def __init__(self, storage_dir: str = None):
10 def __init__(self, storage_dir: "str | None" = None):
11 11 if storage_dir is None:
12 12 storage_dir = os.path.join(get_cookies_dir(), ".models")
13 13 self.storage_dir = storage_dir
@@ -25,20 +25,23 @@ class FileStorage:
25 25 dirname = os.path.dirname(file)
26 26 if not os.path.exists(dirname):
27 27 os.makedirs(dirname)
28 with open(file, "w", encoding="utf-8") as f:
29 json.dump(value, f)
28 try:
29 with open(file, "w", encoding="utf-8") as f:
30 json.dump(value, f)
31 except Exception as e:
32 print(f"Error writing to {file}: {e}")
30 33
31 34 def get(self, key: str) -> str | None:
32 35 try:
33 36 with open(self.get_file(key), "r", encoding="utf-8") as f:
34 37 return json.load(f)
35 except FileNotFoundError:
38 except (FileNotFoundError, json.JSONDecodeError, OSError) as e:
36 39 return None
37 40
38 41 def delete(self, key: str):
39 42 try:
40 43 os.remove(self.get_file(key))
41 except FileNotFoundError:
44 except (FileNotFoundError, OSError) as e:
42 45 pass
43 46
44 47 def clear(self):
Modified g4f/tools/optimize_request.py +0 -64
@@ -111,70 +111,6 @@ REPLACE_VSC = (
111 111 "- **Skills:** Use `read_file` to load detailed skill instructions when a "
112 112 "task matches a skill's domain (e.g., use `project-setup-info-local` for "
113 113 "scaffolding new projects from scratch, not for adding individual files)."
114 """
115 # ADHD Mode: Escaping the Textbook Answer
116
117 The first three answers to any problem are obvious, safe, and forgettable. The interesting answers live past number three, in the "awkward middle." This skill forces the model there using parallel divergent ideation.
118
119 ## Pre-flight Gate (Cost Check)
120 This process costs ~10 parallel Agent calls (5-10x normal). Run this gate first.
121 1. **Explicit Invocation:** If invoked via `/adhd` or explicit user request, **skip to Phase 1**.
122 2. **Self-Judge:** Abort and answer directly unless ALL three are true:
123 - **Open-ended:** Multiple viable answers exist (no canonical answer).
124 - **High-stakes:** Architecture, public APIs, fuzzy bugs (not a 11pm side-project).
125 - **Open phrasing:** User didn't use words like "quick," "standard," "just," or "textbook."
126 *(If aborted, append: "Run `/adhd <your problem>` for wider exploration.")*
127
128 ## The Loop
129 Strict separation is required; the critic must not strangle the generator.
130
131 ### Phase 1 — Diverge (No Critic)
132 1. Pick 5 cognitive frames from the table below. Bias toward `code`/`design` for technical problems; always include 1 `wild`.
133 2. Spawn 5 **parallel, isolated** Agent/Task calls (one per frame). *Critical invariant: Do NOT serialize or share context between branches.*
134 3. **Agent Instruction:**
135 > DIVERGENT MODE: Generate 6 short, distinct ideas under this frame. The first 3 obvious answers are banned. No evaluation, ranking, or hedging. Push into the awkward middle. Output JSON array only: `[{"text": "...", "rationale": "..."}]`
136
137 ### Phase 2 — Focus (Critic On)
138 1. **Score:** Rate ideas 0-10 on Novelty (0.35 weight), Viability (0.40), Fit (0.25). Flag traps (hidden costs, false economies) with a one-line reason.
139 2. **Cluster:** Group into 3-6 clusters by underlying angle (e.g., "cache-shaped plays").
140 3. **Deepen Top 3:** Spawn 1 Agent call per top idea (excluding traps). **Agent Instruction:**
141 > FOCUS MODE: Sketch how this works (4-8 sentences). Name the load-bearing risk. Name the first concrete coding step. Generate 3-5 child ideas (variations/unlocks). Output JSON only.
142
143 ## Cognitive Frames (Pick 5 per run)
144 | Frame | Vantage Prompt | Tags |
145 |---|---|---|
146 | **Hardware engineer** | Think in latency, memory layout, physical constraints. What does bus topology/cache/timing tell you? | code, wild |
147 | **Regulator** | Audit for compliance/failure modes. What must be provable, traceable, or refusable here? | design, general |
148 | **10-year-old** | Naive but unencumbered. Ignore convention. | general, wild |
149 | **Hostile competitor** | Exploit, fail, or sabotage the obvious solution. Then invert into ideas. | code, design |
150 | **Biology** | Transplant a mechanism from biology (immune systems, cell signaling). Force-fit it. | code, wild |
151 | **Logistics** | Steal from logistics: queues, batching, JIT, hub-and-spoke. Apply literally. | code, design |
152 | **Game design** | What are the loops, rewards, friction, speedrun tricks? Treat the user as a player. | design, general |
153 | **Markets** | Treat as a market. Buyers, sellers, auction, clearing house—what do they look like here? | design, wild |
154 | **Inversion** | Brainstorm how to guarantee NOT X. Then negate each answer back. | code, design, general |
155 | **Extreme: $0, 1hr** | Crudest version that still does the load-bearing thing? | code, general |
156 | **Extreme: ∞ budget, 10yrs** | Maximalist version? | design, wild |
157 | **Remove assumption** | Name the thing everyone treats as fixed. Imagine it is gone. What is possible? | code, design, wild |
158 | **Speedrunner** | Find glitches, skips, out-of-bounds tricks. What is the abusive-but-legal path? | code, wild |
159 | **Ant colony** | No central planner. Many dumb agents, local rules. How does this solve itself emergently? | code, wild |
160 | **3am on-call** | You are woken at 3am when this breaks. What design prevents the page? | code, design |
161
162 ## Output Shape
163 1. **Brief:** 1-2 lines confirming the problem/reframe.
164 2. **Wide Set:** Full pool grouped by cluster (labeled by angle). Short phrases with score chips `[N7 V8 F9]`.
165 3. **Converge:** 2-4 idea shortlist with rationale. Mark non-obvious viable picks with ★. List traps separately with 1-line reasons.
166 4. **Focus:** The 3 deepened branches (sketch, risk, first step, child ideas).
167 5. **Provocation:** 1 wildcard question opening a new direction.
168
169 ## Anti-patterns & Calibration
170 - **No fake divergence:** 10 variations of one assumption isn't breadth; it's decoration.
171 - **No weird-for-weird's-sake:** Always converge with a real opinion. "You decide" is a cop-out.
172 - **Strict Isolation:** Simulating parallel branches in one context just creates a wider single thought. Use separate Agent contexts.
173 - **Structure over prose:** Cluster, label, and score. Walls of text are useless.
174 - **Calibrate:** Scale ideas to stakes (3x4 for quick tasks, 5x8 for strategy). Stop diverging when candidates repeat shapes.
175
176 *(Note: Use companion CLI `npm install -g adhd-agent` for batch/outside-Claude runs).*
177 """
178 114 )
179 115
180 116