Skip to content

Commit

Permalink
Explicit lack of support for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
andgordio committed Aug 28, 2024
1 parent 56ea693 commit 54c7a2e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Sources/OpenAI/Public/Models/ChatQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -784,20 +784,31 @@ public struct ChatQuery: Equatable, Codable, Streamable {
if let child = mirror.children.first {
return .array(try generate(from: child.value))
} else {
throw StructuredOutputError.unsupportedType
throw StructuredOutputError.typeUnsupported
}
case .enum:
throw StructuredOutputError.enumsUnsupported
default:
throw StructuredOutputError.unsupportedType
throw StructuredOutputError.typeUnsupported
}
}
throw StructuredOutputError.unsupportedType
throw StructuredOutputError.typeUnsupported
}
}
}

// TODO: Implement other options. Move to a separate file too? Public?
public enum StructuredOutputError: Error {
case unsupportedType
public enum StructuredOutputError: LocalizedError {
case enumsUnsupported
case typeUnsupported

public var errorDescription: String? {
switch self {
case .enumsUnsupported:
return "Enums are not supported at the moment. Consider using one of the basics types and specifying the accepted values in the prompt."
case .typeUnsupported:
return "Unsupported type. Supported types: String, Bool, Int, Double, Array, and Codable struct/class instances."
}
}
}

public enum ChatCompletionFunctionCallOptionParam: Codable, Equatable {
Expand Down

0 comments on commit 54c7a2e

Please sign in to comment.