Skip to content

Commit 311b492

Browse files
Merge pull request #173 from jamesrochabrun/jroch-responses-api
Conversations API
2 parents 7c89f2a + df47177 commit 311b492

35 files changed

+2496
-126
lines changed

Examples/SwiftOpenAIExample/SwiftOpenAIExample/ChatStructureOutputTool/ChatStructuredOutputToolProvider.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import SwiftUI
1212
// MARK: - StructuredToolCall
1313

1414
enum StructuredToolCall: String, CaseIterable {
15-
1615
case structureUI = "structured_ui"
1716

1817
var functionTool: ChatCompletionParameters.Tool {
@@ -73,7 +72,6 @@ enum StructuredToolCall: String, CaseIterable {
7372

7473
@Observable
7574
final class ChatStructuredOutputToolProvider {
76-
7775
init(service: OpenAIService, customModel: String? = nil) {
7876
self.service = service
7977
self.customModel = customModel
@@ -157,13 +155,11 @@ final class ChatStructuredOutputToolProvider {
157155
private var lastDisplayedMessageID: UUID?
158156
private var chatMessageParameters = [ChatCompletionParameters.Message]()
159157
private var availableFunctions = [StructuredToolCall: (String) -> String]()
160-
161158
}
162159

163160
// MARK: UI related
164161

165162
extension ChatStructuredOutputToolProvider {
166-
167163
func createUserMessage(
168164
_ prompt: String)
169165
-> ChatCompletionParameters.Message

Examples/SwiftOpenAIExample/SwiftOpenAIExample/ResponseAPIDemo/ResponseStreamProvider.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class ResponseStreamProvider {
127127
model: .gpt5,
128128
instructions: "You are a helpful assistant. Use the conversation history to provide contextual responses.",
129129
maxOutputTokens: 1000,
130-
previousResponseId: previousResponseId)
130+
previousResponseId: previousResponseId,
131+
tools: [.imageGeneration(.init())])
131132

132133
let stream = try await service.responseCreateStream(parameters)
133134
var accumulatedText = ""

Sources/OpenAI/AIProxy/AIProxyCertificatePinning.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ private var publicKeysAsData: [Data] = publicKeysAsHex.map { publicKeyAsHex in
127127
private let publicKeysAsHex: [[UInt8]] = [
128128
// live on api.aiproxy.com
129129
[
130-
0x04, 0x4a, 0x42, 0x12, 0xe7, 0xed, 0x36, 0xb4, 0xa9, 0x1f, 0x96, 0x7e, 0xcf, 0xbd, 0xe0,
131-
0x9d, 0xea, 0x4b, 0xfb, 0xaf, 0xe7, 0xc6, 0x93, 0xf0, 0xbf, 0x92, 0x0f, 0x12, 0x7a, 0x22,
132-
0x7d, 0x00, 0x77, 0x81, 0xa5, 0x06, 0x26, 0x06, 0x5c, 0x47, 0x8f, 0x57, 0xef, 0x41, 0x39,
133-
0x0b, 0x3d, 0x41, 0x72, 0x68, 0x33, 0x86, 0x69, 0x14, 0x2a, 0x36, 0x4d, 0x74, 0x7d, 0xbc,
134-
0x60, 0x91, 0xff, 0xcc, 0x29,
130+
0x04, 0x4A, 0x42, 0x12, 0xE7, 0xED, 0x36, 0xB4, 0xA9, 0x1F, 0x96, 0x7E, 0xCF, 0xBD, 0xE0,
131+
0x9D, 0xEA, 0x4B, 0xFB, 0xAF, 0xE7, 0xC6, 0x93, 0xF0, 0xBF, 0x92, 0x0F, 0x12, 0x7A, 0x22,
132+
0x7D, 0x00, 0x77, 0x81, 0xA5, 0x06, 0x26, 0x06, 0x5C, 0x47, 0x8F, 0x57, 0xEF, 0x41, 0x39,
133+
0x0B, 0x3D, 0x41, 0x72, 0x68, 0x33, 0x86, 0x69, 0x14, 0x2A, 0x36, 0x4D, 0x74, 0x7D, 0xBC,
134+
0x60, 0x91, 0xFF, 0xCC, 0x29,
135135
],
136136

137137
// live on api.aiproxy.pro

Sources/OpenAI/AIProxy/AIProxyService.swift

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,8 @@ struct AIProxyService: OpenAIService {
12871287
}
12881288

12891289
func responseModel(
1290-
id _: String)
1290+
id _: String,
1291+
parameters _: GetResponseParameter?)
12911292
async throws -> ResponseModel
12921293
{
12931294
let request = try await OpenAIAPI.chat.request(
@@ -1299,6 +1300,14 @@ struct AIProxyService: OpenAIService {
12991300
return try await fetch(debugEnabled: debugEnabled, type: ResponseModel.self, with: request)
13001301
}
13011302

1303+
func responseModelStream(
1304+
id _: String,
1305+
parameters _: GetResponseParameter?)
1306+
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
1307+
{
1308+
fatalError("responseModelStream not implemented for AIProxy Service")
1309+
}
1310+
13021311
func responseCreateStream(
13031312
_ parameters: ModelResponseParameter)
13041313
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
@@ -1315,6 +1324,92 @@ struct AIProxyService: OpenAIService {
13151324
return try await fetchStream(debugEnabled: debugEnabled, type: ResponseStreamEvent.self, with: request)
13161325
}
13171326

1327+
func responseDelete(
1328+
id _: String)
1329+
async throws -> DeletionStatus
1330+
{
1331+
fatalError("responseDelete not implemented for AIProxy Service")
1332+
}
1333+
1334+
func responseCancel(
1335+
id _: String)
1336+
async throws -> ResponseModel
1337+
{
1338+
fatalError("responseCancel not implemented for AIProxy Service")
1339+
}
1340+
1341+
func responseInputItems(
1342+
id _: String,
1343+
parameters _: GetInputItemsParameter?)
1344+
async throws -> OpenAIResponse<InputItem>
1345+
{
1346+
fatalError("responseInputItems not implemented for AIProxy Service")
1347+
}
1348+
1349+
// MARK: - Conversations
1350+
1351+
func conversationCreate(
1352+
parameters _: CreateConversationParameter?)
1353+
async throws -> ConversationModel
1354+
{
1355+
fatalError("conversationCreate not implemented for AIProxy Service")
1356+
}
1357+
1358+
func getConversation(
1359+
id _: String)
1360+
async throws -> ConversationModel
1361+
{
1362+
fatalError("getConversation not implemented for AIProxy Service")
1363+
}
1364+
1365+
func updateConversation(
1366+
id _: String,
1367+
parameters _: UpdateConversationParameter)
1368+
async throws -> ConversationModel
1369+
{
1370+
fatalError("updateConversation not implemented for AIProxy Service")
1371+
}
1372+
1373+
func deleteConversation(
1374+
id _: String)
1375+
async throws -> DeletionStatus
1376+
{
1377+
fatalError("deleteConversation not implemented for AIProxy Service")
1378+
}
1379+
1380+
func getConversationItems(
1381+
id _: String,
1382+
parameters _: GetConversationItemsParameter?)
1383+
async throws -> OpenAIResponse<InputItem>
1384+
{
1385+
fatalError("getConversationItems not implemented for AIProxy Service")
1386+
}
1387+
1388+
func createConversationItems(
1389+
id _: String,
1390+
parameters _: CreateConversationItemsParameter)
1391+
async throws -> OpenAIResponse<InputItem>
1392+
{
1393+
fatalError("createConversationItems not implemented for AIProxy Service")
1394+
}
1395+
1396+
func getConversationItem(
1397+
conversationID _: String,
1398+
itemID _: String,
1399+
parameters _: GetConversationItemParameter?)
1400+
async throws -> InputItem
1401+
{
1402+
fatalError("getConversationItem not implemented for AIProxy Service")
1403+
}
1404+
1405+
func deleteConversationItem(
1406+
conversationID _: String,
1407+
itemID _: String)
1408+
async throws -> ConversationModel
1409+
{
1410+
fatalError("deleteConversationItem not implemented for AIProxy Service")
1411+
}
1412+
13181413
private static let assistantsBetaV2 = "assistants=v2"
13191414

13201415
/// Your partial key is provided during the integration process at dashboard.aiproxy.pro

Sources/OpenAI/Azure/DefaultOpenAIAzureService.swift

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,8 @@ public final class DefaultOpenAIAzureService: OpenAIService {
909909
}
910910

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

925+
public func responseModelStream(
926+
id _: String,
927+
parameters _: GetResponseParameter?)
928+
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
929+
{
930+
fatalError("responseModelStream not implemented for Azure OpenAI Service")
931+
}
932+
924933
public func responseCreateStream(
925934
_ parameters: ModelResponseParameter)
926935
async throws -> AsyncThrowingStream<ResponseStreamEvent, Error>
@@ -937,6 +946,92 @@ public final class DefaultOpenAIAzureService: OpenAIService {
937946
return try await fetchStream(debugEnabled: debugEnabled, type: ResponseStreamEvent.self, with: request)
938947
}
939948

949+
public func responseDelete(
950+
id _: String)
951+
async throws -> DeletionStatus
952+
{
953+
fatalError("responseDelete not implemented for Azure OpenAI Service")
954+
}
955+
956+
public func responseCancel(
957+
id _: String)
958+
async throws -> ResponseModel
959+
{
960+
fatalError("responseCancel not implemented for Azure OpenAI Service")
961+
}
962+
963+
public func responseInputItems(
964+
id _: String,
965+
parameters _: GetInputItemsParameter?)
966+
async throws -> OpenAIResponse<InputItem>
967+
{
968+
fatalError("responseInputItems not implemented for Azure OpenAI Service")
969+
}
970+
971+
// MARK: - Conversations
972+
973+
public func conversationCreate(
974+
parameters _: CreateConversationParameter?)
975+
async throws -> ConversationModel
976+
{
977+
fatalError("conversationCreate not implemented for Azure OpenAI Service")
978+
}
979+
980+
public func getConversation(
981+
id _: String)
982+
async throws -> ConversationModel
983+
{
984+
fatalError("getConversation not implemented for Azure OpenAI Service")
985+
}
986+
987+
public func updateConversation(
988+
id _: String,
989+
parameters _: UpdateConversationParameter)
990+
async throws -> ConversationModel
991+
{
992+
fatalError("updateConversation not implemented for Azure OpenAI Service")
993+
}
994+
995+
public func deleteConversation(
996+
id _: String)
997+
async throws -> DeletionStatus
998+
{
999+
fatalError("deleteConversation not implemented for Azure OpenAI Service")
1000+
}
1001+
1002+
public func getConversationItems(
1003+
id _: String,
1004+
parameters _: GetConversationItemsParameter?)
1005+
async throws -> OpenAIResponse<InputItem>
1006+
{
1007+
fatalError("getConversationItems not implemented for Azure OpenAI Service")
1008+
}
1009+
1010+
public func createConversationItems(
1011+
id _: String,
1012+
parameters _: CreateConversationItemsParameter)
1013+
async throws -> OpenAIResponse<InputItem>
1014+
{
1015+
fatalError("createConversationItems not implemented for Azure OpenAI Service")
1016+
}
1017+
1018+
public func getConversationItem(
1019+
conversationID _: String,
1020+
itemID _: String,
1021+
parameters _: GetConversationItemParameter?)
1022+
async throws -> InputItem
1023+
{
1024+
fatalError("getConversationItem not implemented for Azure OpenAI Service")
1025+
}
1026+
1027+
public func deleteConversationItem(
1028+
conversationID _: String,
1029+
itemID _: String)
1030+
async throws -> ConversationModel
1031+
{
1032+
fatalError("deleteConversationItem not implemented for Azure OpenAI Service")
1033+
}
1034+
9401035
private static let assistantsBetaV2 = "assistants=v2"
9411036

9421037
private let apiKey: Authorization

0 commit comments

Comments
 (0)