Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import SwiftUI
// MARK: - StructuredToolCall

enum StructuredToolCall: String, CaseIterable {

case structureUI = "structured_ui"

var functionTool: ChatCompletionParameters.Tool {
Expand Down Expand Up @@ -73,7 +72,6 @@ enum StructuredToolCall: String, CaseIterable {

@Observable
final class ChatStructuredOutputToolProvider {

init(service: OpenAIService, customModel: String? = nil) {
self.service = service
self.customModel = customModel
Expand Down Expand Up @@ -157,13 +155,11 @@ final class ChatStructuredOutputToolProvider {
private var lastDisplayedMessageID: UUID?
private var chatMessageParameters = [ChatCompletionParameters.Message]()
private var availableFunctions = [StructuredToolCall: (String) -> String]()

}

// MARK: UI related

extension ChatStructuredOutputToolProvider {

func createUserMessage(
_ prompt: String)
-> ChatCompletionParameters.Message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class ResponseStreamProvider {
model: .gpt5,
instructions: "You are a helpful assistant. Use the conversation history to provide contextual responses.",
maxOutputTokens: 1000,
previousResponseId: previousResponseId)
previousResponseId: previousResponseId,
tools: [.imageGeneration(.init())])

let stream = try await service.responseCreateStream(parameters)
var accumulatedText = ""
Expand Down
10 changes: 5 additions & 5 deletions Sources/OpenAI/AIProxy/AIProxyCertificatePinning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ private var publicKeysAsData: [Data] = publicKeysAsHex.map { publicKeyAsHex in
private let publicKeysAsHex: [[UInt8]] = [
// live on api.aiproxy.com
[
0x04, 0x4a, 0x42, 0x12, 0xe7, 0xed, 0x36, 0xb4, 0xa9, 0x1f, 0x96, 0x7e, 0xcf, 0xbd, 0xe0,
0x9d, 0xea, 0x4b, 0xfb, 0xaf, 0xe7, 0xc6, 0x93, 0xf0, 0xbf, 0x92, 0x0f, 0x12, 0x7a, 0x22,
0x7d, 0x00, 0x77, 0x81, 0xa5, 0x06, 0x26, 0x06, 0x5c, 0x47, 0x8f, 0x57, 0xef, 0x41, 0x39,
0x0b, 0x3d, 0x41, 0x72, 0x68, 0x33, 0x86, 0x69, 0x14, 0x2a, 0x36, 0x4d, 0x74, 0x7d, 0xbc,
0x60, 0x91, 0xff, 0xcc, 0x29,
0x04, 0x4A, 0x42, 0x12, 0xE7, 0xED, 0x36, 0xB4, 0xA9, 0x1F, 0x96, 0x7E, 0xCF, 0xBD, 0xE0,
0x9D, 0xEA, 0x4B, 0xFB, 0xAF, 0xE7, 0xC6, 0x93, 0xF0, 0xBF, 0x92, 0x0F, 0x12, 0x7A, 0x22,
0x7D, 0x00, 0x77, 0x81, 0xA5, 0x06, 0x26, 0x06, 0x5C, 0x47, 0x8F, 0x57, 0xEF, 0x41, 0x39,
0x0B, 0x3D, 0x41, 0x72, 0x68, 0x33, 0x86, 0x69, 0x14, 0x2A, 0x36, 0x4D, 0x74, 0x7D, 0xBC,
0x60, 0x91, 0xFF, 0xCC, 0x29,
],

// live on api.aiproxy.pro
Expand Down
97 changes: 96 additions & 1 deletion Sources/OpenAI/AIProxy/AIProxyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ struct AIProxyService: OpenAIService {
}

func responseModel(
id _: String)
id _: String,
parameters _: GetResponseParameter?)
async throws -> ResponseModel
{
let request = try await OpenAIAPI.chat.request(
Expand All @@ -1299,6 +1300,14 @@ struct AIProxyService: OpenAIService {
return try await fetch(debugEnabled: debugEnabled, type: ResponseModel.self, with: request)
}

func responseModelStream(
id _: String,
parameters _: GetResponseParameter?)
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
{
fatalError("responseModelStream not implemented for AIProxy Service")
}

func responseCreateStream(
_ parameters: ModelResponseParameter)
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
Expand All @@ -1315,6 +1324,92 @@ struct AIProxyService: OpenAIService {
return try await fetchStream(debugEnabled: debugEnabled, type: ResponseStreamEvent.self, with: request)
}

func responseDelete(
id _: String)
async throws -> DeletionStatus
{
fatalError("responseDelete not implemented for AIProxy Service")
}

func responseCancel(
id _: String)
async throws -> ResponseModel
{
fatalError("responseCancel not implemented for AIProxy Service")
}

func responseInputItems(
id _: String,
parameters _: GetInputItemsParameter?)
async throws -> OpenAIResponse<InputItem>
{
fatalError("responseInputItems not implemented for AIProxy Service")
}

// MARK: - Conversations

func conversationCreate(
parameters _: CreateConversationParameter?)
async throws -> ConversationModel
{
fatalError("conversationCreate not implemented for AIProxy Service")
}

func getConversation(
id _: String)
async throws -> ConversationModel
{
fatalError("getConversation not implemented for AIProxy Service")
}

func updateConversation(
id _: String,
parameters _: UpdateConversationParameter)
async throws -> ConversationModel
{
fatalError("updateConversation not implemented for AIProxy Service")
}

func deleteConversation(
id _: String)
async throws -> DeletionStatus
{
fatalError("deleteConversation not implemented for AIProxy Service")
}

func getConversationItems(
id _: String,
parameters _: GetConversationItemsParameter?)
async throws -> OpenAIResponse<InputItem>
{
fatalError("getConversationItems not implemented for AIProxy Service")
}

func createConversationItems(
id _: String,
parameters _: CreateConversationItemsParameter)
async throws -> OpenAIResponse<InputItem>
{
fatalError("createConversationItems not implemented for AIProxy Service")
}

func getConversationItem(
conversationID _: String,
itemID _: String,
parameters _: GetConversationItemParameter?)
async throws -> InputItem
{
fatalError("getConversationItem not implemented for AIProxy Service")
}

func deleteConversationItem(
conversationID _: String,
itemID _: String)
async throws -> ConversationModel
{
fatalError("deleteConversationItem not implemented for AIProxy Service")
}

private static let assistantsBetaV2 = "assistants=v2"

/// Your partial key is provided during the integration process at dashboard.aiproxy.pro
Expand Down
97 changes: 96 additions & 1 deletion Sources/OpenAI/Azure/DefaultOpenAIAzureService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,8 @@ public final class DefaultOpenAIAzureService: OpenAIService {
}

public func responseModel(
id: String)
id: String,
parameters _: GetResponseParameter?)
async throws -> ResponseModel
{
let request = try AzureOpenAIAPI.response(.retrieve(responseID: id)).request(
Expand All @@ -921,6 +922,14 @@ public final class DefaultOpenAIAzureService: OpenAIService {
return try await fetch(debugEnabled: debugEnabled, type: ResponseModel.self, with: request)
}

public func responseModelStream(
id _: String,
parameters _: GetResponseParameter?)
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
{
fatalError("responseModelStream not implemented for Azure OpenAI Service")
}

public func responseCreateStream(
_ parameters: ModelResponseParameter)
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
Expand All @@ -937,6 +946,92 @@ public final class DefaultOpenAIAzureService: OpenAIService {
return try await fetchStream(debugEnabled: debugEnabled, type: ResponseStreamEvent.self, with: request)
}

public func responseDelete(
id _: String)
async throws -> DeletionStatus
{
fatalError("responseDelete not implemented for Azure OpenAI Service")
}

public func responseCancel(
id _: String)
async throws -> ResponseModel
{
fatalError("responseCancel not implemented for Azure OpenAI Service")
}

public func responseInputItems(
id _: String,
parameters _: GetInputItemsParameter?)
async throws -> OpenAIResponse<InputItem>
{
fatalError("responseInputItems not implemented for Azure OpenAI Service")
}

// MARK: - Conversations

public func conversationCreate(
parameters _: CreateConversationParameter?)
async throws -> ConversationModel
{
fatalError("conversationCreate not implemented for Azure OpenAI Service")
}

public func getConversation(
id _: String)
async throws -> ConversationModel
{
fatalError("getConversation not implemented for Azure OpenAI Service")
}

public func updateConversation(
id _: String,
parameters _: UpdateConversationParameter)
async throws -> ConversationModel
{
fatalError("updateConversation not implemented for Azure OpenAI Service")
}

public func deleteConversation(
id _: String)
async throws -> DeletionStatus
{
fatalError("deleteConversation not implemented for Azure OpenAI Service")
}

public func getConversationItems(
id _: String,
parameters _: GetConversationItemsParameter?)
async throws -> OpenAIResponse<InputItem>
{
fatalError("getConversationItems not implemented for Azure OpenAI Service")
}

public func createConversationItems(
id _: String,
parameters _: CreateConversationItemsParameter)
async throws -> OpenAIResponse<InputItem>
{
fatalError("createConversationItems not implemented for Azure OpenAI Service")
}

public func getConversationItem(
conversationID _: String,
itemID _: String,
parameters _: GetConversationItemParameter?)
async throws -> InputItem
{
fatalError("getConversationItem not implemented for Azure OpenAI Service")
}

public func deleteConversationItem(
conversationID _: String,
itemID _: String)
async throws -> ConversationModel
{
fatalError("deleteConversationItem not implemented for Azure OpenAI Service")
}

private static let assistantsBetaV2 = "assistants=v2"

private let apiKey: Authorization
Expand Down
Loading