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

Fix: Rename redundant type names #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions Sources/OpenAI/Public/Models/ChatQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ public struct ChatQuery: Equatable, Codable, Streamable {

public enum ChatCompletionMessageParam: Codable, Equatable {

case system(Self.ChatCompletionSystemMessageParam)
case user(Self.ChatCompletionUserMessageParam)
case assistant(Self.ChatCompletionAssistantMessageParam)
case tool(Self.ChatCompletionToolMessageParam)
case system(Self.SystemMessageParam)
case user(Self.UserMessageParam)
case assistant(Self.AssistantMessageParam)
case tool(Self.ToolMessageParam)

public var content: Self.ChatCompletionUserMessageParam.Content? { get {
public var content: Self.UserMessageParam.Content? { get {
switch self {
case .system(let systemMessage):
return Self.ChatCompletionUserMessageParam.Content.string(systemMessage.content)
return Self.UserMessageParam.Content.string(systemMessage.content)
case .user(let userMessage):
return userMessage.content
case .assistant(let assistantMessage):
if let content = assistantMessage.content {
return Self.ChatCompletionUserMessageParam.Content.string(content)
return Self.UserMessageParam.Content.string(content)
}
return nil
case .tool(let toolMessage):
return Self.ChatCompletionUserMessageParam.Content.string(toolMessage.content)
return Self.UserMessageParam.Content.string(toolMessage.content)
}
}}

Expand Down Expand Up @@ -166,7 +166,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
}
}}

public var toolCalls: [Self.ChatCompletionAssistantMessageParam.ChatCompletionMessageToolCallParam]? { get {
public var toolCalls: [Self.AssistantMessageParam.ToolCallParam]? { get {
switch self {
case .assistant(let assistantMessage):
return assistantMessage.toolCalls
Expand All @@ -179,7 +179,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
role: Role,
content: String? = nil,
name: String? = nil,
toolCalls: [Self.ChatCompletionAssistantMessageParam.ChatCompletionMessageToolCallParam]? = nil,
toolCalls: [Self.AssistantMessageParam.ToolCallParam]? = nil,
toolCallId: String? = nil
) {
switch role {
Expand Down Expand Up @@ -208,7 +208,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {

public init?(
role: Role,
content: [ChatCompletionUserMessageParam.Content.VisionContent],
content: [UserMessageParam.Content.VisionContent],
name: String? = nil
) {
switch role {
Expand All @@ -233,7 +233,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
}

private init?(
content: Self.ChatCompletionUserMessageParam.Content,
content: Self.UserMessageParam.Content,
role: Role,
name: String? = nil
) {
Expand All @@ -248,7 +248,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
role: Role,
content: String? = nil,
name: String? = nil,
toolCalls: [Self.ChatCompletionAssistantMessageParam.ChatCompletionMessageToolCallParam]? = nil
toolCalls: [Self.AssistantMessageParam.ToolCallParam]? = nil
) {
if role == .assistant {
self = .assistant(.init(content: content, name: name, toolCalls: toolCalls))
Expand Down Expand Up @@ -290,7 +290,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
case tool
}

public struct ChatCompletionSystemMessageParam: Codable, Equatable {
public struct SystemMessageParam: Codable, Equatable {
public typealias Role = ChatQuery.ChatCompletionMessageParam.Role

/// The contents of the system message.
Expand All @@ -315,7 +315,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
}
}

public struct ChatCompletionUserMessageParam: Codable, Equatable {
public struct UserMessageParam: Codable, Equatable {
public typealias Role = ChatQuery.ChatCompletionMessageParam.Role

/// The contents of the user message.
Expand Down Expand Up @@ -486,7 +486,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
}
}

public struct ChatCompletionAssistantMessageParam: Codable, Equatable {
public struct AssistantMessageParam: Codable, Equatable {
public typealias Role = ChatQuery.ChatCompletionMessageParam.Role

//// The role of the messages author, in this case assistant.
Expand All @@ -496,12 +496,12 @@ public struct ChatQuery: Equatable, Codable, Streamable {
/// The name of the author of this message. `name` is required if role is `function`, and it should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
public let name: String?
/// The tool calls generated by the model, such as function calls.
public let toolCalls: [Self.ChatCompletionMessageToolCallParam]?
public let toolCalls: [Self.ToolCallParam]?

public init(
content: String? = nil,
name: String? = nil,
toolCalls: [Self.ChatCompletionMessageToolCallParam]? = nil
toolCalls: [Self.ToolCallParam]? = nil
) {
self.content = content
self.name = name
Expand All @@ -515,7 +515,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
case toolCalls = "tool_calls"
}

public struct ChatCompletionMessageToolCallParam: Codable, Equatable {
public struct ToolCallParam: Codable, Equatable {
public typealias ToolsType = ChatQuery.ChatCompletionToolParam.ToolsType

/// The ID of the tool call.
Expand Down Expand Up @@ -543,7 +543,7 @@ public struct ChatQuery: Equatable, Codable, Streamable {
}
}

public struct ChatCompletionToolMessageParam: Codable, Equatable {
public struct ToolMessageParam: Codable, Equatable {
public typealias Role = ChatQuery.ChatCompletionMessageParam.Role

/// The contents of the tool message.
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAI/Public/Models/ChatResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ extension ChatQuery.ChatCompletionMessageParam {
}
}

extension ChatQuery.ChatCompletionMessageParam.ChatCompletionUserMessageParam.Content {
extension ChatQuery.ChatCompletionMessageParam.UserMessageParam.Content {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
do {
Expand Down