Skip to content

Commit b29d1aa

Browse files
committed
Fix message count
1 parent 9776cee commit b29d1aa

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

Core/Sources/ChatPlugin/AskChatGPT.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public func askChatGPT(
1212
let memory = AutoManagedChatGPTMemory(
1313
systemPrompt: systemPrompt,
1414
configuration: configuration,
15-
functionProvider: NoChatGPTFunctionProvider()
15+
functionProvider: NoChatGPTFunctionProvider(),
16+
maxNumberOfMessages: .max
1617
)
1718
let service = LegacyChatGPTService(
1819
memory: memory,

Core/Sources/ChatPlugin/CallAIFunction.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func callAIFunction(
2222
memory: AutoManagedChatGPTMemory(
2323
systemPrompt: "You are now the following python function: ```# \(description)\n\(function)```\n\nOnly respond with your `return` value.",
2424
configuration: configuration,
25-
functionProvider: NoChatGPTFunctionProvider()
25+
functionProvider: NoChatGPTFunctionProvider(),
26+
maxNumberOfMessages: .max
2627
),
2728
configuration: configuration
2829
)

Core/Sources/ChatService/ContextAwareAutoManagedChatGPTMemory.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public final class ContextAwareAutoManagedChatGPTMemory: ChatGPTMemory {
2222
memory = AutoManagedChatGPTMemory(
2323
systemPrompt: "",
2424
configuration: configuration,
25-
functionProvider: functionProvider
25+
functionProvider: functionProvider,
26+
maxNumberOfMessages: UserDefaults.shared.value(for: \.chatGPTMaxMessageCount)
2627
)
2728
contextController = DynamicContextController(
2829
memory: memory,

Core/Sources/PromptToCodeService/OpenAIPromptToCodeService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
179179
let memory = AutoManagedChatGPTMemory(
180180
systemPrompt: systemPrompt,
181181
configuration: configuration,
182-
functionProvider: NoChatGPTFunctionProvider()
182+
functionProvider: NoChatGPTFunctionProvider(),
183+
maxNumberOfMessages: .max
183184
)
184185
let chatGPTService = LegacyChatGPTService(
185186
memory: memory,

Core/Sources/PromptToCodeService/PromptToCodeServiceType.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public extension DependencyValues {
6262
import ContextAwarePromptToCodeService
6363

6464
extension ContextAwarePromptToCodeService: PromptToCodeServiceType {
65+
public func stopResponding() {}
66+
6567
public func modifyCode(
6668
code: String,
6769
requirement: String,

Tool/Sources/OpenAIService/LegacyChatGPTService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public class LegacyChatGPTService: LegacyChatGPTServiceType {
2626
memory: ChatGPTMemory = AutoManagedChatGPTMemory(
2727
systemPrompt: "",
2828
configuration: UserPreferenceChatGPTConfiguration(),
29-
functionProvider: NoChatGPTFunctionProvider()
29+
functionProvider: NoChatGPTFunctionProvider(),
30+
maxNumberOfMessages: .max
3031
),
3132
configuration: ChatGPTConfiguration = UserPreferenceChatGPTConfiguration(),
3233
functionProvider: ChatGPTFunctionProvider = NoChatGPTFunctionProvider()

Tool/Sources/OpenAIService/Memory/AutoManagedChatGPTMemory.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
3838
public var retrievedContent: [ChatMessage.Reference] = []
3939
public var configuration: ChatGPTConfiguration
4040
public var functionProvider: ChatGPTFunctionProvider
41+
public var maxNumberOfMessages: Int
4142

4243
var onHistoryChange: () -> Void = {}
4344

@@ -47,6 +48,7 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
4748
systemPrompt: String,
4849
configuration: ChatGPTConfiguration,
4950
functionProvider: ChatGPTFunctionProvider,
51+
maxNumberOfMessages: Int = .max,
5052
composeHistory: @escaping HistoryComposer = {
5153
/// Default Format:
5254
/// ```
@@ -70,6 +72,7 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
7072
self.configuration = configuration
7173
self.functionProvider = functionProvider
7274
self.composeHistory = composeHistory
75+
self.maxNumberOfMessages = maxNumberOfMessages
7376
}
7477

7578
public func mutateHistory(_ update: (inout [ChatMessage]) -> Void) {
@@ -110,10 +113,7 @@ public actor AutoManagedChatGPTMemory: ChatGPTMemory {
110113

111114
extension AutoManagedChatGPTMemory {
112115
/// https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
113-
func generateSendingHistory(
114-
maxNumberOfMessages: Int = UserDefaults.shared.value(for: \.chatGPTMaxMessageCount),
115-
strategy: AutoManagedChatGPTMemoryStrategy
116-
) async -> ChatGPTPrompt {
116+
func generateSendingHistory(strategy: AutoManagedChatGPTMemoryStrategy) async -> ChatGPTPrompt {
117117
// handle no function support models
118118

119119
let (

0 commit comments

Comments
 (0)