AI desktop path: plain-HTML Review and Cost tabs over the Qt bridge, gate in Python
ai_sections.html pastes into the no-AI dashboard.html; ai_bridge.py adds one ai_request slot that hands every AI contract request (incl. GET /roi) to the review backend's dispatch(). Desktop page check reruns the web review and cost cases plus a tampered-page gate case. Eval fixture e-pyqt-ai added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
128f153f84
commit
d89dce3c33
13 files changed
+203
-14
No files matched your search
+34
@@ -0,0 +1,34 @@
|
||||
"""The LLM extraction call: one scanned invoice in, its fields out, each with word scores."""
|
||||
import json
|
||||
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
MODEL = "gemini-2.5-flash"
|
||||
FIELDS = { # field name -> mandatory
|
||||
"Invoice number": True,
|
||||
"Invoice date": True,
|
||||
"Vendor": True,
|
||||
"PO number": False,
|
||||
"Due date": True,
|
||||
"Total": True,
|
||||
}
|
||||
PROMPT = (
|
||||
"Read this invoice. Return JSON: a list of {field, value, word_scores}, one per field in "
|
||||
+ ", ".join(FIELDS)
|
||||
+ ". word_scores is your 0-1 legibility score for each word of the value. Use an empty "
|
||||
"value and no scores when a field isn't on the page."
|
||||
)
|
||||
|
||||
|
||||
def extract_invoice(document: bytes, mime_type: str) -> list[dict]:
|
||||
client = genai.Client() # credentials come from the environment
|
||||
response = client.models.generate_content(
|
||||
model=MODEL,
|
||||
contents=[types.Part.from_bytes(data=document, mime_type=mime_type), PROMPT],
|
||||
config=types.GenerateContentConfig(response_mime_type="application/json"),
|
||||
)
|
||||
rows = json.loads(response.text)
|
||||
for row in rows:
|
||||
row["mandatory"] = FIELDS.get(row["field"], False)
|
||||
return rows
|
||||
Reference in new issue
Block a user