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

Chore: adding required to ChatCompletionFunctionCallOptionParam enum #215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/OpenAI/Public/Models/ChatQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
/// We generally recommend altering this or top_p but not both.
/// Defaults to 1
public let temperature: Double?
/// Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. Specifying a particular function via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
/// Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. required means the model must call one or more tools. Specifying a particular function via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.
/// none is the default when no functions are present. auto is the default if functions are present
public let toolChoice: Self.ChatCompletionFunctionCallOptionParam?
/// A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
Expand Down Expand Up @@ -614,6 +614,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
case none
case auto
case function(String)
case required

public func encode(to encoder: Encoder) throws {
switch self {
Expand All @@ -627,6 +628,9 @@ public struct ChatQuery: Equatable, Codable, Streamable {
var container = encoder.container(keyedBy: Self.ChatCompletionFunctionCallNameParam.CodingKeys.self)
try container.encode("function", forKey: .type)
try container.encode(["name": name], forKey: .function)
case .required:
var container = encoder.singleValueContainer()
try container.encode(CodingKeys.required.rawValue)
}
}

Expand All @@ -638,6 +642,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
case none = "none"
case auto = "auto"
case function = "name"
case required = "required"
}

private enum ChatCompletionFunctionCallNameParam: Codable, Equatable {
Expand Down