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

Added additional parameters to send() function #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ben-meeker
Copy link

Added additional updated parameters to ChatCompletionRequest to enable additional functionality, such as tools, streams, and response format.

Added extensive list of parameter additions to ChatCompletionRequest
Fixed Parallel_Tool_Calls triggering unexpectedly by adding `omitempty` to json tag
This allows for structs to be omitted if empty. 

E.g. Stream_Options does not marshal, fixing error where Stream_Options returns an error when neither Stream_Options or Stream are set.
@ben-meeker ben-meeker mentioned this pull request Jul 26, 2024
Copy link

@kaashmonee kaashmonee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem like we actually change the SimpleSend function though? is PR meant to be just model updates? just wanted to get a bit of context since i found this in an issue where i was requesting threads: #11 (comment)

// Options
// Type: "json_object" to enable JSON mode.
// Type: "text" to enable plain text mode.
Response_Format *ResponseFormat `json:"response_format,omitempty"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Just use camelcase (here and elsewhere)? ResponseFormat

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the underscore naming convention to match the pattern set by Top_P on line 62 of the chat.go file. I figured it was best to follow what was already in place. That way, it matches the API parameters OpenAI accepts more clearly as well.

I do see your nit side though!! I'm a big camelcase fan 😄

// (Optional - default: null)
// A list of tools the model may call
// Provide a list of functions the model may generate JSON inputs for. 128 functions max supported.
Tools *[]Tool `json:"tools,omitempty"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to avoid pointers since i keep running into nil dereference issues haha :(

Suggested change
Tools *[]Tool `json:"tools,omitempty"`
Tools []Tool `json:"tools,omitempty"`

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of pointers here is necessary, since you can set the value of a pointer to nil, but not the value of a custom struct. That means that if it isn't a pointer, then the json tag 'omitempty' won't function, and it will send that parameter in each call, resulting in errors!

This is the best way I know of the resolve this issue. But I'm very open to other solutions that resolve the omitempty issue!

// (Optional - default: null)
// Only set this when Stream is True
// Set an additional chunk to stream before data: [DONE] message.
Stream_Options *StreamOptions `json:"stream_options,omitempty"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here: want to avoid pointers to avoid possible nil dereference issues haha (but should still be able to check if empty since go zeroes out the struct if we don't add anything to it)

Suggested change
Stream_Options *StreamOptions `json:"stream_options,omitempty"`
Stream_Options StreamOptions `json:"stream_options,omitempty"`

@ben-meeker
Copy link
Author

it doesn't seem like we actually change the SimpleSend function though? is PR meant to be just model updates? just wanted to get a bit of context since i found this in an issue where i was requesting threads: #11 (comment)

You are right here -- I mislabeled my changes. I didn't actually edit the 'Send' function, but rather added fields to the 'ChatCompletionRequest' struct to allow for additional parameters to be passed in the call.

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

Successfully merging this pull request may close these issues.

2 participants