Resolved : Prompt Formatting

#6
by Tonic - opened
This comment has been hidden (marked as Resolved)
This comment has been hidden (marked as Resolved)
This comment has been hidden (marked as Resolved)
Tonic changed discussion title from Transformers Code , CPU doesnt resolve , or resolves too slowly to Strange and Poor Performance πŸ€·πŸ»β€β™‚οΈ

Hey! I noticed that you didn't specify a JSON schema in your system prompt. I replicated your prompt and added JSON schema, and here are the results:

(I'm using the ollama example as template)

from datetime import date
from ollama import chat
from pydantic import BaseModel


class RegistrationFee(BaseModel):
    early_bird_price: float
    regular_price: float
    early_bird_deadline: date


class ConferenceDetails(BaseModel):
    event_start_date: date
    event_end_date: date
    location: str
    registration_fees: RegistrationFee
    contact_email: str


reasoning_trace = """
The conference will be held on June 10-12, 2024 at the Grand Hotel in San Francisco.
Registration fee is $500 for early bird (before May 1) and $650 for regular registration.
Contact [email protected] for questions.
"""

response = chat(
    messages=[
        {
            "role": "system",
            "content": f"You are a helpful assistant that understands and translates text to JSON format according to the following schema. {ConferenceDetails.model_json_schema()}",
        },
        {
            "role": "user",
            "content": reasoning_trace,
        },
    ],
    model="hf.co/osmosis-ai/Osmosis-Structure-0.6B",
    format=ConferenceDetails.model_json_schema(),
)

answer = ConferenceDetails.model_validate_json(response.message.content)
print(answer.model_dump_json(indent=2))

Output:

{
  "event_start_date": "2024-05-10",
  "event_end_date": "2024-05-12",
  "location": "Grand Hotel, San Francisco",
  "registration_fees": {
    "early_bird_price": 500.0,
    "regular_price": 650.0,
    "early_bird_deadline": "2024-05-01"
  },
  "contact_email": "[email protected]"
}

Let me know if you still run into issues after specifying the schema.

This comment has been hidden (marked as Resolved)

woop woop , works perfect, i'm very happy

very good work here !

Tonic changed discussion status to closed
Tonic changed discussion title from Strange and Poor Performance πŸ€·πŸ»β€β™‚οΈ to Resolved : Prompt Formatting

Sign up or log in to comment