Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
63af3b4
Merge tag '0.27.0' into develop
intitni Nov 9, 2023
651b639
Support retrieval in context aware prompt to code
intitni Nov 16, 2023
ba79efd
Update
intitni Nov 16, 2023
221a034
Merge tag '0.27.1' into develop
intitni Nov 18, 2023
6e0895c
Rename FocusCodeFinder to FocusCodeFinderType
intitni Nov 16, 2023
9c47de5
Simplify interface of focused code finder
intitni Nov 16, 2023
1d89fcc
Remove tree sitter for Swift
intitni Nov 25, 2023
6b040e3
Update syntax tree dump
intitni Nov 25, 2023
71bc6e7
Fix code finder tests
intitni Nov 26, 2023
2b027e9
Update focused code finder
intitni Nov 26, 2023
3516f57
Fix imports
intitni Nov 26, 2023
f9c5301
Add ObjectiveCFocusedCodeFinder
intitni Nov 26, 2023
3e807b0
Update
intitni Nov 26, 2023
975a1df
Fix SwiftFocusedCodeFinderTests
intitni Nov 26, 2023
72035e7
Fix parseSignatureBeforeBody
intitni Nov 26, 2023
7dcd116
Simplify contextContainingNode
intitni Nov 26, 2023
3a0b5e5
Fix super class and protocol conformance parsing
intitni Nov 27, 2023
b17d282
Add parseDeclarationInterfaceNode to parse all declaration contexts
intitni Nov 27, 2023
2749e2e
Fix parsing includes and imports
intitni Nov 27, 2023
f4ea0f6
Fix focused code
intitni Nov 27, 2023
e8c3ba4
Update
intitni Nov 27, 2023
ecfdfc0
Merge branch 'feature/objective-c-code-finder' into develop
intitni Nov 27, 2023
6d22d48
Add AutoresizingCustomTextEditor
intitni Nov 28, 2023
1305c72
Rename SuggestionProvider to CodeSuggestionProvider
intitni Nov 28, 2023
02900cb
Update
intitni Nov 28, 2023
e5967e0
Merge branch 'feature/informative-suggestion-wip' into develop
intitni Nov 30, 2023
03882d7
Update the context system prompt to use role user
intitni Nov 30, 2023
bc39122
Adjust the prompt in chat
intitni Nov 30, 2023
a1c1043
Rename ChatMessage in chat panel to DisplayedChatMessage
intitni Nov 30, 2023
9b22c29
Add references to chat message
intitni Nov 30, 2023
94aaade
Change the definition of a memory
intitni Nov 30, 2023
68ea73b
Update RetrievedContent in ChatContext
intitni Nov 30, 2023
ba592c2
Support displaying references in chat panel
intitni Dec 1, 2023
aac293e
Break ChatPanel.swift into multiple files
intitni Dec 1, 2023
be2376a
Update to stream references to message
intitni Dec 1, 2023
1925397
Support opening references in Xcode
intitni Dec 1, 2023
774216b
Support jump to specific line of reference file
intitni Dec 1, 2023
5d57f90
Fix the UI of reference list
intitni Dec 1, 2023
01bcaad
Fix opening reference
intitni Dec 1, 2023
353c686
Fix cancellation
intitni Dec 2, 2023
9c3840d
Update
intitni Dec 2, 2023
46da74c
Support providing history compose logic from other types
intitni Dec 2, 2023
67221f4
Update
intitni Dec 2, 2023
2b317fd
Update prompt of prompt to code
intitni Dec 2, 2023
b3ae4ec
Fix that context retriever was incorrect when the context is too long
intitni Dec 2, 2023
6c129d7
Fix that multiple function result was added to history
intitni Dec 2, 2023
d117fb1
Fix unit tests
intitni Dec 2, 2023
f4130c9
Merge branch 'feature/prompt-improvements-28' into develop
intitni Dec 2, 2023
966f654
Add SubSection
intitni Dec 2, 2023
ed339b6
Replace wrappers with SubSection
intitni Dec 2, 2023
3aba060
Update style
intitni Dec 2, 2023
b11f49e
Add scope settings to prompt to code
intitni Dec 2, 2023
bc0eb57
Update
intitni Dec 2, 2023
5b3051d
Merge branch 'feature/improve-scope-settings' into develop
intitni Dec 2, 2023
4f1a60b
Add instructions to chat model settings
intitni Dec 2, 2023
c0e8aa0
Handle errors from azure openai
intitni Dec 2, 2023
9f528c6
Update
intitni Dec 2, 2023
81051ab
Add git ignore checker
intitni Dec 3, 2023
a916e14
Update to not generate suggestion if a file is git ignored
intitni Dec 3, 2023
6c4fc82
Update ActiveDocumentChatContextCollector to only include selected co…
intitni Dec 3, 2023
f6ee5b7
Update
intitni Dec 3, 2023
e9dfeb1
Update
intitni Dec 3, 2023
5ca3bf0
Merge branch 'feature/keyword-base-retrieval' into develop
intitni Dec 3, 2023
a00c478
Fix gitignore check
intitni Dec 3, 2023
e43902a
Limit to 15 references
intitni Dec 3, 2023
28ac89c
Limit references token usage
intitni Dec 3, 2023
de6fa08
Update
intitni Dec 4, 2023
c1404c4
Bump version to 0.28.0
intitni Dec 4, 2023
0c55c5d
Merge branch 'main' into release/0.28.0
intitni Dec 4, 2023
0b54d7c
Update README.md
intitni Dec 4, 2023
66a3494
Use fallback solution when it can't find xcode
intitni Dec 4, 2023
ed2a203
Remove a fatalError
intitni Dec 4, 2023
c452fae
Update
intitni Dec 4, 2023
2312248
Adjust UI
intitni Dec 4, 2023
8ccb85f
Update appcast.xml
intitni Dec 4, 2023
28cf55b
Merge tag '0.28.0' into develop
intitni Dec 4, 2023
bd0f17d
Merge branch 'release/0.28.0'
intitni Dec 4, 2023
143c966
Update
intitni Dec 4, 2023
ea61843
Disable git ignore check by default
intitni Dec 4, 2023
c5dd90e
Bump version to 0.28.1
intitni Dec 4, 2023
de2b382
Update appcast.xml
intitni Dec 4, 2023
d426013
Merge tag '0.28.1' into develop
intitni Dec 4, 2023
b3a73bc
Merge branch 'hotfix/0.28.1'
intitni Dec 4, 2023
b5b6019
Fix git ignore check
intitni Dec 4, 2023
95ba0c3
Bump version 0.28.2
intitni Dec 4, 2023
d0e41d2
Update appcast.xml
intitni Dec 4, 2023
8613f35
Merge branch 'release/0.28.2'
intitni Dec 4, 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
Prev Previous commit
Next Next commit
Support providing history compose logic from other types
  • Loading branch information
