File tree Expand file tree Collapse file tree
Core/Sources/ChatContextCollectors/WebChatContextCollector Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import ChatContextCollector
22import Foundation
33import OpenAIService
4- import SuggestionModel
54
65public final class WebChatContextCollector : ChatContextCollector {
76 var recentLinks = [ String] ( )
8-
7+
98 public init ( ) { }
109
1110 public func generateContext(
@@ -28,8 +27,24 @@ public final class WebChatContextCollector: ChatContextCollector {
2827}
2928
3029extension WebChatContextCollector {
31- static func detectLinks( from: [ ChatMessage ] ) -> [ String ] {
32- return [ ]
30+ static func detectLinks( from messages: [ ChatMessage ] ) -> [ String ] {
31+ var links = [ String] ( )
32+ let detector = try ? NSDataDetector ( types: NSTextCheckingResult . CheckingType. link. rawValue)
33+ for message in messages {
34+ guard let content = message. content else { continue }
35+ let matches = detector? . matches (
36+ in: content,
37+ options: [ ] ,
38+ range: NSRange ( content. startIndex... , in: content)
39+ )
40+
41+ for match in matches ?? [ ] {
42+ guard let range = Range ( match. range, in: content) else { continue }
43+ let url = content [ range]
44+ links. append ( String ( url) )
45+ }
46+ }
47+ return links
3348 }
3449}
3550
You can’t perform that action at this time.
0 commit comments