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

could you provide an easy way to force output as json? #1456

Open
fancy45daddy opened this issue Sep 9, 2024 · 1 comment
Open

could you provide an easy way to force output as json? #1456

fancy45daddy opened this issue Sep 9, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@fancy45daddy
Copy link

current I use

preprompt:'only output json. Do not output anything that is not json. Do not use markdown format. Must begin with {.'

But llama is not smart enough to output json form. It always begin with Here is the JSON answer or begin with ```(markdown format) for give me unvalid json string.

It seems preprompt is not enough to force json format. Could you provide an easy way to output just json. Or maybe the method is in tools.

@fancy45daddy fancy45daddy added the enhancement New feature or request label Sep 9, 2024
@dlavrenuek
Copy link
Contributor

The prompt depends on the model you are using, different models can return different results for the same prompt. You can find some good general information about prompt engineering here: https://www.promptingguide.ai/introduction/tips.

As for returning json, you have to state that the output should be returned as "valid JSON" and that no additional text other than json must be included. Also you need to tell what format the returned json should have. Following works with Llama:

List 5 funny jokes. Format the output as valid JSON array, each element of the array should contain the joke type in property "type" and the joke in property "joke". The output must not contain any other text than the JSON.

Using the format in the prompt as example:

List 5 funny jokes. Format the output as valid JSON array. The output must not contain any other text than the JSON. Example of the returned format: "[{"type": "sarcasm", "joke":"some sarcastic joke"}]"

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

No branches or pull requests

2 participants