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

fix: Ensure JSON response is properly parsed in generate function when format is set to 'json' #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wyy511511
Copy link

@wyy511511 wyy511511 commented Jun 28, 2024

When I set format as "json", my response looks like this:

{'model': 'llama3', 'created_at': '2024-06-28T05:44:32.12715Z', 'response': '{"results": [\n{\n"entity_type": "IMEI",\n"text": "06-184755-866851-3"\n}\n]}\n\n \n\n ', 'done': True, 'done_reason': 'stop', 'context': [], 'total_duration': 4528553708, 'load_duration': 2316500, 'prompt_eval_count': 437, 'prompt_eval_duration': 2743245000, 'eval_count': 32, 'eval_duration': 1781380000}

As you can notice, although it indeed returns a JSON object, the previous code parses the 'response' as a string (hence the presence of \n characters and type checking result).

After I added some code to correctly parse the JSON response, the response now looks like this:

{'model': 'llama3', 'created_at': '2024-06-28T09:16:56.417739Z', 'response': {'results': [{'entity_type': 'IMEI', 'text': '06-184755-866851-3'}]}, 'done': True, 'done_reason': 'stop', 'context':

It becomes cleaner and matches my expected format.

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.

1 participant