Easpórtáil agus Aicmiú Eintiteas
Ar an leathanach seo
Príomhchásanna úsáide
Bíonn aschuir struchtúrtha thar barr i dhá chatagóir tasc: faisnéis a eastóscadh ó théacs neamhstruchtúrtha, agus ábhar a aicmiú. Tá an dá chás úsáide seo lárnach do chuid is mó feidhmchlár AI fiontraíochta.
Eastóscadh eintiteas ainmnithe
Baineann eastóscadh eintiteas le príomhghnéithe i dtéacs a aithint agus a chatagóiriú: daoine, cuideachtaí, suíomhanna, dátaí, méideanna, agus mar sin de.
from pydantic import BaseModel
from typing import Literal
class Entite(BaseModel):
texte: str
type: Literal[
"person", "company", "location",
"date", "amount", "product"
]
contexte: str
class ExtractionEntites(BaseModel):
entites: list[Entite]
nombre_total: int
langue_detectee: str
response, parsed = client.chat.parse(
model="grok-4.20-0309-reasoning",
messages=[{
"role": "user",
"content": """Extract all entities from this text:
On March 15, 2026, Mistral AI raised €600 million
from General Catalyst. Arthur Mensch, the CEO based in
Paris, plans to launch Mistral Large 3 by June."""
}],
response_format=ExtractionEntites
)
for e in parsed.entites:
print(f"[{e.type}] {e.texte} — {e.contexte}")
Aicmiú ábhair
San aicmiú, sannann tú catagóirí réamhshainithe d’ábhar. Ráthaíonn aschuir struchtúrtha nach dtugann an tsamhail ar ais ach catagóirí bailí amháin.
class ClassificationEmail(BaseModel):
categorie: Literal[
"sales", "support", "billing",
"partnership", "application", "spam", "other"
]
sous_categorie: str
priorite: Literal["low", "medium", "high", "urgent"]
sentiment: Literal["positive", "neutral", "negative"]
action_requise: bool
resume: str
response, parsed = client.chat.parse(
model="grok-4.20-0309-reasoning",
messages=[{
"role": "user",
"content": """Classify this email:
Subject: Urgent billing issue
Hello, our latest invoice #2847 contains an error.
The amount shown is €3,500 instead of the agreed €2,800.
Please correct this quickly."""
}],
response_format=ClassificationEmail
)
print(f"Category: {parsed.categorie}") # "billing"
print(f"Priority: {parsed.priorite}") # "high"
print(f"Action required: {parsed.action_requise}") # True
Aicmiú il-lipéad
Nuair is féidir le hábhar bheith i roinnt catagóirí ag an am céanna:
class ClassificationArticle(BaseModel):
titre: str
themes: list[str]
audience_cible: list[Literal[
"developers", "managers", "data_scientists",
"designers", "executives", "general_public"
]]
niveau_technique: Literal["beginner", "intermediate", "advanced"]
mots_cles_seo: list[str]
temps_lecture_minutes: int
Eastóscadh sonraí táblacha
Tiontaigh téacs ina shonraí struchtúrtha in-ghníomhaithe:
class LigneCommande(BaseModel):
reference: str
designation: str
quantite: int
prix_unitaire: float
montant_total: float
class BonCommande(BaseModel):
numero: str
date: str
fournisseur: str
lignes: list[LigneCommande]
montant_ht: float
tva: float
montant_ttc: float
response, parsed = client.chat.parse(
model="grok-4.20-0309-reasoning",
messages=[{
"role": "user",
"content": """Extract data from this purchase order:
PO-2026-0847 dated 03/28/2026 — Supplier: TechParts SAS
REF-001 | USB-C Cable 2m | x50 | €3.20
REF-002 | HDMI Adapter | x20 | €12.50
REF-003 | 4-port USB Hub | x10 | €24.90"""
}],
response_format=BonCommande
)
Anailís mhothúcháin ghraíneach
Seachas dearfach/diúltach simplí, struchtúraigh anailís iomlán:
class AspectSentiment(BaseModel):
aspect: str
sentiment: Literal["very_positive", "positive", "neutral", "negative", "very_negative"]
mention: str
class AnalyseAvis(BaseModel):
note_globale: float
sentiment_global: str
aspects: list[AspectSentiment]
points_forts: list[str]
points_faibles: list[str]
recommande: bool
Príomhphointí
- Aithníonn eastóscadh eintiteas daoine, suíomhanna, dátaí agus méideanna i dtéacs saor
- Forghníomhaíonn an t-aicmiú catagóirí réamhshainithe ag baint úsáide as
Literalagusenum - Úsáideann aicmiú il-lipéad liostaí de
Literal - Tiontaíonn eastóscadh táblach téacs neamhstruchtúrtha ina shonraí in-ghníomhaithe
- Is féidir le hanailís mhothúcháin bheith graíneach le gnéithe aonair
- Oibríonn na patrúin seo go léir le
parse()nóresponse_format