Skip to content

Commit 02f0f38

Browse files
committed
Merge branch 'hotfix/0.35.4'
2 parents dbd4194 + 1a76a00 commit 02f0f38

File tree

14 files changed

+500
-106
lines changed

14 files changed

+500
-106
lines changed

Core/Sources/HostApp/AccountSettings/ChatModelManagement/ChatModelEdit.swift

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ChatModelEdit {
3232
var openAIOrganizationID: String = ""
3333
var openAIProjectID: String = ""
3434
var customHeaders: [ChatModel.Info.CustomHeaderInfo.HeaderField] = []
35+
var openAICompatibleSupportsMultipartMessageContent = true
3536
}
3637

3738
enum Action: Equatable, BindableAction {
@@ -88,21 +89,33 @@ struct ChatModelEdit {
8889
let model = ChatModel(state: state)
8990
return .run { send in
9091
do {
91-
let service = LegacyChatGPTService(
92-
configuration: UserPreferenceChatGPTConfiguration()
93-
.overriding {
94-
$0.model = model
95-
}
96-
)
97-
let reply = try await service
98-
.sendAndWait(content: "Respond with \"Test succeeded\"")
99-
await send(.testSucceeded(reply ?? "No Message"))
100-
let stream = try await service
101-
.send(content: "Respond with \"Stream response is working\"")
102-
var streamReply = ""
103-
for try await chunk in stream {
104-
streamReply += chunk
92+
let configuration = UserPreferenceChatGPTConfiguration().overriding {
93+
$0.model = model
10594
}
95+
let service = ChatGPTService(configuration: configuration)
96+
let stream = service.send(TemplateChatGPTMemory(
97+
memoryTemplate: .init(messages: [
98+
.init(chatMessage: .init(
99+
role: .system,
100+
content: "You are a bot. Just do what is told."
101+
)),
102+
.init(chatMessage: .init(
103+
role: .assistant,
104+
content: "Hello"
105+
)),
106+
.init(chatMessage: .init(
107+
role: .user,
108+
content: "Respond with \"Test succeeded.\""
109+
)),
110+
.init(chatMessage: .init(
111+
role: .user,
112+
content: "Respond with \"Test succeeded.\""
113+
)),
114+
]),
115+
configuration: configuration,
116+
functionProvider: NoChatGPTFunctionProvider()
117+
))
118+
let streamReply = try await stream.asText()
106119
await send(.testSucceeded(streamReply))
107120
} catch {
108121
await send(.testFailed(error.localizedDescription))
@@ -206,7 +219,11 @@ extension ChatModel {
206219
),
207220
ollamaInfo: .init(keepAlive: state.ollamaKeepAlive),
208221
googleGenerativeAIInfo: .init(apiVersion: state.apiVersion),
209-
openAICompatibleInfo: .init(enforceMessageOrder: state.enforceMessageOrder),
222+
openAICompatibleInfo: .init(
223+
enforceMessageOrder: state.enforceMessageOrder,
224+
supportsMultipartMessageContent: state
225+
.openAICompatibleSupportsMultipartMessageContent
226+
),
210227
customHeaderInfo: .init(headers: state.customHeaders)
211228
)
212229
)
@@ -230,7 +247,9 @@ extension ChatModel {
230247
enforceMessageOrder: info.openAICompatibleInfo.enforceMessageOrder,
231248
openAIOrganizationID: info.openAIInfo.organizationID,
232249
openAIProjectID: info.openAIInfo.projectID,
233-
customHeaders: info.customHeaderInfo.headers
250+
customHeaders: info.customHeaderInfo.headers,
251+
openAICompatibleSupportsMultipartMessageContent: info.openAICompatibleInfo
252+
.supportsMultipartMessageContent
234253
)
235254
}
236255
}

Core/Sources/HostApp/AccountSettings/ChatModelManagement/ChatModelEditView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ struct ChatModelEditView: View {
322322
Text("Enforce message order to be user/assistant alternated")
323323
}
324324

325+
Toggle(isOn: $store.openAICompatibleSupportsMultipartMessageContent) {
326+
Text("Support multi-part message content")
327+
}
328+
325329
Button("Custom Headers") {
326330
isEditingCustomHeader.toggle()
327331
}

Core/Sources/HostApp/CustomCommandSettings/CustomCommandView.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct CustomCommandView: View {
198198
VStack {
199199
SubSection(title: Text("Send Message")) {
200200
Text(
201-
"This command sends a message to the active chat tab. You can provide additional context through the \"Extra System Prompt\" as well."
201+
"This command sends a message to the active chat tab. You can provide additional context as well. The additional context will be removed once a message is sent. If the message provided is empty, you can manually type the message in the chat."
202202
)
203203
}
204204
SubSection(title: Text("Modification")) {
@@ -208,7 +208,7 @@ struct CustomCommandView: View {
208208
}
209209
SubSection(title: Text("Custom Chat")) {
210210
Text(
211-
"This command will overwrite the system prompt to let the bot behave differently."
211+
"This command will overwrite the context of the chat. You can use it to switch to different contexts in the chat. If a message is provided, it will be sent to the chat as well."
212212
)
213213
}
214214
SubSection(title: Text("Single Round Dialog")) {
@@ -275,7 +275,9 @@ struct CustomCommandView_Preview: PreviewProvider {
275275
extraSystemPrompt: nil,
276276
prompt: "Hello",
277277
useExtraSystemPrompt: false
278-
)
278+
),
279+
ignoreExistingAttachments: false,
280+
attachments: []
279281
),
280282
.init(
281283
commandId: "2",
@@ -285,7 +287,9 @@ struct CustomCommandView_Preview: PreviewProvider {
285287
prompt: "Refactor",
286288
continuousMode: false,
287289
generateDescription: true
288-
)
290+
),
291+
ignoreExistingAttachments: false,
292+
attachments: []
289293
),
290294
], "CustomCommandView_Preview"))
291295

