Рет қаралды 8,205
UPDATE: in openAI DevDay, they announced new functionality to improve consistency of JSON output. check out the details here: platform.opena...
Colab Workbook with code: colab.research...
Includes few-shot learning with function calling demo!
Using OpenAI's Chat Completion API, we explore two different ways of getting structured JSON output out from GPT rather than a blob of free text - For example, if you wanted to get the output returned as a list or as a dictionary of key-value pairs or even more completed schemas!
In the first method, we just use prompt engineering to describe what we want the output schema to be in free text. However, this gets a bit hairy when the schema gets more complicated. So as an alternative, we also explore a second method.
In this second method, we use function calling. But instead of using it to actually call a function, we just take the arguments as our output.
However, when the schema gets more complicated, GPT has trouble filling in all of the required arguments. So we also show you how to do "Few-Shot Learning" for function calling to teach GPT a few real worked examples to improve it's ability to consistently deliver the output you want!