Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d1121aa
Merge tag '0.17.1' into develop
intitni May 31, 2023
61e76d2
Display instructions in the chat panel
intitni Jun 1, 2023
be9c57b
Merge branch 'feature/add-manual-in-using-chat' into develop
intitni Jun 1, 2023
cd3ff1d
Make chat instruction always visible
intitni Jun 4, 2023
1f452d4
Remove LazyVStack
intitni Jun 4, 2023
4f338f8
Merge branch 'feature/disable-lazy-vstack' into develop
intitni Jun 4, 2023
536fbb5
Add new package Tool
intitni May 22, 2023
1cd60d1
Add target LangChainService
intitni May 22, 2023
57856af
Move Terminal to Tool
intitni May 22, 2023
19f53cb
Successfully embedded Python langchain
intitni Jun 1, 2023
02ef3bb
Rename package ChatPlugins to ChatPlugin
intitni Jun 3, 2023
0ccd6aa
Fix build phase to always sign Python on build
intitni Jun 3, 2023
651bf1b
Move Preferences and Configs to Tool
intitni Jun 3, 2023
513468d
Add LangChainChatModel and ReadablePythonError
intitni Jun 3, 2023
ede7135
Add MathChatPlugin
intitni Jun 3, 2023
e83e885
Update
intitni Jun 4, 2023
72eb8ea
Adjust folder structure
intitni Jun 4, 2023
878cda6
Add script to install python
intitni Jun 4, 2023
204b4f3
Fix importing large packages like langchain
intitni Jun 4, 2023
1c52b21
Make runPython sync
intitni Jun 5, 2023
3a2fe5d
Remove pythonQueue
intitni Jun 5, 2023
8cd5690
Update DEVELOPMENT.md
intitni Jun 5, 2023
0ffa5df
Update README.md
intitni Jun 5, 2023
386bddf
Simplify python initialization
intitni Jun 5, 2023
d864a22
Merge branch 'feature/langchain-service' into develop
intitni Jun 5, 2023
c1b98de
Adjust chat instruction
intitni Jun 5, 2023
02ba264
Disable library validation until I now how to correctly sign everything
intitni Jun 5, 2023
08306e4
Add default system prompt settings
intitni Jun 5, 2023
92ec079
Merge branch 'feature/customize-default-system-prompt' into develop
intitni Jun 5, 2023
b94ab81
Support using {{selected_code}} in custom chat command
intitni Jun 5, 2023
1b837d7
Add default custom command Send Selected Code to Chat
intitni Jun 5, 2023
b32c782
Merge branch 'feature/custom-command-templatable' into develop
intitni Jun 5, 2023
32c388a
Update
intitni Jun 5, 2023
6eef413
Remove the current implementation of the new plugins
intitni Jun 6, 2023
3f979b6
Re-implement math chat plugin in Swift
intitni Jun 6, 2023
df8a478
Merge branch 'feature/re-implement-math-plugin-in-swift' into develop
intitni Jun 6, 2023
13f4cbd
LangChain in Swift and a working version of the search plugin
intitni Jun 7, 2023
0945ba9
Add settings for bing search
intitni Jun 7, 2023
ab0ccf7
Fix broken tests
intitni Jun 7, 2023
e367c4a
Remove GILState guards
intitni Jun 7, 2023
ce315f4
Remove prints
intitni Jun 7, 2023
cb0b0d8
Update README.md
intitni Jun 7, 2023
3adf852
Rename mapped to map
intitni Jun 7, 2023
2e0b92b
Merge branch 'feature/search-plugin-in-swift' into develop
intitni Jun 7, 2023
96a6a0a
Update CustomCommandTemplateProcessor to support more parameters
intitni Jun 7, 2023
28fe801
Add auto complete for chat plugins and scopes
intitni Jun 7, 2023
eac0330
Add instructions on plugins
intitni Jun 7, 2023
99f6a63
Search plugins with lowercased ids
intitni Jun 7, 2023
e22ec05
Merge branch 'feature/chat-instruction-on-scopes-and-plugins' into de…
intitni Jun 7, 2023
f4397db
Add cancellation support to agent executor
intitni Jun 7, 2023
503e5ed
Add /exit to auto completion
intitni Jun 7, 2023
77fa566
Update README.md
intitni Jun 7, 2023
f4c7e05
Support setting max search iteration
intitni Jun 7, 2023
e71d936
Bump version to 0.18.0
intitni Jun 7, 2023
33ecf12
Detach LangChain Python
intitni Jun 7, 2023
8fbf130
Remove the "Calculating..." thing from MathChatPlugin
intitni Jun 7, 2023
a47fa95
Adjust ChatAgent
intitni Jun 8, 2023
22e3fa4
Update appcast.xml
intitni Jun 8, 2023
a94e308
Merge branch 'release/0.18.0'
intitni Jun 8, 2023
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
18 changes: 4 additions & 14 deletions Core/Sources/ChatService/ChatService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@ import Combine
import Foundation
import OpenAIService