@@ -299,7 +303,9 @@ struct CustomCommandView_Preview: PreviewProvider {
299303
extraSystemPrompt: nil,
300304
prompt: "Hello",
301305
useExtraSystemPrompt: false
302-
)
306+
),
307+
ignoreExistingAttachments: false,
308+
attachments: [] as [CustomCommand.Attachment]
303309
)))
304310
),
305311
reducer: { CustomCommandFeature(settings: settings) }
@@ -319,7 +325,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
319325
extraSystemPrompt: nil,
320326
prompt: "Hello",
321327
useExtraSystemPrompt: false
322-
)
328+
),
329+
ignoreExistingAttachments: false,
330+
attachments: []
323331
),
324332
.init(
325333
commandId: "2",
@@ -329,7 +337,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
329337
prompt: "Refactor",
330338
continuousMode: false,
331339
generateDescription: true
332-
)
340+
),
341+
ignoreExistingAttachments: false,
342+
attachments: []
333343
),
334344
], "CustomCommandView_Preview"))
335345

Core/Sources/HostApp/CustomCommandSettings/EditCustomCommand.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ struct EditCustomCommand {
2323
var promptToCode = EditPromptToCodeCommand.State()
2424
var customChat = EditCustomChatCommand.State()
2525
var singleRoundDialog = EditSingleRoundDialogCommand.State()
26+
var attachments = EditCustomCommandAttachment.State()
2627

2728
init(_ command: CustomCommand?) {
2829
isNewCommand = command == nil
2930
commandId = command?.id ?? UUID().uuidString
3031
name = command?.name ?? "New Command"
32+
attachments = .init(
33+
attachments: command?.attachments ?? [],
34+
ignoreExistingAttachments: command?.ignoreExistingAttachments ?? false
35+
)
3136

3237
switch command?.feature {
3338
case let .chatWithSelection(extraSystemPrompt, prompt, useExtraSystemPrompt):
@@ -83,6 +88,7 @@ struct EditCustomCommand {
8388
case promptToCode(EditPromptToCodeCommand.Action)
8489
case customChat(EditCustomChatCommand.Action)
8590
case singleRoundDialog(EditSingleRoundDialogCommand.Action)
91+
case attachments(EditCustomCommandAttachment.Action)
8692
}
8793

8894
let settings: CustomCommandView.Settings
@@ -106,6 +112,10 @@ struct EditCustomCommand {
106112
EditSingleRoundDialogCommand()
107113
}
108114

115+
Scope(state: \.attachments, action: \.attachments) {
116+
EditCustomCommandAttachment()
117+
}
118+
109119
BindingReducer()
110120

111121
Reduce { state, action in
@@ -151,7 +161,9 @@ struct EditCustomCommand {
151161
receiveReplyInNotification: state.receiveReplyInNotification
152162
)
153163
}
154-
}()
164+
}(),
165+
ignoreExistingAttachments: state.attachments.ignoreExistingAttachments,
166+
attachments: state.attachments.attachments
155167
)
156168

157169
if state.isNewCommand {
@@ -184,6 +196,32 @@ struct EditCustomCommand {
184196
return .none
185197
case .singleRoundDialog:
186198
return .none
199+
case .attachments:
200+
return .none
201+
}
202+
}
203+
}
204+
}
205+
206+
@Reducer
207+
struct EditCustomCommandAttachment {
208+
@ObservableState
209+
struct State: Equatable {
210+
var attachments: [CustomCommand.Attachment] = []
211+
var ignoreExistingAttachments: Bool = false
212+
}
213+
214+
enum Action: BindableAction, Equatable {
215+
case binding(BindingAction<State>)
216+
}
217+
218+
var body: some ReducerOf<Self> {
219+
BindingReducer()
220+
221+
Reduce { _, action in
222+
switch action {
223+
case .binding:
224+
return .none
187225
}
188226
}
189227
}

0 commit comments

Comments
 (0)