firattamur / llmdantic Goto Github PK
View Code? Open in Web Editor NEWStructured Output Is All You Need!
License: MIT License
Structured Output Is All You Need!
License: MIT License
Is your feature request related to a problem? Please describe.
The tool is fantastic but it would be great to integrate its functionality with Agent frameworks like CrewAI or Autogen to control the outputs of the agents within the framework. This could potentially be game changing.
Describe the solution you'd like
Autogen and CrewAI allow you to create tools specific to an agent. We should be able to easily create an agent tool to check on outputs and ensure consistency of the agent in getting it's tasks done.
Describe alternatives you've considered
Currently my attempts are to use pydantic structures to achieve this but it doesn't seem to work well.
Description
Hey, seems like a fun library and tried to use example that's similar to one that's in readme (would be nice to have a script/notebook to check out library). I used AzureChatOpenAI as a llm.
The result (LLMdanticResult) have field with None and result's text have dict that's filled.
text - {"rewritten": "Miód to ulubiony przysmak Kubusia Puchatka."} - Honey is Winnie the Pooh's favorite treat.
output - rewritten=None
To Reproduce
Steps to reproduce the behavior:
# setup
llm = AzureChatOpenAI(
api_key=AZURE_API_KEY,
api_version=AZURE_API_VERSION,
azure_endpoint=RESOURCE_ENDPOINT,
azure_deployment=AZURE_DEPLOY,
temperature=0,
verbose=True,
)
class RewriteInput(BaseModel):
text: str
class RewriteOutput(BaseModel):
rewritten: str
@field_validator("rewritten")
def rewritten_text_must_be_in_polish(cls, v) -> bool:
""" Rewritten text must be in polish language """
...
@field_validator("rewritten")
def rewritten_text_must_not_be_empty(cls, v) -> bool:
"""Rewritten text cannot be empty """
...
@field_validator("rewritten")
def rewritten_text_must_be_short(cls, v) -> bool:
"""Rewritten must be less than 100 words """
...
config: LLMdanticConfig = LLMdanticConfig(
objective="Rewrite the polish text and convey the same meaning but with different phrasing and structure to ensure it is fresh and engaging.",
inp_schema=RewriteInput,
out_schema=RewriteOutput,
retry=3,
verbose=True,
)
llmdantic = LLMdantic(llm=llm, config=config)
# polish for Winnie the Pooh likes honey
data = RewriteInput(text="Kubuś Puchatek lubi miód.")
result = llmdantic.invoke(data)
print(result.text)
# output: {"rewritten": "Miód to ulubiony przysmak Kubusia Puchatka."} - Honey is Winnie the Pooh's favorite treat.
print(result.output)
# output: rewritten=None
Expected behavior
Output should have filled fields from llm
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.