This gives the user the ability to pass in models for embeddings that are not
already defined in the library. Also more closely matches how the completions
API works.
As a user of this go SDK it was not immediately intuitive to me how to
correctly utilize the function calling capability of GPT4
(https://platform.openai.com/docs/guides/function-calling). While the
aformentioned link provides a helpful example written in python, I
initially tripped over how to correclty translate the specification of
function arguments when usingthis go SDK.
To make it easier for others in the future this commit adds a
completion-with-tool example showing how to correctly utilize the
function calling capability of GPT4 using this SDK end-to-end in a
CreateChatCompletion() sequence.
* Add support for multi part chat messages
OpenAI has recently introduced a new model called gpt-4-visual-preview,
which now supports images as input. The chat completion endpoint accepts
multi-part chat messages, where the content can be an array of structs
in addition to the usual string format.
This commit introduces new structures and constants to represent
different types of content parts. It also implements the json.Marshaler
and json.Unmarshaler interfaces on ChatCompletionMessage.
* Add ImageURLDetail and ChatMessagePartType types
* Optimize ChatCompletionMessage deserialization
* Add ErrContentFieldsMisused error
* fix test server setup:
- go map access is not deterministic
- this can lead to a route: /foo/bar/1 matching /foo/bar before matching /foo/bar/1 if the map iteration go through /foo/bar first since the regex match wasn't bound to start and end anchors
- registering handlers now converts * in routes to .* for proper regex matching
- test server route handling now tries to fully match the handler route
* add missing /v1 prefix to fine-tuning job cancel test server handler
* add create message call
* add messages list call
* add get message call
* add modify message call, fix return types for other message calls
* add message file retrieve call
* add list message files call
* code style fixes
* add test for list messages with pagination options
* add beta header to msg calls now that #545 is merged
* Update messages.go
Co-authored-by: Simone Vellei <henomis@gmail.com>
* Update messages.go
Co-authored-by: Simone Vellei <henomis@gmail.com>
* add missing object details for message, fix tests
* fix merge formatting
* minor style fixes
---------
Co-authored-by: Simone Vellei <henomis@gmail.com>
* fix test server setup:
- go map access is not deterministic
- this can lead to a route: /foo/bar/1 matching /foo/bar before matching /foo/bar/1 if the map iteration go through /foo/bar first since the regex match wasn't bound to start and end anchors
- registering handlers now converts * in routes to .* for proper regex matching
- test server route handling now tries to fully match the handler route
* add missing /v1 prefix to fine-tuning job cancel test server handler
* fix ToolChoiche typo
* add tool_call_id to ChatCompletionMessage
* add /chat system_fingerprint response field
* check empty ToolCallID JSON marshaling
and add omitempty for tool_call_id
* messages also required; don't omitempty
* add Type to ToolCall, required by the API
* fix test, omitempty for response_format ptr
* fix casing of role values in comments