Skip to content

Commit 93e2592

Browse files
committed
Update api builder to switch according to model format
1 parent d7987be commit 93e2592

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

Tool/Sources/OpenAIService/ChatGPTService.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,35 @@ public class ChatGPTService: ChatGPTServiceType {
6969
public var functionProvider: ChatGPTFunctionProvider
7070

7171
var runningTask: Task<Void, Never>?
72-
var buildCompletionStreamAPI: CompletionStreamAPIBuilder = OpenAICompletionStreamAPI.init
73-
var buildCompletionAPI: CompletionAPIBuilder = OpenAICompletionAPI.init
72+
var buildCompletionStreamAPI: CompletionStreamAPIBuilder = {
73+
apiKey, model, endpoint, requestBody in
74+
switch model.format {
75+
case .googleAI:
76+
fatalError()
77+
case .openAI, .openAICompatible, .azureOpenAI:
78+
return OpenAICompletionStreamAPI(
79+
apiKey: apiKey,
80+
model: model,
81+
endpoint: endpoint,
82+
requestBody: requestBody
83+
)
84+
}
85+
}
86+
87+
var buildCompletionAPI: CompletionAPIBuilder = {
88+
apiKey, model, endpoint, requestBody in
89+
switch model.format {
90+
case .googleAI:
91+
fatalError()
92+
case .openAI, .openAICompatible, .azureOpenAI:
93+
return OpenAICompletionAPI(
94+
apiKey: apiKey,
95+
model: model,
96+
endpoint: endpoint,
97+
requestBody: requestBody
98+
)
99+
}
100+
}
74101

75102
public init(
76103
memory: ChatGPTMemory = AutoManagedChatGPTMemory(

0 commit comments

Comments
 (0)