let defaultSystemPrompt = """
You are an AI programming assistant.
Your reply should be concise, clear, informative and logical.
You MUST reply in the format of markdown.
You MUST embed every code you provide in a markdown code block.
You MUST add the programming language name at the start of the markdown code block.
If you are asked to help perform a task, you MUST think step-by-step, then describe each step concisely.
If you are asked to explain code, you MUST explain it step-by-step in a ordered list.
Make your answer short and structured.
"""

public final class ChatService: ObservableObject {
public let chatGPTService: any ChatGPTServiceType
let pluginController: ChatPluginController
let contextController: DynamicContextController
var cancellable = Set<AnyCancellable>()
@Published public internal(set) var systemPrompt = defaultSystemPrompt
@Published public internal(set) var systemPrompt = UserDefaults.shared
.value(for: \.defaultChatSystemPrompt)
@Published public internal(set) var extraSystemPrompt = ""

public init<T: ChatGPTServiceType>(chatGPTService: T) {
Expand Down Expand Up @@ -58,7 +48,7 @@ public final class ChatService: ObservableObject {
}

public func resetPrompt() async {
systemPrompt = defaultSystemPrompt
systemPrompt = UserDefaults.shared.value(for: \.defaultChatSystemPrompt)
extraSystemPrompt = ""
}

Expand Down Expand Up @@ -89,7 +79,7 @@ public final class ChatService: ObservableObject {

/// Setting it to `nil` to reset the system prompt
public func mutateSystemPrompt(_ newPrompt: String?) {
systemPrompt = newPrompt ?? defaultSystemPrompt
systemPrompt = newPrompt ?? UserDefaults.shared.value(for: \.defaultChatSystemPrompt)
}

public func mutateExtraSystemPrompt(_ newPrompt: String) {
Expand Down
64 changes: 2 additions & 62 deletions Core/Sources/HostApp/CustomCommandView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,14 @@ struct EditCustomCommandView: View {
}
.padding(.bottom)
.background(.regularMaterial)
.sheet(isPresented: .init(get: { editingContentInFullScreen != nil }, set: {
if $0 == false {
editingContentInFullScreen = nil
}
}), content: {
VStack {
if let editingContentInFullScreen {
TextEditor(text: editingContentInFullScreen)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.frame(minHeight: 120)
.multilineTextAlignment(.leading)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
)
}

Button(action: {
editingContentInFullScreen = nil
}) {
Text("Done")
}
}
.padding()
.frame(width: 600, height: 500)
.background(Color(nsColor: .windowBackgroundColor))
})
}
}

@ViewBuilder
var promptTextField: some View {
VStack(alignment: .leading, spacing: 4) {
Text("Prompt")
editableText($prompt)
EditableText(text: $prompt)
}
.padding(.vertical, 4)
}
Expand All @@ -378,7 +350,7 @@ struct EditCustomCommandView: View {
} else {
Text(title ?? "System Prompt")
}
editableText($systemPrompt)
EditableText(text: $systemPrompt)
}
.padding(.vertical, 4)
}
Expand All @@ -390,38 +362,6 @@ struct EditCustomCommandView: View {
var generateDescriptionToggle: some View {
Toggle("Generate Description", isOn: $generatingPromptToCodeDescription)
}

func editableText(_ binding: Binding<String>) -> some View {
Button(action: {
editingContentInFullScreen = binding
}) {
HStack(alignment: .top) {
Text(binding.wrappedValue)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.background {
RoundedRectangle(cornerRadius: 4)
.fill(Color(nsColor: .textBackgroundColor))
}
.overlay {
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
}
Image(systemName: "square.and.pencil")
.resizable()
.scaledToFit()
.frame(width: 14)
.padding(4)
.background(
Color.primary.opacity(0.1),
in: RoundedRectangle(cornerRadius: 4)
)
}
}
.buttonStyle(.plain)
}
}

