-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement outlines converter model for structured output (#1211) #1318
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MuggleJinx! I have added two comments for reference, please have a look when possible.
Co-authored-by: Harry Ye <116691547+harryeqs@users.noreply.github.com>
Thanks @harryeqs, updated! |
Thanks @MuggleJinx ! |
# 1. Using a Pydantic model | ||
class Temperature(BaseModel): | ||
location: str | ||
date: str | ||
temperature: float | ||
|
||
|
||
output = model.convert_json( | ||
"Today is 2023-09-01, the temperature in Beijing is 30 degrees.", | ||
output_schema=Temperature, | ||
) | ||
|
||
print(output) | ||
''' | ||
location='Beijing' date='2023-09-01' temperature=30.0 | ||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the output format use '=' @Wendong-Fan , not {'location':'Beijing'}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I split the it into 2 functions, one returns pydantic object, one returns the internal dict object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MuggleJinx ! Overall LGTM, left some comments below
camel/schemas/outlines_converter.py
Outdated
|
||
from typing import Any, Callable, List, Literal, Type, Union | ||
|
||
import outlines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outlines is not necessary packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sry, it is needed in outlines.generate.regex
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can move import outlines
within the class to make it optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @MuggleJinx ! left some comments below and added one commit here:87ccb62 feel free to review and check, let me know if there's any issue~
@@ -67,6 +67,7 @@ sentencepiece = { version = "^0", optional = true } | |||
opencv-python = { version = "^4", optional = true } | |||
|
|||
# tools | |||
outlines = { version = "^0.1.7", optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add it to tool
and all
list
) | ||
|
||
print(output) | ||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unify by using "
instead of '
camel/schemas/outlines_converter.py
Outdated
|
||
from typing import Any, Callable, List, Literal, Type, Union | ||
|
||
import outlines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can move import outlines
within the class to make it optional
camel/schemas/outlines_converter.py
Outdated
case _: | ||
raise ValueError(f"Unsupported platform: {platform}") | ||
|
||
def convert_regex(self, content: str, regex_pattern: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing return type hint, even it could be Any
camel/schemas/outlines_converter.py
Outdated
) | ||
return json_generator(content) | ||
|
||
def convert_type(self, content: str, type_name: type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing return type hint, same for other methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file naming, use _
instead of -
Description
Integrate outlines library to produce the structured output.
Motivation and Context
Close #1211.
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Implemented Tasks
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!