space_25_hackathon_CNIEL / src /bon_livraison.py
François Mentec
moved schema and null values for additives
e4267eb
raw
history blame
1.22 kB
import os
import json
SYSTEM_PROMPT = """From this delivery note document, extract the following information by following these instructions.
The information is in French. Return the information in JSON format according to the schema below.
The details of each piece of information to be extracted are found in the description field of each item.
{{schema}}
"""
SCHEMA_PATH = os.path.join(os.path.dirname(__file__), "schema.json")
with open(SCHEMA_PATH, "r", encoding="utf-8") as f:
schema_content = f.read()
SYSTEM_PROMPT = SYSTEM_PROMPT.replace("{{schema}}", schema_content)
def extract_from_bl (client, document_source):
model = "mistral-medium-2508" # Mistral Medium 3.1
messages = [
{
"role": "system",
"content": SYSTEM_PROMPT,
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Extract data from this document"
},
document_source
]
}
]
chat_response = client.chat.complete(
model=model,
messages=messages,
response_format = {
"type": "json_object" #, "json_schema": JSON_SCHEMA
},
temperature=0.0,
)
return chat_response.choices[0].message.content