Skip to content

[FEATURE]: Add MistralAI Structured Output feature #542

Description

@skutaada

Description

Description

MistralAI supports custom structured output. It would be useful to also implement it in neo4j-graphrag. How to use it with mistralai python package:

import os
from mistralai.client import Mistral
from pydantic import BaseModel

api_key = os.environ["MISTRAL_API_KEY"]
model = "ministral-8b-latest"

client = Mistral(api_key=api_key)

class Book(BaseModel):
    name: str
    authors: list[str]

chat_response = client.chat.parse(
    model=model,
    messages=[
        {
            "role": "system",
            "content": "Extract the books information."
        },
        {
            "role": "user",
            "content": "I recently read 'To Kill a Mockingbird' by Harper Lee."
        },
    ],
    response_format=Book,
    max_tokens=256,
    temperature=0
)

print(chat_response.choices[0].message.content) // for JSON output
print(chat_response.choices[0].message.parsed) // for Pydantic model output

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions