File size: 555 Bytes
6369972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
python -m src.proof_of_concepts.run_extract_one_user
"""
import json
from typing import List, Optional
from pydantic import BaseModel
from src.llm_factory import get_llm

class User(BaseModel):
    id: int
    name: str = "Jane Doe"

llm = get_llm("ollama-llama3.1")
# llm = get_llm("openrouter-paid-gemini-2.0-flash-001")
sllm = llm.as_structured_llm(User)

text = "location=unspecified, user id=42, role=agent, name=Simon, age=30"

response = sllm.complete(text)

json_response = json.loads(response.text)
print(json.dumps(json_response, indent=2))