File size: 1,452 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
from typing import List, Optional
from pydantic import BaseModel, Field
from src.llm_factory import get_llm

class User(BaseModel):
    """Details about a single user."""
    name: str = "Jane Doe"
    email: Optional[str] = None

class DocumentDetails(BaseModel):
    """A markdown document with details about a project."""
    user_items: list[User] = Field(
        description="A list with info about every user mentioned in this document"
    )
    license: Optional[str] = Field(
        description="What kind of license for this project, such as: GPL, MIT, Apache, etc."
    )
    urls: list[str] = Field(
        description="List of all URLs appearing in this document"
    )

llm = get_llm("ollama-llama3.1")
sllm = llm.as_structured_llm(DocumentDetails)

text = """
# ARC-Heavy

- [BARC Synthetic Examples](https://www.basis.ai/arc_interface/examples) - visualization and navigate the datasets and corresponding code for each puzzle.
- Repo: [github](https://github.com/xu3kev/BARC)
- Datasets: [huggingface](https://huggingface.co/collections/barc0/synthetic-arc-dataset-6725aa6031376d3bacc34f76)
- Users: Wen-Ding Li, Keya Hu, Carter Larsen, Yuqing Wu, Simon Alford, Caleb Woo, Spencer M. Dunn, Hao Tang, Michelangelo Naim, Dat Nguyen, Wei-Long Zheng,
Zenna Tavares, Yewen Pu, Kevin Ellis
- License: MIT
"""

response = sllm.complete(text)

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