Skip to content
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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tugrulguner
Copy link

Hi,

I added HuggingFace text-generation models support, which was failing because of the use of ChatOpenAI (OpenAI API Key error occurs) when ConversationalAgent applies json output parsing through ConvoJSONOutputParser that uses load_json_output. To do that, instead of calling ChatOpenAI in the except part of the load_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.

@tugrulguner
Copy link
Author

anyone, any comments on this? @tiangolo @yyiilluu

Copy link
Contributor

@yyiilluu yyiilluu left a 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:
Copy link
Contributor

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):
Copy link
Contributor

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

@tugrulguner
Copy link
Author

No worries at all! I will work on your comments, thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants