Responses
When making queries via
HTTP Requests,
the OpenAI Python Package,
and the OpenAI NodeJS Package,
then the full ChatCompletion
is returned, as per the
OpenAI Standard.
Firstly, lets take a look at how we can format these returned ChatCompletion
instances more elegantly, so we can easily examine the contents.
Formatting
As a recap, requests can be made directly to our REST API as follows:
The response is printed on a single line by default, which is not very human-readable:
The jq package can be used to render the returned
ChatCompletion
much more elegantly in the terminal:
Again, as a recap, requests can also be made via the OpenAI Python Package as follows:
As with the REST API request, the response is printed on a single line by default:
The rich package can be used to print the chat completion much more elegantly:
Finally, again as a recap, queries to the OpenAI NodeJS Package can be made as follows:
The response is printed as follows:
Unify Python Client
In order to make things more user friendly, by default the
Unify Python Client
only returns the message content of the first choice among the returned choices
.
In Python, this is indexed like so: response.choices[0].message.content
The full ChatCompletion
can also easily be returned in the Python client, by setting
return_full_completion=True
, either in the constructor
(making it a Default Argument),
or in the generate
method, as below:
Again, we can make the ChatCompletion
output more concise by setting the mode
unify.set_repr_mode("concise")
. Aside from removing the None
fields, "concise"
mode also removes all fields apart from choices
:
The reason we omit all other fields when visualizing ChatCompletion
instances in
"concise"
mode is because Unify as a platform is primarily built for evaluations.
From this perspective, the focus is on tracking the input-output behaviour of LLMs.
We already explained our definition of a prompt in the
Prompts section.
As a recap, our definition of a prompt is as follows:
A prompt is a json object containing all arguments in the OpenAI chat completions request body which impact the output.
Similarly, when it comes to evaluating LLM responses, we’re only concerned with the
aspects in the ChatCompletion
returned which are are impacted by the input.
Looking through OpenAI’s
ChatCompletion description,
we can see that the only field which is affected by the input is the choices
field.
As such, everything else returned in the ChatCompletion
instance is irrelevant
from the perspective of evaluations. As before, even when "concise"
mode is set,
you can view the full ChatCompletion
instance with all meta data like so:
Broader Usage
Aside from being the default response type from the
chat/completions
endpoint, ChatCompletion
instances are also what are logged in the platform
(see Logging section) and cached
(see Caching section).
This section is mainly to give a quick introduction to the ChatCompletion
return type,
explain how to print this in a human-readable way when making queries via the various
options available, and explain some of the design decisions we’ve made for our own
Python client.
To learn more about what each field represents, you should consult OpenAI’s documentation. If anything is unclear, let us know on discord! 👾