-
Notifications
You must be signed in to change notification settings - Fork 95
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
Open-source LLM from HuggingFace Agent Support for json output parsing #130
base: main
Are you sure you want to change the base?
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.
i am very sorry for the delayed review and thank you for making this improvement.
i did a pretty bad job for this one :)
once the comment is addressed, i would be more than happy to approve it
|
||
return response | ||
|
||
@staticmethod | ||
def _fix_message(clean_text: str) -> UserMessage: |
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.
can you make this is a helper function inside of _attempt_fix_and_generate
?
@@ -55,30 +54,94 @@ def format_output(self) -> Dict[str, Any]: | |||
|
|||
|
|||
class AgentOutputParser(BaseModel): |
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.
i think there is a way to simplify this logics inside of this function
first json load, if run into exception, fix and generate, format into message for load_json_output
, decrease retry, call load_json_output again,
if no exception, just return
No worries at all! I will work on your comments, thank you so much |
Hi,
I added HuggingFace
text-generation
models support, which was failing because of the use ofChatOpenAI
(OpenAI API Key error occurs) whenConversationalAgent
applies json output parsing throughConvoJSONOutputParser
that usesload_json_output
. To do that, instead of calling ChatOpenAI in theexcept
part of theload_json_output
, I am passing whatever llm model is given, either ChatOpenAI or HuggingFaceTextGenerationModel, just passing the provided llm inside to make it more general.I also added
max_retry
to set the amount of retry that recursive function being applied to get the correct output that JSON parseable._fix_message
needs to be improved to get better responses from models each time it is called. I added it as TO DO as well as a comment there.After
max_retry
number is reached and if we couldn't get the proper json parseable response, I raised ValueError to inform user that selected open-source model is not good enough or is not able to generate json parseable output.I checked this modified code with ChatOpenAI and it is working with no issue. But, there is a lot of things to do to improve and set the boundaries for the open-source model use. This may mean one needs to specify and allow some specific open-source models only. Also, some model optimizations can be applied.