mirror of
https://github.com/hanzoai/engine.git
synced 2026-11-20 14:17:52 +00:00
* Initial * Fxies * Faster * Even faster * tmp disable for constrained * Support mtp + grammars * Refactor * Refactor * Tweaks and non pagd support * Batching support * Docs * Docs * SUpport on normal * Tweaks * Proper non paged cahe impl * Rework * Trace * Change * Change * even more * even more * even more * even more * even more * even more * even more * even more * even more * even more * even more * even more * Cleanup. * Finalize
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from enum import Enum
|
|
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from openai import OpenAI
|
|
|
|
client = OpenAI(api_key="foobar", base_url="http://localhost:1234/v1/")
|
|
|
|
|
|
class AirplaneType(str, Enum):
|
|
commercial = "commercial"
|
|
cargo = "cargo"
|
|
private = "private"
|
|
|
|
|
|
class Airplane(BaseModel):
|
|
id: int = Field(
|
|
..., title="Airplane ID", description="Unique identifier for the airplane"
|
|
)
|
|
model: str = Field(..., title="Model", min_length=1, max_length=100)
|
|
manufacturer: str = Field(..., title="Manufacturer", min_length=1, max_length=100)
|
|
type: AirplaneType = Field(default=AirplaneType.commercial, title="Airplane Type")
|
|
capacity: Optional[int] = Field(None, title="Passenger Capacity", ge=1, le=1000)
|
|
|
|
|
|
class Fleet(BaseModel):
|
|
fleet_name: str = Field(..., title="Fleet Name", min_length=1, max_length=50)
|
|
airplanes: List[Airplane] = Field(
|
|
..., title="Fleet Airplanes", min_length=1, max_length=3
|
|
)
|
|
|
|
|
|
completion = client.beta.chat.completions.parse(
|
|
model="default",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "Can you please make me a fleet of airplanes?",
|
|
}
|
|
],
|
|
frequency_penalty=1.0,
|
|
top_p=0.1,
|
|
temperature=0,
|
|
response_format=Fleet,
|
|
)
|
|
|
|
event = completion.choices[0].message.parsed
|
|
print(event)
|