structured llm outputs
Project description
struct-gpt
structured llm outputs
Usage
from struct_gpt import OpenAiBase
from pydantic import Field
class SentimentSchema(OpenAiBase):
"""
Determine the sentiment of the given text:
{content}
"""
sentiment: str = Field(description="Either -1, 0, or 1.")
positive = SentimentSchema.create(content="I love pizza!")
print(f"{positive = }") # positive = SentimentSchema(sentiment='1')
class SentimentAnalysis(OpenAiBase):
"""
Determine the sentiment of each word in the following: {text}
"""
sentiment: Mapping[str, SentimentSchema]
analysis = SentimentAnalysis.create(text="I love the beautiful scenery, but the long hike was exhausting.")
print(analysis.json(indent=2))
outputs:
{
"sentiment": {
"I": {
"sentiment": "1"
},
"love": {
"sentiment": "1"
},
"the": {
"sentiment": "0"
},
"beautiful": {
"sentiment": "1"
},
"scenery,": {
"sentiment": "1"
},
"but": {
"sentiment": "0"
},
"long": {
"sentiment": "-1"
},
"hike": {
"sentiment": "-1"
},
"was": {
"sentiment": "0"
},
"exhausting.": {
"sentiment": "-1"
}
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
struct_gpt-0.1.0.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for struct_gpt-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 301f0ca6d52136fedda67aa04d41d8b23487c3fe95d6577af7c0ed61a7f4bece |
|
MD5 | 043a7529bff068bd501a3d1e98d89777 |
|
BLAKE2b-256 | a49a872a930fee0e53b22ab37feb8a98ddfcd790c0389af2529457d073da6f92 |