Hacker News new | ask | show | jobs
by mittermayr 873 days ago
I have a suggestion that would make this very valuable for anyone starting in the field (part of which you already have implemented, great!):

Provide various templates for both pre-instructions as well as post-processing prompts. Like, some "tested" prompts that ensure (as best as possible) that the output is in certain formats (JSON, a list, a restricted CSV set, etc.), or that the input will ensure (as best as possible at least) to prevent basic jailbreaks from the main prompt.

It would take me a long time to get up to speed to what people working with ChatGPT every day have already figured out to work best in warming up GPT with a prompt as well as ensuring that the output doesn't escalate into something unexpected. Having those (reliable) templates would be fantastic for anyone starting!

2 comments

For API responses that require valid JSON - you can make requests in JSON mode - https://platform.openai.com/docs/api-reference/chat/create#c...

Edit: url to API docs

One thing I found helps if I want the responses to be valid JSON, seems to work:

where result contains all of the <data expected> and the result is valid JSON. Do NOT under any circumstances deviate from this format! Ensure all of the value <data expected> are complete, do not leave ANY of them out. Do not add ANY other text to your answer except for the JSON result.

I found that just asking for valid JSON didn't always work out as expected (e.g. gpt-4 API would add formatting etc., so I became more and more of a micromanager!

Nice! Thanks for the pointer
It does not really need to be that intense. I get very reliable results from the gpt4 api using this template:

  You are a data cleaner and JSON formatter
  Take the input data and format it into attributes
  Your output will be fed directly to `json.loads`
  
  Example input:
  foo bar baz bat
  
  Example format:
  {
     "string": "foo bar baz bat", 
  }
You can give it multiple input examples, too. I often use a "minimum viable" example so that it knows it's ok to return empty attributes instead of hallucinating when the data is sparse.