intitni committed Dec 2, 2023
commit 46da74c7ccc433b1bfdddbd4c15fe98ebf3e65fe
60 changes: 40 additions & 20 deletions Tool/Sources/OpenAIService/Memory/AutoManagedChatGPTMemory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import TokenEncoder

/// A memory that automatically manages the history according to max tokens and max message count.
public actor AutoManagedChatGPTMemory: ChatGPTMemory {
public struct ComposableMessages {
public var systemPromptMessage: ChatMessage
public var historyMessage: [ChatMessage]
public var retrievedContentMessage: ChatMessage
public var contextSystemPromptMessage: ChatMessage
public var newMessage: ChatMessage
}

public typealias HistoryComposer = (ComposableMessages) -> [ChatMessage]

public private(set) var history: [ChatMessage] = [] {
didSet { onHistoryChange() }
}

public private(set) var remainingTokens: Int?

public var systemPrompt: String
Expand All @@ -19,16 +30,36 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
static let encoder: TokenEncoder = TiktokenCl100kBaseTokenEncoder()

var onHistoryChange: () -> Void = {}

let composeHistory: HistoryComposer

public init(
systemPrompt: String,
configuration: ChatGPTConfiguration,
functionProvider: ChatGPTFunctionProvider
functionProvider: ChatGPTFunctionProvider,
composeHistory: @escaping HistoryComposer = {
/// Default Format:
/// ```
/// [System Prompt] priority: high
/// [Functions] priority: high
/// [Retrieved Content] priority: low
/// [Retrieved Content A]
/// <separator>
/// [Retrieved Content B]
/// [Message History] priority: medium
/// [Context System Prompt] priority: high
/// [Latest Message] priority: high
/// ```
[$0.systemPromptMessage] +
$0.historyMessage +
[$0.retrievedContentMessage, $0.contextSystemPromptMessage, $0.newMessage]
}
) {
self.systemPrompt = systemPrompt
contextSystemPrompt = ""
self.configuration = configuration
self.functionProvider = functionProvider
self.composeHistory = composeHistory
_ = Self.encoder // force pre-initialize
}

Expand Down Expand Up @@ -60,19 +91,6 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
}

/// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
///
/// Format:
/// ```
/// [System Prompt] priority: high
/// [Functions] priority: high
/// [Retrieved Content] priority: low
/// [Retrieved Content A]
/// <separator>
/// [Retrieved Content B]
/// [Message History] priority: medium
/// [Context System Prompt] priority: high
/// [Latest Message] priority: high
/// ```
func generateSendingHistory(
maxNumberOfMessages: Int = UserDefaults.shared.value(for: \.chatGPTMaxMessageCount),
encoder: TokenEncoder = AutoManagedChatGPTMemory.encoder
Expand Down Expand Up @@ -105,11 +123,13 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
encoder: encoder
)

let allMessages: [ChatMessage] = (
[systemPromptMessage] +
historyMessage +
[retrievedContentMessage, contextSystemPromptMessage, newMessage]
).filter {
let allMessages = composeHistory(.init(
systemPromptMessage: systemPromptMessage,
historyMessage: historyMessage,
retrievedContentMessage: retrievedContentMessage,
contextSystemPromptMessage: contextSystemPromptMessage,
newMessage: newMessage
)).filter {
!($0.content?.isEmpty ?? false)
}

Expand Down Expand Up @@ -269,7 +289,7 @@ extension AutoManagedChatGPTMemory {
}
}

extension TokenEncoder {
public extension TokenEncoder {
/// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
func countToken(message: ChatMessage) -> Int {
var total = 3
Expand Down