Léim go dtí an príomhábhar
Gaeilge— Roghnaigh teanga
Roghchlár

Eastóscadh agus Bailíochtú le Uirlisí

Ceacht 10 as 12 Nuashonraithe 30 Iúil 2026 Forbróir
Ar an leathanach seo
  1. Tóg píblínte eastósctha iontaofa
  2. Patrún: eastóscadh saibhrithe
  3. Patrún: tras-bhailíochtú
  4. Patrún: ríomh agus struchtúrú
  5. Ailtireacht píblíne láidre
  6. Láimhseáil earráidí i dtáirgeadh
  7. Príomhphointí

Tóg píblínte eastósctha iontaofa

Trí aschuir struchtúrtha a chomhcheangal le huirlisí (cuardach gréasáin, rith cód), is féidir leat píblínte láidre eastósctha agus bailíochtaithe a thógáil. Taispeánann an ceacht seo conas na píblínte seo a ailtireacht le haghaidh úsáide táirgeachta.

Patrún: eastóscadh saibhrithe

Is é an patrún is coitianta ná saibhriú a dhéanamh ar eastóscadh sonraí le cuardach gréasáin. Tosaíonn tú le téacs amh, eastóscaíonn an tsamhail eintitis, agus ansin saibhríonn sí iad le faisnéis a fhaightear ar líne.

from pydantic import BaseModel

class EntrepriseEnrichie(BaseModel):
    nom: str
    secteur: str
    pays_siege: str
    site_web: str | None
    description_courte: str
    nombre_employes_estime: str | None
    technologies_utilisees: list[str]

class ExtractionEnrichie(BaseModel):
    entreprises: list[EntrepriseEnrichie]
    relations: list[str]
    contexte: str

response, parsed = client.chat.parse(
    model="grok-4.20-0309-reasoning",
    messages=[{
        "role": "user",
        "content": """Extract and enrich the companies mentioned in this text:

        'Mistral AI announced a partnership with Scaleway to
        host its models in France. Meanwhile, Hugging Face
        continues to collaborate with OVHcloud on open source
        infrastructure.'"""
    }],
    response_format=ExtractionEnrichie,
    tools=[{"type": "web_search"}]
)

Patrún: tras-bhailíochtú

Úsáideann tras-bhailíochtú cuardach gréasáin chun faisnéis a fhíorú a eastóscaíodh as doiciméad:

class FactCheck(BaseModel):
    affirmation: str
    verifie: bool
    source: str | None
    correction: str | None
    confiance: float

class RapportValidation(BaseModel):
    document_original: str
    verifications: list[FactCheck]
    fiabilite_globale: float
    resume: str

response, parsed = client.chat.parse(
    model="grok-4.20-0309-reasoning",
    messages=[{
        "role": "user",
        "content": """Verify the facts in this text:
        'France has 68 million inhabitants. Paris is the
        largest city in Europe. France's GDP is the 7th
        largest worldwide.'"""
    }],
    response_format=RapportValidation,
    tools=[{"type": "web_search"}]
)

for v in parsed.verifications:
    status = "Verified" if v.verifie else "Unverified"
    print(f"[{status}] {v.affirmation}")
    if v.correction:
        print(f"  → Correction: {v.correction}")

Patrún: ríomh agus struchtúrú

Comhcheangail rith cód le haghaidh ríomhaireachtaí agus aschuir struchtúrtha le haghaidh formáidithe:

class LigneFacture(BaseModel):
    description: str
    quantite: int
    prix_unitaire_ht: float
    montant_ht: float
    tva: float
    montant_ttc: float

class Facture(BaseModel):
    lignes: list[LigneFacture]
    total_ht: float
    total_tva: float
    total_ttc: float

response, parsed = client.chat.parse(
    model="grok-4.20-0309-reasoning",
    messages=[{
        "role": "user",
        "content": """Calculate the invoice:
        - 3x Pro License at 299 EUR excl. VAT (VAT 20%)
        - 1x Training at 1500 EUR excl. VAT (VAT 20%)
        - 12x Monthly Support at 49 EUR excl. VAT (VAT 20%)"""
    }],
    response_format=Facture,
    tools=[{"type": "code_interpreter"}]
)

print(f"Total excl. VAT: {parsed.total_ht} EUR")
print(f"Total incl. VAT: {parsed.total_ttc} EUR")

Ailtireacht píblíne láidre

Chun críocha táirgeachta, struchtúraigh do phíblíne i gcéimeanna:

# Step 1: Raw extraction
class ExtractionBrute(BaseModel):
    entites: list[str]
    dates: list[str]
    montants: list[str]

# Step 2: Enrichment
class EntiteEnrichie(BaseModel):
    nom: str
    type: str
    details: str

# Step 3: Validation
class ResultatValide(BaseModel):
    entites: list[EntiteEnrichie]
    score_qualite: float
    alertes: list[str]

Úsáideann gach céim glao ar leith le scéima oiriúnaithe. Simplíonn an cur chuige modúlach seo dífhabhtú agus monatóireacht.

Láimhseáil earráidí i dtáirgeadh

try:
    response, parsed = client.chat.parse(
        model="grok-4.20-0309-reasoning",
        messages=messages,
        response_format=MonSchema,
        tools=[{"type": "web_search"}]
    )
except Exception as e:
    # Fallback without web search
    response, parsed = client.chat.parse(
        model="grok-4.20-0309-reasoning",
        messages=messages,
        response_format=MonSchema
    )

Príomhphointí

  • Comhcheanglaíonn eastóscadh saibhrithe cuardach gréasáin agus aschuir struchtúrtha chun sonraí iomlána a fháil
  • Fíoraíonn tras-bhailíochtú fíricí le cuardach gréasáin
  • Cinntíonn rith cód ríomhaireachtaí cruinne i bpíblínte airgeadais
  • Struchtúraigh i gcéimeanna ar leith chun neart agus dífhabhtú a chinntiú
  • Pleanáil i gcónaí rogha mhalartach má theipeann ar uirlisí