-
Notifications
You must be signed in to change notification settings - Fork 43
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
38 changed files
with
979 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,5 @@ fastlane/metadata/trade_representative_contact_information | |
|
||
vendor/ | ||
.bundle/ | ||
|
||
Config.xcconfig |
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 |
---|---|---|
@@ -1 +1 @@ | ||
5.8 | ||
5.9 |
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
import Foundation | ||
import HTTPTypes | ||
import OpenAPIRuntime | ||
import OpenAPIURLSession | ||
|
||
protocol ChatAssistantProtocol { | ||
func generateSynthesis(content: String) async throws -> String | ||
func generateTags(content: String) async throws -> [String] | ||
} | ||
|
||
struct ChatAssistant: ChatAssistantProtocol { | ||
var client: Client { | ||
get throws { | ||
try Client( | ||
serverURL: Servers.server1(), | ||
transport: URLSessionTransport(), | ||
middlewares: [AuthenticationMiddleware()] | ||
) | ||
} | ||
} | ||
|
||
var locale = Locale.current.identifier | ||
|
||
func generateSynthesis(content: String) async throws -> String { | ||
let response = try await client.wallabagSynthesis(body: .json(.init(body: content, language: locale))) | ||
|
||
return try response.ok.body.json.content ?? "" | ||
} | ||
|
||
func generateTags(content: String) async throws -> [String] { | ||
let response = try await client.wallabagTags(body: .json(.init(body: content, language: locale))) | ||
|
||
return try response.ok.body.json.tags ?? [] | ||
} | ||
} | ||
|
||
private struct AuthenticationMiddleware: ClientMiddleware { | ||
@BundleKey("GPTBACK_KEY") | ||
private var gptBackKey | ||
|
||
func intercept( | ||
_ request: HTTPTypes.HTTPRequest, | ||
body: OpenAPIRuntime.HTTPBody?, | ||
baseURL: URL, | ||
operationID _: String, | ||
next: @Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, URL) async throws -> ( | ||
HTTPTypes.HTTPResponse, | ||
OpenAPIRuntime.HTTPBody? | ||
) | ||
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?) { | ||
var request = request | ||
request.headerFields[.authorization] = "Bearer \(gptBackKey)" | ||
|
||
return try await next(request, body, baseURL) | ||
} | ||
} |
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,57 @@ | ||
// | ||
// SynthesisEntryView.swift | ||
// wallabag | ||
// | ||
// Created by maxime marinel on 11/12/2023. | ||
// | ||
|
||
import Factory | ||
import SwiftUI | ||
|
||
final class SynthesisEntryViewModel: ObservableObject { | ||
@Injected(\.chatAssistant) private var chatAssistant | ||
@Published var synthesis = "" | ||
@Published var isLoading = false | ||
|
||
@MainActor | ||
func generateSynthesis(from entry: Entry) async throws { | ||
defer { | ||
isLoading = false | ||
} | ||
isLoading = true | ||
|
||
guard let content = entry.content?.withoutHTML else { return } | ||
|
||
synthesis = try await chatAssistant.generateSynthesis(content: content) | ||
} | ||
} | ||
|
||
struct SynthesisEntryView: View { | ||
@StateObject private var viewModel = SynthesisEntryViewModel() | ||
let entry: Entry | ||
|
||
var body: some View { | ||
ScrollView { | ||
if viewModel.isLoading { | ||
Text("Your assistant is working") | ||
ProgressView() | ||
} else { | ||
Text(viewModel.synthesis) | ||
.padding() | ||
.fontDesign(.serif) | ||
} | ||
} | ||
.navigationTitle("Synthesis") | ||
.task { | ||
do { | ||
try await viewModel.generateSynthesis(from: entry) | ||
} catch { | ||
print(error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// #Preview { | ||
// SynthesisEntryView(entry: .) | ||
// } |
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,78 @@ | ||
import Factory | ||
import SwiftUI | ||
|
||
final class TagSuggestionViewModel: ObservableObject { | ||
@Injected(\.chatAssistant) private var chatAssistant | ||
@Published var suggestions: [String] = [] | ||
@Published var isLoading = false | ||
|
||
@MainActor | ||
func generateSynthesis(from entry: Entry) async throws { | ||
defer { | ||
isLoading = false | ||
} | ||
isLoading = true | ||
|
||
guard let content = entry.content?.withoutHTML else { return } | ||
|
||
suggestions = try await chatAssistant.generateTags(content: content) | ||
} | ||
} | ||
|
||
struct TagSuggestionView: View { | ||
@StateObject private var viewModel = TagSuggestionViewModel() | ||
@State private var selection = Set<String>() | ||
|
||
let entry: Entry | ||
|
||
var body: some View { | ||
VStack { | ||
if viewModel.isLoading { | ||
Text("Your assistant is working") | ||
ProgressView() | ||
} else { | ||
List { | ||
ForEach(viewModel.suggestions, id: \.self) { suggestion in | ||
Button(action: { | ||
if selection.contains(suggestion) { | ||
selection.remove(suggestion) | ||
} else { | ||
selection.insert(suggestion) | ||
} | ||
}, label: { | ||
HStack { | ||
Text(suggestion) | ||
.padding() | ||
.fontDesign(.serif) | ||
Spacer() | ||
if selection.contains(suggestion) { | ||
Image(systemName: "checkmark.circle.fill") | ||
} else { | ||
Image(systemName: "circle") | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
.listStyle(.plain) | ||
if !selection.isEmpty { | ||
Button(action: {}, label: { | ||
Text("Add \(selection.count.formatted()) tags") | ||
}) | ||
} | ||
} | ||
} | ||
.navigationTitle("Tag suggestion") | ||
.task { | ||
do { | ||
try await viewModel.generateSynthesis(from: entry) | ||
} catch { | ||
print(error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// #Preview { | ||
// SynthesisEntryView(entry: .) | ||
// } |
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
25 changes: 25 additions & 0 deletions
25
App/Features/WallabagPlus/WallabagPlusProtectedModifier.swift
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,25 @@ | ||
import SwiftUI | ||
|
||
struct WallabagPlusProtectedModifier: ViewModifier { | ||
@EnvironmentObject private var wallabagPlusStore: WallabagPlusStore | ||
|
||
func body(content: Content) -> some View { | ||
VStack { | ||
if wallabagPlusStore.proUnlocked { | ||
content | ||
} else { | ||
Image("logo") | ||
.resizable() | ||
.scaledToFit() | ||
Text("Sorry, this feature require you subscribe to wallabag Plus") | ||
.fontDesign(.rounded) | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func wallabagPlusProtected() -> some View { | ||
modifier(WallabagPlusProtectedModifier()) | ||
} | ||
} |
Oops, something went wrong.