Files
AzooKeyKanaKanjiConverter/Sources/KanaKanjiConverterModule/Converter/ConvertRequestOptions.swift
Miwa 55ffe3c708 [Experimental] Zenzai (#92)
* experimental rinna integration

* Update impl

* update

* Bump swift-actions/setup-swift from 1 to 2

Bumps [swift-actions/setup-swift](https://github.com/swift-actions/setup-swift) from 1 to 2.
- [Release notes](https://github.com/swift-actions/setup-swift/releases)
- [Commits](https://github.com/swift-actions/setup-swift/compare/v1...v2)

---
updated-dependencies:
- dependency-name: swift-actions/setup-swift
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* change test

* change impl

* take gpt2 weight as option

* don't use async

* support status check

* enhance error

* avoid percent encode

* update

* GPT-2 based kana-kanji conversion is now perfectly workinggit statusgit status

* fix a bug

* Rename gpt2/llama -> zenz

* cleanup

* internal apiを綺麗にした

* cleanup experimental commands

* update

* partially support incremental input using cache

* fix names

* fix bug

* support roman2kana

* cleanup

* fix minor bugs

* improve logic

* fix minor bug

* fix minor bug

* fix minor bug

* optimize

* optimize performance

* Optimize cache hit

* cli: add anco session command

* fix cache hit bugs

* improve session commands

* maybe this will work better for incremental input environment

* speed up zenzai by using n_best alternatives

* update zenz context

* adding no_typo api

* add inference limit

* fix bug

* reset install_cli

* make package buildable -- but llama.cpp features just do not work at this point because metal is not preprocessed

* add proper availability checks

* change macOS minimum version

* fix several problems

* code cleanup

* enable ubuntu build

* fix build error

* fix ubuntu build

* fix borrowing

* update install_cli.sh

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-15 01:36:45 +09:00

160 lines
9.6 KiB
Swift

//
// ConvertRequestOptions.swift
// Keyboard
//
// Created by ensan on 2022/12/20.
// Copyright © 2022 ensan. All rights reserved.
//
import Foundation
public struct ConvertRequestOptions: Sendable {
///
///
/// - parameters:
/// - N_best: `N`
/// - requireJapanesePrediction: `false`
/// - requireEnglishPrediction: `false``false`
/// - keyboardLanguage:
/// - typographyLetterCandidate: `true``KanaKanjiConverter.typographicalCandidates(_:)`
/// - unicodeCandidate: `true``U+xxxx`Unicode`KanaKanjiConverter.unicodeCandidates(_:)``
/// - englishCandidateInRoman2KanaInput: `true``false`
/// - fullWidthRomanCandidate: `true`
/// - halfWidthKanaCandidate: `true`
/// - learningType: `LearningType`
/// - maxMemoryCount: `0``learningType``nothing`
/// - shouldResetMemory: `true`
/// - dictionaryResourceURL:
/// - memoryDirectoryURL:
/// - sharedContainerURL:
/// - textReplacer:
/// - metadata: `ConvertRequestOptions.Metadata`
public init(N_best: Int = 10, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, typographyLetterCandidate: Bool = false, unicodeCandidate: Bool = true, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer = TextReplacer(), zenzaiMode: ZenzaiMode = .off, metadata: ConvertRequestOptions.Metadata?) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
self.keyboardLanguage = keyboardLanguage
self.typographyLetterCandidate = typographyLetterCandidate
self.unicodeCandidate = unicodeCandidate
self.englishCandidateInRoman2KanaInput = englishCandidateInRoman2KanaInput
self.fullWidthRomanCandidate = fullWidthRomanCandidate
self.halfWidthKanaCandidate = halfWidthKanaCandidate
self.learningType = learningType
self.maxMemoryCount = maxMemoryCount
self.shouldResetMemory = shouldResetMemory
self.memoryDirectoryURL = memoryDirectoryURL
self.sharedContainerURL = sharedContainerURL
self.metadata = metadata
self.textReplacer = textReplacer
self.zenzaiMode = zenzaiMode
self.dictionaryResourceURL = dictionaryResourceURL
}
package init(N_best: Int = 10, requireJapanesePrediction: Bool, requireEnglishPrediction: Bool, keyboardLanguage: KeyboardLanguage, typographyLetterCandidate: Bool = false, unicodeCandidate: Bool = true, englishCandidateInRoman2KanaInput: Bool = false, fullWidthRomanCandidate: Bool = false, halfWidthKanaCandidate: Bool = false, learningType: LearningType, maxMemoryCount: Int = 65536, shouldResetMemory: Bool = false, dictionaryResourceURL: URL, memoryDirectoryURL: URL, sharedContainerURL: URL, textReplacer: TextReplacer = TextReplacer(), zenzaiMode: ZenzaiMode = .off, metadata: ConvertRequestOptions.Metadata?, requestQuery: RequestQuery) {
self.N_best = N_best
self.requireJapanesePrediction = requireJapanesePrediction
self.requireEnglishPrediction = requireEnglishPrediction
self.keyboardLanguage = keyboardLanguage
self.typographyLetterCandidate = typographyLetterCandidate
self.unicodeCandidate = unicodeCandidate
self.englishCandidateInRoman2KanaInput = englishCandidateInRoman2KanaInput
self.fullWidthRomanCandidate = fullWidthRomanCandidate
self.halfWidthKanaCandidate = halfWidthKanaCandidate
self.learningType = learningType
self.maxMemoryCount = maxMemoryCount
self.shouldResetMemory = shouldResetMemory
self.memoryDirectoryURL = memoryDirectoryURL
self.sharedContainerURL = sharedContainerURL
self.metadata = metadata
self.textReplacer = textReplacer
self.zenzaiMode = zenzaiMode
self.dictionaryResourceURL = dictionaryResourceURL
}
public var N_best: Int
public var requireJapanesePrediction: Bool
public var requireEnglishPrediction: Bool
public var keyboardLanguage: KeyboardLanguage
// KeyboardSettinginjection
public var typographyLetterCandidate: Bool
public var unicodeCandidate: Bool
public var englishCandidateInRoman2KanaInput: Bool
public var fullWidthRomanCandidate: Bool
public var halfWidthKanaCandidate: Bool
public var learningType: LearningType
public var maxMemoryCount: Int
public var shouldResetMemory: Bool
///
public var textReplacer: TextReplacer
//
public var memoryDirectoryURL: URL
public var sharedContainerURL: URL
public var dictionaryResourceURL: URL
public var zenzaiMode: ZenzaiMode
//
public var metadata: Metadata?
// MARK: API
package var requestQuery: RequestQuery = .default
static var `default`: Self {
Self(
N_best: 10,
requireJapanesePrediction: true,
requireEnglishPrediction: true,
keyboardLanguage: .ja_JP,
typographyLetterCandidate: false,
unicodeCandidate: true,
englishCandidateInRoman2KanaInput: true,
fullWidthRomanCandidate: true,
halfWidthKanaCandidate: false,
learningType: .inputAndOutput,
maxMemoryCount: 65536,
shouldResetMemory: false,
// dummy data, won't work
dictionaryResourceURL: Bundle.main.bundleURL,
// dummy data, won't work
memoryDirectoryURL: (try? FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)) ?? Bundle.main.bundleURL,
// dummy data, won't work
sharedContainerURL: Bundle.main.bundleURL,
metadata: nil
)
}
public struct Metadata: Sendable {
/// - parameters:
/// - appVersionString: `KanaKanjiCovnerter.toVersionCandidate(_:)`
@available(*, deprecated, renamed: "init(versionString:)", message: "it be removed in AzooKeyKanaKanjiConverter v1.0")
public init(appVersionString: String) {
self.versionString = "azooKey Version " + appVersionString
}
/// - parameters:
/// - versionString: `"MyIME Version 0.7.1"``KanaKanjiCovnerter.toVersionCandidate(_:)`
public init(versionString: String = "Powererd by AzooKeyKanaKanjiConverter") {
self.versionString = versionString
}
var versionString: String
}
package enum RequestQuery: Sendable {
case `default`
case
}
public struct ZenzaiMode: Sendable, Equatable {
public static let off = ZenzaiMode(enabled: false, weightURL: URL(fileURLWithPath: ""), inferenceLimit: 10)
/// activate *Zenzai* - Neural Kana-Kanji Conversiion Engine
/// - Parameters:
/// - weight: path for model weight (gguf)
/// - inferenceLimit: applying inference count limitation. Smaller limit makes conversion faster but quality will be worse. (Default: 10)
public static func on(weight: URL, inferenceLimit: Int = 10) -> Self {
ZenzaiMode(enabled: true, weightURL: weight, inferenceLimit: inferenceLimit)
}
var enabled: Bool
var weightURL: URL
var inferenceLimit: Int
}
}