Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,3 @@
|
|
| 1 |
-
"""
|
| 2 |
-
FINAL Bench v4.1 — Baseline (Non-AGI) Evaluation System
|
| 3 |
-
=========================================================
|
| 4 |
-
Frontier Intelligence Nexus for AGI-Level Verification
|
| 5 |
-
|
| 6 |
-
★ Baseline (Non-AGI) single-call evaluation
|
| 7 |
-
★ Multi-Provider: OpenAI / Anthropic / Google (Gemini)
|
| 8 |
-
★ Both Eval Model AND Judge Model support all 3 providers
|
| 9 |
-
★ 100 Tasks · 15 Domains · 8 TICOS Types · 5-Axis · 5-Stage AGI Grade
|
| 10 |
-
★ Dataset: HuggingFace FINAL-Bench/Metacognitive
|
| 11 |
-
|
| 12 |
-
🔒 MetaCog (Self-Correction Protocol) evaluation: COMING SOON
|
| 13 |
-
|
| 14 |
-
Author: Ginigen AI — Choi Sunyoung
|
| 15 |
-
License: Apache 2.0
|
| 16 |
-
"""
|
| 17 |
-
|
| 18 |
import json, os, time, csv, io, re, html, hashlib, sqlite3, threading
|
| 19 |
from datetime import datetime
|
| 20 |
from dataclasses import dataclass, field
|
|
@@ -187,7 +170,7 @@ def call_openai(prompt, system="", api_key="", model="gpt-5.2",
|
|
| 187 |
for attempt in range(3):
|
| 188 |
try:
|
| 189 |
r=requests.post("https://api.openai.com/v1/chat/completions",
|
| 190 |
-
headers=headers,json
|
| 191 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 192 |
r.raise_for_status(); c=r.json()["choices"][0]["message"]["content"]
|
| 193 |
return _strip_think(c) if c else "[EMPTY]"
|
|
@@ -200,22 +183,31 @@ def call_openai(prompt, system="", api_key="", model="gpt-5.2",
|
|
| 200 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 201 |
else: return f"[API_ERROR] {e}"
|
| 202 |
|
| 203 |
-
# --- Anthropic ---
|
| 204 |
def call_anthropic(prompt, system="", api_key="", model="claude-opus-4-6",
|
| 205 |
max_tokens=8192, temperature=0.6):
|
| 206 |
-
headers={
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
| 210 |
if system: payload["system"]=system
|
| 211 |
for attempt in range(3):
|
| 212 |
try:
|
| 213 |
r=requests.post("https://api.anthropic.com/v1/messages",
|
| 214 |
-
headers=headers,json
|
| 215 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 216 |
-
r.
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
except requests.exceptions.HTTPError:
|
| 220 |
try: err=r.json().get("error",{}).get("message","")
|
| 221 |
except: err=str(r.status_code)
|
|
@@ -225,31 +217,47 @@ def call_anthropic(prompt, system="", api_key="", model="claude-opus-4-6",
|
|
| 225 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 226 |
else: return f"[API_ERROR] {e}"
|
| 227 |
|
| 228 |
-
# --- Google Gemini ---
|
|
|
|
|
|
|
| 229 |
def call_gemini(prompt, system="", api_key="", model="gemini-3-pro",
|
| 230 |
-
max_tokens=8192, temperature=0
|
| 231 |
-
url=f"
|
| 232 |
-
headers={
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
if json_mode:
|
| 237 |
-
|
| 238 |
for attempt in range(3):
|
| 239 |
try:
|
| 240 |
-
r=requests.post(url,headers=headers,
|
| 241 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 242 |
-
r.
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
except requests.exceptions.HTTPError:
|
| 249 |
try: err=r.json().get("error",{}).get("message","")
|
| 250 |
except: err=str(r.status_code)
|
| 251 |
if attempt<2: time.sleep(3*(attempt+1)); continue
|
| 252 |
-
return f"[API_ERROR] {err}"
|
| 253 |
except Exception as e:
|
| 254 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 255 |
else: return f"[API_ERROR] {e}"
|
|
@@ -921,4 +929,4 @@ if __name__=="__main__":
|
|
| 921 |
print(f" 🔒 MetaCog: COMING SOON\n{'='*60}\n")
|
| 922 |
app=create_app()
|
| 923 |
app.queue(default_concurrency_limit=2)
|
| 924 |
-
app.launch(server_name="0.0.0.0",server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json, os, time, csv, io, re, html, hashlib, sqlite3, threading
|
| 2 |
from datetime import datetime
|
| 3 |
from dataclasses import dataclass, field
|
|
|
|
| 170 |
for attempt in range(3):
|
| 171 |
try:
|
| 172 |
r=requests.post("https://api.openai.com/v1/chat/completions",
|
| 173 |
+
headers=headers,data=json.dumps(payload),timeout=300)
|
| 174 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 175 |
r.raise_for_status(); c=r.json()["choices"][0]["message"]["content"]
|
| 176 |
return _strip_think(c) if c else "[EMPTY]"
|
|
|
|
| 183 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 184 |
else: return f"[API_ERROR] {e}"
|
| 185 |
|
| 186 |
+
# --- Anthropic (★ data=json.dumps, 429+529 retry) ---
|
| 187 |
def call_anthropic(prompt, system="", api_key="", model="claude-opus-4-6",
|
| 188 |
max_tokens=8192, temperature=0.6):
|
| 189 |
+
headers={
|
| 190 |
+
"Content-Type":"application/json",
|
| 191 |
+
"x-api-key":api_key,
|
| 192 |
+
"anthropic-version":"2023-06-01"
|
| 193 |
+
}
|
| 194 |
+
messages=[{"role":"user","content":prompt}]
|
| 195 |
+
payload={"model":model,"max_tokens":max_tokens,"temperature":temperature,"messages":messages}
|
| 196 |
if system: payload["system"]=system
|
| 197 |
for attempt in range(3):
|
| 198 |
try:
|
| 199 |
r=requests.post("https://api.anthropic.com/v1/messages",
|
| 200 |
+
headers=headers,data=json.dumps(payload),timeout=300)
|
| 201 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 202 |
+
if r.status_code==529: time.sleep(8*(attempt+1)); continue
|
| 203 |
+
r.raise_for_status()
|
| 204 |
+
resp=r.json()
|
| 205 |
+
text_parts=[]
|
| 206 |
+
for block in resp.get("content",[]):
|
| 207 |
+
if block.get("type")=="text":
|
| 208 |
+
text_parts.append(block["text"])
|
| 209 |
+
c="\n".join(text_parts)
|
| 210 |
+
return _strip_think(c) if c else "[EMPTY]"
|
| 211 |
except requests.exceptions.HTTPError:
|
| 212 |
try: err=r.json().get("error",{}).get("message","")
|
| 213 |
except: err=str(r.status_code)
|
|
|
|
| 217 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 218 |
else: return f"[API_ERROR] {e}"
|
| 219 |
|
| 220 |
+
# --- Google Gemini (★ x-goog-api-key header, data=json.dumps, thinking filter) ---
|
| 221 |
+
GEMINI_API_BASE = "https://generativelanguage.googleapis.com/v1beta"
|
| 222 |
+
|
| 223 |
def call_gemini(prompt, system="", api_key="", model="gemini-3-pro",
|
| 224 |
+
max_tokens=8192, temperature=1.0, json_mode=False):
|
| 225 |
+
url=f"{GEMINI_API_BASE}/models/{model}:generateContent"
|
| 226 |
+
headers={
|
| 227 |
+
"Content-Type":"application/json",
|
| 228 |
+
"x-goog-api-key":api_key,
|
| 229 |
+
}
|
| 230 |
+
contents=[{"role":"user","parts":[{"text":prompt}]}]
|
| 231 |
+
gen_config={"maxOutputTokens":max_tokens,"temperature":temperature}
|
| 232 |
+
payload={"contents":contents,"generationConfig":gen_config}
|
| 233 |
+
if system:
|
| 234 |
+
payload["systemInstruction"]={"parts":[{"text":system}]}
|
| 235 |
if json_mode:
|
| 236 |
+
gen_config["responseMimeType"]="application/json"
|
| 237 |
for attempt in range(3):
|
| 238 |
try:
|
| 239 |
+
r=requests.post(url,headers=headers,data=json.dumps(payload),timeout=300)
|
| 240 |
if r.status_code==429: time.sleep(5*(attempt+1)); continue
|
| 241 |
+
if r.status_code==503: time.sleep(8*(attempt+1)); continue
|
| 242 |
+
r.raise_for_status()
|
| 243 |
+
data=r.json()
|
| 244 |
+
candidates=data.get("candidates",[])
|
| 245 |
+
if not candidates:
|
| 246 |
+
block_reason=data.get("promptFeedback",{}).get("blockReason","UNKNOWN")
|
| 247 |
+
return f"[BLOCKED] Gemini blocked response: {block_reason}"
|
| 248 |
+
parts=candidates[0].get("content",{}).get("parts",[])
|
| 249 |
+
result=[]
|
| 250 |
+
for p in parts:
|
| 251 |
+
if "text" in p:
|
| 252 |
+
if p.get("thought",False): continue # skip thinking parts
|
| 253 |
+
result.append(p["text"])
|
| 254 |
+
c="\n".join(result) if result else ""
|
| 255 |
+
return _strip_think(c) if c else "[EMPTY]"
|
| 256 |
except requests.exceptions.HTTPError:
|
| 257 |
try: err=r.json().get("error",{}).get("message","")
|
| 258 |
except: err=str(r.status_code)
|
| 259 |
if attempt<2: time.sleep(3*(attempt+1)); continue
|
| 260 |
+
return f"[API_ERROR] Gemini {r.status_code}: {err}"
|
| 261 |
except Exception as e:
|
| 262 |
if attempt<2: time.sleep(3*(attempt+1))
|
| 263 |
else: return f"[API_ERROR] {e}"
|
|
|
|
| 929 |
print(f" 🔒 MetaCog: COMING SOON\n{'='*60}\n")
|
| 930 |
app=create_app()
|
| 931 |
app.queue(default_concurrency_limit=2)
|
| 932 |
+
app.launch(server_name="0.0.0.0",server_port=7860,ssr_mode=False)
|