Skip to content

Commit

Permalink
Merge branch 'hotfix/0.35.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
intitni committed Jan 7, 2025
2 parents dbd4194 + 1a76a00 commit 02f0f38
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct ChatModelEdit {
var openAIOrganizationID: String = ""
var openAIProjectID: String = ""
var customHeaders: [ChatModel.Info.CustomHeaderInfo.HeaderField] = []
var openAICompatibleSupportsMultipartMessageContent = true
}

enum Action: Equatable, BindableAction {
Expand Down Expand Up @@ -88,21 +89,33 @@ struct ChatModelEdit {
let model = ChatModel(state: state)
return .run { send in
do {
let service = LegacyChatGPTService(
configuration: UserPreferenceChatGPTConfiguration()
.overriding {
$0.model = model
}
)
let reply = try await service
.sendAndWait(content: "Respond with \"Test succeeded\"")
await send(.testSucceeded(reply ?? "No Message"))
let stream = try await service
.send(content: "Respond with \"Stream response is working\"")
var streamReply = ""
for try await chunk in stream {
streamReply += chunk
let configuration = UserPreferenceChatGPTConfiguration().overriding {
$0.model = model
}
let service = ChatGPTService(configuration: configuration)
let stream = service.send(TemplateChatGPTMemory(
memoryTemplate: .init(messages: [
.init(chatMessage: .init(
role: .system,
content: "You are a bot. Just do what is told."
)),
.init(chatMessage: .init(
role: .assistant,
content: "Hello"
)),
.init(chatMessage: .init(
role: .user,
content: "Respond with \"Test succeeded.\""
)),
.init(chatMessage: .init(
role: .user,
content: "Respond with \"Test succeeded.\""
)),
]),
configuration: configuration,
functionProvider: NoChatGPTFunctionProvider()
))
let streamReply = try await stream.asText()
await send(.testSucceeded(streamReply))
} catch {
await send(.testFailed(error.localizedDescription))
Expand Down Expand Up @@ -206,7 +219,11 @@ extension ChatModel {
),
ollamaInfo: .init(keepAlive: state.ollamaKeepAlive),
googleGenerativeAIInfo: .init(apiVersion: state.apiVersion),
openAICompatibleInfo: .init(enforceMessageOrder: state.enforceMessageOrder),
openAICompatibleInfo: .init(
enforceMessageOrder: state.enforceMessageOrder,
supportsMultipartMessageContent: state
.openAICompatibleSupportsMultipartMessageContent
),
customHeaderInfo: .init(headers: state.customHeaders)
)
)
Expand All @@ -230,7 +247,9 @@ extension ChatModel {
enforceMessageOrder: info.openAICompatibleInfo.enforceMessageOrder,
openAIOrganizationID: info.openAIInfo.organizationID,
openAIProjectID: info.openAIInfo.projectID,
customHeaders: info.customHeaderInfo.headers
customHeaders: info.customHeaderInfo.headers,
openAICompatibleSupportsMultipartMessageContent: info.openAICompatibleInfo
.supportsMultipartMessageContent
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ struct ChatModelEditView: View {
Text("Enforce message order to be user/assistant alternated")
}

Toggle(isOn: $store.openAICompatibleSupportsMultipartMessageContent) {
Text("Support multi-part message content")
}

Button("Custom Headers") {
isEditingCustomHeader.toggle()
}
Expand Down
24 changes: 17 additions & 7 deletions Core/Sources/HostApp/CustomCommandSettings/CustomCommandView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ struct CustomCommandView: View {
VStack {
SubSection(title: Text("Send Message")) {
Text(
"This command sends a message to the active chat tab. You can provide additional context through the \"Extra System Prompt\" as well."
"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."
)
}
SubSection(title: Text("Modification")) {
Expand All @@ -208,7 +208,7 @@ struct CustomCommandView: View {
}
SubSection(title: Text("Custom Chat")) {
Text(
"This command will overwrite the system prompt to let the bot behave differently."
"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."
)
}
SubSection(title: Text("Single Round Dialog")) {
Expand Down Expand Up @@ -275,7 +275,9 @@ struct CustomCommandView_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: []
),
.init(
commandId: "2",
Expand All @@ -285,7 +287,9 @@ struct CustomCommandView_Preview: PreviewProvider {
prompt: "Refactor",
continuousMode: false,
generateDescription: true
)
),
ignoreExistingAttachments: false,
attachments: []
),
], "CustomCommandView_Preview"))

Expand All @@ -299,7 +303,9 @@ struct CustomCommandView_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: [] as [CustomCommand.Attachment]
)))
),
reducer: { CustomCommandFeature(settings: settings) }
Expand All @@ -319,7 +325,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
extraSystemPrompt: nil,
prompt: "Hello",
useExtraSystemPrompt: false
)
),
ignoreExistingAttachments: false,
attachments: []
),
.init(
commandId: "2",
Expand All @@ -329,7 +337,9 @@ struct CustomCommandView_NoEditing_Preview: PreviewProvider {
prompt: "Refactor",
continuousMode: false,
generateDescription: true
)
),
ignoreExistingAttachments: false,
attachments: []
),
], "CustomCommandView_Preview"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ struct EditCustomCommand {
var promptToCode = EditPromptToCodeCommand.State()
var customChat = EditCustomChatCommand.State()
var singleRoundDialog = EditSingleRoundDialogCommand.State()
var attachments = EditCustomCommandAttachment.State()

init(_ command: CustomCommand?) {
isNewCommand = command == nil
commandId = command?.id ?? UUID().uuidString
name = command?.name ?? "New Command"
attachments = .init(
attachments: command?.attachments ?? [],
ignoreExistingAttachments: command?.ignoreExistingAttachments ?? false
)

switch command?.feature {
case let .chatWithSelection(extraSystemPrompt, prompt, useExtraSystemPrompt):
Expand Down Expand Up @@ -83,6 +88,7 @@ struct EditCustomCommand {
case promptToCode(EditPromptToCodeCommand.Action)
case customChat(EditCustomChatCommand.Action)
case singleRoundDialog(EditSingleRoundDialogCommand.Action)
case attachments(EditCustomCommandAttachment.Action)
}

let settings: CustomCommandView.Settings
Expand All @@ -106,6 +112,10 @@ struct EditCustomCommand {
EditSingleRoundDialogCommand()
}

Scope(state: \.attachments, action: \.attachments) {
EditCustomCommandAttachment()
}

BindingReducer()

Reduce { state, action in
Expand Down Expand Up @@ -151,7 +161,9 @@ struct EditCustomCommand {
receiveReplyInNotification: state.receiveReplyInNotification
)
}
}()
}(),
ignoreExistingAttachments: state.attachments.ignoreExistingAttachments,
attachments: state.attachments.attachments
)

if state.isNewCommand {
Expand Down Expand Up @@ -184,6 +196,32 @@ struct EditCustomCommand {
return .none
case .singleRoundDialog:
return .none
case .attachments:
return .none
}
}
}
}

@Reducer
struct EditCustomCommandAttachment {
@ObservableState
struct State: Equatable {
var attachments: [CustomCommand.Attachment] = []
var ignoreExistingAttachments: Bool = false
}

enum Action: BindableAction, Equatable {
case binding(BindingAction<State>)
}

var body: some ReducerOf<Self> {
BindingReducer()

Reduce { _, action in
switch action {
case .binding:
return .none
}
}
}
Expand Down
Loading

0 comments on commit 02f0f38

Please sign in to comment.