-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
200 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by 顾艳华 on 2/10/24. | ||
// | ||
|
||
import Foundation | ||
import FeedKit | ||
|
||
public class RSSLoader: BaseLoader { | ||
let url: String | ||
|
||
public init(url: String, callbacks: [BaseCallbackHandler] = []) { | ||
self.url = url | ||
super.init(callbacks: callbacks) | ||
} | ||
public override func _load() async throws -> [Document] { | ||
let feedURL = URL(string: url)! | ||
let parser = FeedParser(URL: feedURL) | ||
let result = parser.parse() | ||
switch result { | ||
case .success(let feed): | ||
|
||
// Grab the parsed feed directly as an optional rss, atom or json feed object | ||
switch feed { | ||
case let .atom(feed): | ||
var content = [Document]() | ||
for f in feed.entries ?? [] { | ||
content.append(Document(page_content: f.title ?? "", metadata: [:])) | ||
} | ||
return content | ||
case let .rss(feed): | ||
var content = [Document]() | ||
for f in feed.items ?? [] { | ||
content.append(Document(page_content: f.title ?? "", metadata: [:])) | ||
} | ||
return content | ||
case let .json(feed): | ||
var content = [Document]() | ||
for f in feed.items ?? [] { | ||
content.append(Document(page_content: f.title ?? "", metadata: [:])) | ||
} | ||
return content | ||
} | ||
|
||
|
||
case .failure(let error): | ||
print(error) | ||
return [] | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// | ||
//// File.swift | ||
//// | ||
//// | ||
//// Created by 顾艳华 on 2/11/24. | ||
//// | ||
// | ||
//import Foundation | ||
//import SimilaritySearchKitDistilbert | ||
// | ||
//@available(macOS 13.0, *) | ||
//public struct Distilbert: Embeddings { | ||
// let n = DistilbertEmbeddings() | ||
// public init() { | ||
// | ||
// } | ||
// | ||
// | ||
// public func embedQuery(text: String) async -> [Float] { | ||
// await n.encode(sentence: text)! | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.