Skip to content

Commit f37bc13

Browse files
committed
Add current time to system prompt
1 parent 011596d commit f37bc13

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

Core/Package.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ let package = Package(
180180
// context collectors
181181
"WebChatContextCollector",
182182
"ActiveDocumentChatContextCollector",
183+
"SystemInfoChatContextCollector",
183184

184185
.product(name: "AppMonitoring", package: "Tool"),
185186
.product(name: "Environment", package: "Tool"),
@@ -346,6 +347,15 @@ let package = Package(
346347
path: "Sources/ChatContextCollectors/WebChatContextCollector"
347348
),
348349

350+
.target(
351+
name: "SystemInfoChatContextCollector",
352+
dependencies: [
353+
"ChatContextCollector",
354+
.product(name: "OpenAIService", package: "Tool"),
355+
],
356+
path: "Sources/ChatContextCollectors/SystemInfoChatContextCollector"
357+
),
358+
349359
.target(
350360
name: "ActiveDocumentChatContextCollector",
351361
dependencies: [
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import ChatContextCollector
2+
import Foundation
3+
import OpenAIService
4+
5+
public final class SystemInfoChatContextCollector: ChatContextCollector {
6+
static let dateFormatter: DateFormatter = {
7+
let formatter = DateFormatter()
8+
formatter.dateFormat = "EEEE, yyyy-MM-dd HH:mm:ssZ"
9+
return formatter
10+
}()
11+
12+
public init() {}
13+
14+
public func generateContext(
15+
history: [ChatMessage],
16+
scopes: Set<String>,
17+
content: String
18+
) -> ChatContext? {
19+
return .init(
20+
systemPrompt: """
21+
Current Time: \(Self.dateFormatter.string(from: Date())) (You can use it to calculate time in another time zone)
22+
""",
23+
functions: []
24+
)
25+
}
26+
}
27+

Core/Sources/ChatService/AllContextCollector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import ActiveDocumentChatContextCollector
22
import ChatContextCollector
3+
import SystemInfoChatContextCollector
34
import WebChatContextCollector
45

56
let allContextCollectors: [any ChatContextCollector] = [
7+
SystemInfoChatContextCollector(),
68
ActiveDocumentChatContextCollector(),
79
WebChatContextCollector(),
810
]

0 commit comments

Comments
 (0)