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.")
print(SentimentSchema.create(content="I love pizza!").json())
outputs:
{
"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.2.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for struct_gpt-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 521cfe670df63f49290698ec4e499f4cd80fe97e97ad0fb5279ce0eaca85aef7 |
|
MD5 | e272c976691b96cff9264a6940bdac6e |
|
BLAKE2b-256 | 11f77c650aab63905cb5b168b0accf0d29ce325cb533a7fbb94ccc7a4cd889ed |