// MARK: - Previews
Expand Down
8 changes: 8 additions & 0 deletions Core/Sources/HostApp/FeatureSettings/ChatSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct ChatSettingsView: View {

@AppStorage(\.chatFeatureProvider) var chatFeatureProvider
@AppStorage(\.chatGPTModel) var chatGPTModel
@AppStorage(\.defaultChatSystemPrompt) var defaultChatSystemPrompt

init() {}
}
Expand Down Expand Up @@ -122,6 +123,13 @@ struct ChatSettingsView: View {
Text("9 Messages").tag(9)
Text("11 Messages").tag(11)
}

VStack(alignment: .leading, spacing: 4) {
Text("Default System Prompt")
EditableText(text: $settings.defaultChatSystemPrompt)
.lineLimit(6)
}
.padding(.vertical, 4)
}.onAppear {
checkMaxToken()
}.onChange(of: settings.chatFeatureProvider) { _ in
Expand Down
62 changes: 62 additions & 0 deletions Core/Sources/HostApp/SharedComponents/EditableText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Foundation
import SwiftUI

struct EditableText: View {
var text: Binding<String>
@State var isEditing: Bool = false

var body: some View {
Button(action: {
isEditing = true
}) {
HStack(alignment: .top) {
Text(text.wrappedValue)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.background {
RoundedRectangle(cornerRadius: 4)
.fill(Color(nsColor: .textBackgroundColor))
}
.overlay {
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
}
Image(systemName: "square.and.pencil")
.resizable()
.scaledToFit()
.frame(width: 14)
.padding(4)
.background(
Color.primary.opacity(0.1),
in: RoundedRectangle(cornerRadius: 4)
)
}
}
.buttonStyle(.plain)
.sheet(isPresented: $isEditing) {
VStack {
TextEditor(text: text)
.font(Font.system(.body, design: .monospaced))
.padding(4)
.frame(minHeight: 120)
.multilineTextAlignment(.leading)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
)

Button(action: {
isEditing = false
}) {
Text("Done")
}
}
.padding()
.frame(width: 600, height: 500)
.background(Color(nsColor: .windowBackgroundColor))
}
}
}

24 changes: 20 additions & 4 deletions Tool/Sources/Preferences/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public extension UserDefaultPreferenceKeys {
var azureOpenAIAPIKey: PreferenceKey<String> {
.init(defaultValue: "", key: "AzureOpenAIAPIKey")
}

var azureOpenAIBaseURL: PreferenceKey<String> {
.init(defaultValue: "", key: "AzureOpenAIBaseURL")
}

var azureChatGPTDeployment: PreferenceKey<String> {
.init(defaultValue: "", key: "AzureChatGPTDeployment")
}
Expand Down Expand Up @@ -205,7 +205,7 @@ public extension UserDefaultPreferenceKeys {
var chatFeatureProvider: PreferenceKey<ChatFeatureProvider> {
.init(defaultValue: .openAI, key: "ChatFeatureProvider")
}

var chatFontSize: PreferenceKey<Double> {
.init(defaultValue: 12, key: "ChatFontSize")
}
Expand All @@ -225,10 +225,26 @@ public extension UserDefaultPreferenceKeys {
var maxEmbeddableFileInChatContextLineCount: PreferenceKey<Int> {
.init(defaultValue: 100, key: "MaxEmbeddableFileInChatContextLineCount")
}

var useSelectionScopeByDefaultInChatContext: PreferenceKey<Bool> {
.init(defaultValue: true, key: "UseSelectionScopeByDefaultInChatContext")
}

var defaultChatSystemPrompt: PreferenceKey<String> {
.init(
defaultValue: """
You are an AI programming assistant.
Your reply should be concise, clear, informative and logical.
You MUST reply in the format of markdown.
You MUST embed every code you provide in a markdown code block.
You MUST add the programming language name at the start of the markdown code block.
If you are asked to help perform a task, you MUST think step-by-step, then describe each step concisely.
If you are asked to explain code, you MUST explain it step-by-step in a ordered list.
Make your answer short and structured.
""",
key: "DefaultChatSystemPrompt"
)
}
}

// MARK: - Custom Commands
Expand Down