Skip to content

Commit f41df22

Browse files
committed
Add userReadableContent to functions
1 parent d7eeb3f commit f41df22

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Core/Sources/ChatContextCollectors/WebChatContextCollector/QueryWebsiteFunction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct QueryWebsiteFunction: ChatGPTFunction {
1616
var botReadableContent: String {
1717
return answers.joined(separator: "\n")
1818
}
19+
20+
var userReadableContent: ChatGPTFunctionResultUserReadableContent {
21+
.text(botReadableContent)
22+
}
1923
}
2024

2125
var name: String {

Core/Sources/ChatContextCollectors/WebChatContextCollector/SearchFunction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct SearchFunction: ChatGPTFunction {
2828
"""
2929
}.joined(separator: "\n")
3030
}
31+
32+
var userReadableContent: ChatGPTFunctionResultUserReadableContent {
33+
.text(botReadableContent)
34+
}
3135
}
3236

3337
let maxTokens: Int

Tool/Sources/ChatBasic/ChatGPTFunction.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,38 @@ public enum ChatGPTFunctionCallPhase {
77
case error(argumentsJsonString: String, result: Error)
88
}
99

10+
public enum ChatGPTFunctionResultUserReadableContent {
11+
public struct ListItem {
12+
public enum Detail {
13+
case link(URL)
14+
case text(String)
15+
}
16+
17+
var title: String
18+
var description: String?
19+
var detail: Detail?
20+
21+
public init(title: String, description: String? = nil, detail: Detail? = nil) {
22+
self.title = title
23+
self.description = description
24+
self.detail = detail
25+
}
26+
}
27+
28+
case text(String)
29+
case list([ListItem])
30+
}
31+
1032
public protocol ChatGPTFunctionResult {
1133
var botReadableContent: String { get }
34+
var userReadableContent: ChatGPTFunctionResultUserReadableContent { get }
1235
}
1336

1437
extension String: ChatGPTFunctionResult {
1538
public var botReadableContent: String { self }
39+
public var userReadableContent: ChatGPTFunctionResultUserReadableContent {
40+
.text(self)
41+
}
1642
}
1743

1844
public struct NoChatGPTFunctionArguments: Decodable {}

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/GetCodeCodeAroundLineFunction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct GetCodeCodeAroundLineFunction: ChatGPTFunction {
2222
```
2323
"""
2424
}
25+
26+
var userReadableContent: ChatGPTFunctionResultUserReadableContent {
27+
.text(botReadableContent)
28+
}
2529
}
2630

2731
struct E: Error, LocalizedError {

0 commit comments

Comments
 (0)