增加noawait,支持Azure API
parent
e21a28a85f
commit
2f68357c1d
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
DIRNAME=`dirname $0`
|
||||
cd $DIRNAME
|
||||
./.venv/bin/activate
|
@ -1,36 +1,36 @@
|
||||
from aiohttp import web
|
||||
import utils.web
|
||||
import utils.text
|
||||
from extend.hangul_romanize import Transliter
|
||||
from extend.hangul_romanize.rule import academic
|
||||
|
||||
class Hanja:
|
||||
@staticmethod
|
||||
def convertToRomaja(self, hanja: str):
|
||||
transliter = Transliter(academic)
|
||||
segList = utils.text.splitAscii(hanja)
|
||||
sentenceList = []
|
||||
for seg in segList:
|
||||
if seg == " ":
|
||||
sentenceList.append("-")
|
||||
elif utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
roma = transliter.translit(seg)
|
||||
sentenceList.append(roma.split(" "))
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def hanja2roma(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Hanja.convertToRomaja(sentence)
|
||||
return await utils.web.api_response(1, data, request=request)
|
||||
from aiohttp import web
|
||||
import utils.web
|
||||
import utils.text
|
||||
from extend.hangul_romanize import Transliter
|
||||
from extend.hangul_romanize.rule import academic
|
||||
|
||||
class Hanja:
|
||||
@staticmethod
|
||||
def convertToRomaja(self, hanja: str):
|
||||
transliter = Transliter(academic)
|
||||
segList = utils.text.splitAscii(hanja)
|
||||
sentenceList = []
|
||||
for seg in segList:
|
||||
if seg == " ":
|
||||
sentenceList.append("-")
|
||||
elif utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
roma = transliter.translit(seg)
|
||||
sentenceList.append(roma.split(" "))
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def hanja2roma(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Hanja.convertToRomaja(sentence)
|
||||
return await utils.web.api_response(1, data, request=request)
|
||||
|
@ -1,81 +1,81 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from aiohttp import web
|
||||
import os.path as path
|
||||
import jieba
|
||||
import jieba.posseg as pseg
|
||||
from pypinyin import pinyin, Style
|
||||
import utils.text
|
||||
import utils.web
|
||||
|
||||
jieba.initialize()
|
||||
userDict = path.dirname(path.dirname(path.dirname(__file__))) + "/data/userDict.txt"
|
||||
if path.exists(userDict):
|
||||
jieba.load_userdict(userDict)
|
||||
|
||||
|
||||
class Hanzi:
|
||||
@staticmethod
|
||||
def filterJiebaTag(segList: list[str]):
|
||||
ret = []
|
||||
for word, flag in segList:
|
||||
if flag[0] == "u" and (word == "得" or word == "地"):
|
||||
ret.append("的")
|
||||
else:
|
||||
ret.append(word)
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def convertToPinyin(sentence: str):
|
||||
sentence = utils.text.replaceCJKPunc(sentence).replace(' ', '-')
|
||||
segList = Hanzi.filterJiebaTag(pseg.cut(sentence))
|
||||
sentenceList = []
|
||||
pinyinGroup = []
|
||||
for seg in segList:
|
||||
if utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
pinyinGroup = []
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
pinyinGroup = []
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
sentencePinyin = []
|
||||
for one in pinyin(seg, style=Style.NORMAL):
|
||||
sentencePinyin.append(one[0])
|
||||
pinyinGroup.append(sentencePinyin)
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def hanziToPinyin(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Hanzi.convertToPinyin(sentence)
|
||||
return await utils.web.api_response(1, data, request=request)
|
||||
|
||||
@staticmethod
|
||||
async def splitHanzi(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get("sentence")
|
||||
|
||||
segList = list(pseg.cut(sentence))
|
||||
data = []
|
||||
for word, flag in segList:
|
||||
data.append({"word": word, "flag": flag})
|
||||
return await utils.web.api_response(1, data)
|
||||
from __future__ import annotations
|
||||
|
||||
from aiohttp import web
|
||||
import os.path as path
|
||||
import jieba
|
||||
import jieba.posseg as pseg
|
||||
from pypinyin import pinyin, Style
|
||||
import utils.text
|
||||
import utils.web
|
||||
|
||||
jieba.initialize()
|
||||
userDict = path.dirname(path.dirname(path.dirname(__file__))) + "/data/userDict.txt"
|
||||
if path.exists(userDict):
|
||||
jieba.load_userdict(userDict)
|
||||
|
||||
|
||||
class Hanzi:
|
||||
@staticmethod
|
||||
def filterJiebaTag(segList: list[str]):
|
||||
ret = []
|
||||
for word, flag in segList:
|
||||
if flag[0] == "u" and (word == "得" or word == "地"):
|
||||
ret.append("的")
|
||||
else:
|
||||
ret.append(word)
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def convertToPinyin(sentence: str):
|
||||
sentence = utils.text.replaceCJKPunc(sentence).replace(' ', '-')
|
||||
segList = Hanzi.filterJiebaTag(pseg.cut(sentence))
|
||||
sentenceList = []
|
||||
pinyinGroup = []
|
||||
for seg in segList:
|
||||
if utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
pinyinGroup = []
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
pinyinGroup = []
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
sentencePinyin = []
|
||||
for one in pinyin(seg, style=Style.NORMAL):
|
||||
sentencePinyin.append(one[0])
|
||||
pinyinGroup.append(sentencePinyin)
|
||||
if len(pinyinGroup) > 0:
|
||||
sentenceList.append(pinyinGroup)
|
||||
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def hanziToPinyin(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Hanzi.convertToPinyin(sentence)
|
||||
return await utils.web.api_response(1, data, request=request)
|
||||
|
||||
@staticmethod
|
||||
async def splitHanzi(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get("sentence")
|
||||
|
||||
segList = list(pseg.cut(sentence))
|
||||
data = []
|
||||
for word, flag in segList:
|
||||
data.append({"word": word, "flag": flag})
|
||||
return await utils.web.api_response(1, data)
|
||||
|
@ -1,32 +1,32 @@
|
||||
from aiohttp import web
|
||||
import utils.web
|
||||
import utils.text
|
||||
from extend.kanji_to_romaji import kanji_to_romaji
|
||||
|
||||
class Kanji:
|
||||
@staticmethod
|
||||
def convertToRomaji(self, kanji: str):
|
||||
segList = utils.text.splitAscii(kanji)
|
||||
sentenceList = []
|
||||
for seg in segList:
|
||||
if utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
romaji = kanji_to_romaji(seg)
|
||||
sentenceList.append(romaji.split(" "))
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def kanji2romaji(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Kanji.convertToRomaji(sentence)
|
||||
from aiohttp import web
|
||||
import utils.web
|
||||
import utils.text
|
||||
from extend.kanji_to_romaji import kanji_to_romaji
|
||||
|
||||
class Kanji:
|
||||
@staticmethod
|
||||
def convertToRomaji(self, kanji: str):
|
||||
segList = utils.text.splitAscii(kanji)
|
||||
sentenceList = []
|
||||
for seg in segList:
|
||||
if utils.text.isAscii(seg):
|
||||
if utils.text.isAsciiPunc(seg):
|
||||
sentenceList.append(seg)
|
||||
else:
|
||||
sentenceList.append([seg])
|
||||
else:
|
||||
romaji = kanji_to_romaji(seg)
|
||||
sentenceList.append(romaji.split(" "))
|
||||
return sentenceList
|
||||
|
||||
@staticmethod
|
||||
async def kanji2romaji(request: web.Request):
|
||||
params = await utils.web.get_param(request, {
|
||||
"sentence": {
|
||||
"required": True,
|
||||
},
|
||||
})
|
||||
sentence = params.get('sentence')
|
||||
|
||||
data = Kanji.convertToRomaji(sentence)
|
||||
return await utils.web.api_response(1, data, request=request)
|
@ -1,2 +1,2 @@
|
||||
|
||||
from .core import Transliter # noqa
|
||||
|
||||
from .core import Transliter # noqa
|
||||
|
@ -1,89 +1,89 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
try:
|
||||
unicode(0)
|
||||
except NameError:
|
||||
# py3
|
||||
unicode = str
|
||||
unichr = chr
|
||||
|
||||
|
||||
class Syllable(object):
|
||||
"""Hangul syllable interface"""
|
||||
|
||||
MIN = ord('가')
|
||||
MAX = ord('힣')
|
||||
|
||||
def __init__(self, char=None, code=None):
|
||||
if char is None and code is None:
|
||||
raise TypeError('__init__ takes char or code as a keyword argument (not given)')
|
||||
if char is not None and code is not None:
|
||||
raise TypeError('__init__ takes char or code as a keyword argument (both given)')
|
||||
if char:
|
||||
code = ord(char)
|
||||
if not self.MIN <= code <= self.MAX:
|
||||
raise TypeError('__init__ expected Hangul syllable but {0} not in [{1}..{2}]'.format(code, self.MIN, self.MAX))
|
||||
self.code = code
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self.code - self.MIN
|
||||
|
||||
@property
|
||||
def initial(self):
|
||||
return self.index // 588
|
||||
|
||||
@property
|
||||
def vowel(self):
|
||||
return (self.index // 28) % 21
|
||||
|
||||
@property
|
||||
def final(self):
|
||||
return self.index % 28
|
||||
|
||||
@property
|
||||
def char(self):
|
||||
return unichr(self.code)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.char
|
||||
|
||||
def __repr__(self):
|
||||
return '''<Syllable({}({}),{}({}),{}({}),{}({}))>'''.format(
|
||||
self.code, self.char, self.initial, '', self.vowel, '', self.final, '')
|
||||
|
||||
|
||||
class Transliter(object):
|
||||
"""General transliting interface"""
|
||||
|
||||
def __init__(self, rule):
|
||||
self.rule = rule
|
||||
|
||||
def translit(self, text):
|
||||
"""Translit text to romanized text
|
||||
|
||||
:param text: Unicode string or unicode character iterator
|
||||
"""
|
||||
result = []
|
||||
pre = None, None
|
||||
now = None, None
|
||||
for c in text:
|
||||
try:
|
||||
post = c, Syllable(c)
|
||||
except TypeError:
|
||||
post = c, None
|
||||
|
||||
if now[0] is not None:
|
||||
out = self.rule(now, pre=pre, post=post)
|
||||
if out is not None:
|
||||
result.append(out)
|
||||
|
||||
pre = now
|
||||
now = post
|
||||
|
||||
if now is not None:
|
||||
out = self.rule(now, pre=pre, post=(None, None))
|
||||
if out is not None:
|
||||
result.append(out)
|
||||
|
||||
return ''.join(result)
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
try:
|
||||
unicode(0)
|
||||
except NameError:
|
||||
# py3
|
||||
unicode = str
|
||||
unichr = chr
|
||||
|
||||
|
||||
class Syllable(object):
|
||||
"""Hangul syllable interface"""
|
||||
|
||||
MIN = ord('가')
|
||||
MAX = ord('힣')
|
||||
|
||||
def __init__(self, char=None, code=None):
|
||||
if char is None and code is None:
|
||||
raise TypeError('__init__ takes char or code as a keyword argument (not given)')
|
||||
if char is not None and code is not None:
|
||||
raise TypeError('__init__ takes char or code as a keyword argument (both given)')
|
||||
if char:
|
||||
code = ord(char)
|
||||
if not self.MIN <= code <= self.MAX:
|
||||
raise TypeError('__init__ expected Hangul syllable but {0} not in [{1}..{2}]'.format(code, self.MIN, self.MAX))
|
||||
self.code = code
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
return self.code - self.MIN
|
||||
|
||||
@property
|
||||
def initial(self):
|
||||
return self.index // 588
|
||||
|
||||
@property
|
||||
def vowel(self):
|
||||
return (self.index // 28) % 21
|
||||
|
||||
@property
|
||||
def final(self):
|
||||
return self.index % 28
|
||||
|
||||
@property
|
||||
def char(self):
|
||||
return unichr(self.code)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.char
|
||||
|
||||
def __repr__(self):
|
||||
return '''<Syllable({}({}),{}({}),{}({}),{}({}))>'''.format(
|
||||
self.code, self.char, self.initial, '', self.vowel, '', self.final, '')
|
||||
|
||||
|
||||
class Transliter(object):
|
||||
"""General transliting interface"""
|
||||
|
||||
def __init__(self, rule):
|
||||
self.rule = rule
|
||||
|
||||
def translit(self, text):
|
||||
"""Translit text to romanized text
|
||||
|
||||
:param text: Unicode string or unicode character iterator
|
||||
"""
|
||||
result = []
|
||||
pre = None, None
|
||||
now = None, None
|
||||
for c in text:
|
||||
try:
|
||||
post = c, Syllable(c)
|
||||
except TypeError:
|
||||
post = c, None
|
||||
|
||||
if now[0] is not None:
|
||||
out = self.rule(now, pre=pre, post=post)
|
||||
if out is not None:
|
||||
result.append(out)
|
||||
|
||||
pre = now
|
||||
now = post
|
||||
|
||||
if now is not None:
|
||||
out = self.rule(now, pre=pre, post=(None, None))
|
||||
if out is not None:
|
||||
result.append(out)
|
||||
|
||||
return ''.join(result)
|
||||
|
@ -1,47 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
REVISED_INITIALS = 'g', 'kk', 'n', 'd', 'tt', 'l', 'm', 'b', 'pp', 's', 'ss', '', 'j', 'jj', 'ch', 'k', 't', 'p', 'h'
|
||||
REVISED_VOWELS = 'a', 'ae', 'ya', 'yae', 'eo', 'e', 'yeo', 'ye', 'o', 'wa', 'wae', 'oe', 'yo', 'u', 'wo', 'we', 'wi', 'yu', 'eu', 'ui', 'i'
|
||||
REVISED_FINALS = '', 'g', 'kk', 'gs', 'n', 'nj', 'nh', 'd', 'l', 'lg', 'lm', 'lb', 'ls', 'lt', 'lp', 'lh', 'm', 'b', 'bs', 's', 'ss', 'ng', 'j', 'ch', 'k', 't', 'p', 'h'
|
||||
|
||||
|
||||
def academic_ambiguous_patterns():
|
||||
import itertools
|
||||
result = set()
|
||||
for final, initial in itertools.product(REVISED_FINALS, REVISED_INITIALS):
|
||||
check = False
|
||||
combined = final + initial
|
||||
for i in range(len(combined)):
|
||||
head, tail = combined[:i], combined[i:]
|
||||
if head in REVISED_FINALS and tail in REVISED_INITIALS:
|
||||
if not check:
|
||||
check = True
|
||||
else:
|
||||
result.add(combined)
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
ACADEMIC_AMBIGUOUS_PATTERNS = academic_ambiguous_patterns()
|
||||
|
||||
|
||||
def academic(now, pre, **options):
|
||||
"""Rule for academic translition."""
|
||||
c, s = now
|
||||
if not s:
|
||||
return c
|
||||
|
||||
ps = pre[1] if pre else None
|
||||
|
||||
marker = False
|
||||
if ps:
|
||||
if s.initial == 11:
|
||||
marker = True
|
||||
elif ps and (REVISED_FINALS[ps.final] + REVISED_INITIALS[s.initial]) in ACADEMIC_AMBIGUOUS_PATTERNS:
|
||||
marker = True
|
||||
|
||||
r = u''
|
||||
if marker:
|
||||
r += '-'
|
||||
r += REVISED_INITIALS[s.initial] + REVISED_VOWELS[s.vowel] + REVISED_FINALS[s.final]
|
||||
return r
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
REVISED_INITIALS = 'g', 'kk', 'n', 'd', 'tt', 'l', 'm', 'b', 'pp', 's', 'ss', '', 'j', 'jj', 'ch', 'k', 't', 'p', 'h'
|
||||
REVISED_VOWELS = 'a', 'ae', 'ya', 'yae', 'eo', 'e', 'yeo', 'ye', 'o', 'wa', 'wae', 'oe', 'yo', 'u', 'wo', 'we', 'wi', 'yu', 'eu', 'ui', 'i'
|
||||
REVISED_FINALS = '', 'g', 'kk', 'gs', 'n', 'nj', 'nh', 'd', 'l', 'lg', 'lm', 'lb', 'ls', 'lt', 'lp', 'lh', 'm', 'b', 'bs', 's', 'ss', 'ng', 'j', 'ch', 'k', 't', 'p', 'h'
|
||||
|
||||
|
||||
def academic_ambiguous_patterns():
|
||||
import itertools
|
||||
result = set()
|
||||
for final, initial in itertools.product(REVISED_FINALS, REVISED_INITIALS):
|
||||
check = False
|
||||
combined = final + initial
|
||||
for i in range(len(combined)):
|
||||
head, tail = combined[:i], combined[i:]
|
||||
if head in REVISED_FINALS and tail in REVISED_INITIALS:
|
||||
if not check:
|
||||
check = True
|
||||
else:
|
||||
result.add(combined)
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
ACADEMIC_AMBIGUOUS_PATTERNS = academic_ambiguous_patterns()
|
||||
|
||||
|
||||
def academic(now, pre, **options):
|
||||
"""Rule for academic translition."""
|
||||
c, s = now
|
||||
if not s:
|
||||
return c
|
||||
|
||||
ps = pre[1] if pre else None
|
||||
|
||||
marker = False
|
||||
if ps:
|
||||
if s.initial == 11:
|
||||
marker = True
|
||||
elif ps and (REVISED_FINALS[ps.final] + REVISED_INITIALS[s.initial]) in ACADEMIC_AMBIGUOUS_PATTERNS:
|
||||
marker = True
|
||||
|
||||
r = u''
|
||||
if marker:
|
||||
r += '-'
|
||||
r += REVISED_INITIALS[s.initial] + REVISED_VOWELS[s.vowel] + REVISED_FINALS[s.final]
|
||||
return r
|
||||
|
@ -1,5 +1,5 @@
|
||||
from .kanji_to_romaji_module import convert_hiragana_to_katakana, translate_to_romaji, translate_soukon, \
|
||||
translate_long_vowel, translate_soukon_ch, kanji_to_romaji
|
||||
__all__ = ["load_mappings_dict", "convert_hiragana_to_katakana", "convert_katakana_to_hiragana",
|
||||
"translate_to_romaji", "translate_soukon",
|
||||
"translate_long_vowel", "translate_soukon_ch", "kanji_to_romaji"]
|
||||
from .kanji_to_romaji_module import convert_hiragana_to_katakana, translate_to_romaji, translate_soukon, \
|
||||
translate_long_vowel, translate_soukon_ch, kanji_to_romaji
|
||||
__all__ = ["load_mappings_dict", "convert_hiragana_to_katakana", "convert_katakana_to_hiragana",
|
||||
"translate_to_romaji", "translate_soukon",
|
||||
"translate_long_vowel", "translate_soukon_ch", "kanji_to_romaji"]
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,120 +1,120 @@
|
||||
{
|
||||
"ぁ": "a",
|
||||
"あ": "a",
|
||||
"ぃ": "i",
|
||||
"い": "i",
|
||||
"ぅ": "u",
|
||||
"う": "u",
|
||||
"ぇ": "e",
|
||||
"え": "e",
|
||||
"ぉ": "o",
|
||||
"お": "o",
|
||||
"か": "ka",
|
||||
"が": "ga",
|
||||
"き": "ki",
|
||||
"きゃ": "kya",
|
||||
"きゅ": "kyu",
|
||||
"きょ": "kyo",
|
||||
"ぎ": "gi",
|
||||
"ぎゃ": "gya",
|
||||
"ぎゅ": "gyu",
|
||||
"ぎょ": "gyo",
|
||||
"く": "ku",
|
||||
"ぐ": "gu",
|
||||
"け": "ke",
|
||||
"げ": "ge",
|
||||
"こ": "ko",
|
||||
"ご": "go",
|
||||
"さ": "sa",
|
||||
"ざ": "za",
|
||||
"し": "shi",
|
||||
"しゃ": "sha",
|
||||
"しゅ": "shu",
|
||||
"しょ": "sho",
|
||||
"じ": "ji",
|
||||
"じゃ": "ja",
|
||||
"じゅ": "ju",
|
||||
"じょ": "jo",
|
||||
"す": "su",
|
||||
"ず": "zu",
|
||||
"せ": "se",
|
||||
"ぜ": "ze",
|
||||
"そ": "so",
|
||||
"ぞ": "zo",
|
||||
"た": "ta",
|
||||
"だ": "da",
|
||||
"ち": "chi",
|
||||
"ちゃ": "cha",
|
||||
"ちゅ": "chu",
|
||||
"ちょ": "cho",
|
||||
"ぢ": "ji",
|
||||
"つ": "tsu",
|
||||
"づ": "zu",
|
||||
"て": "te",
|
||||
"で": "de",
|
||||
"と": "to",
|
||||
"ど": "do",
|
||||
"な": "na",
|
||||
"に": "ni",
|
||||
"にゃ": "nya",
|
||||
"にゅ": "nyu",
|
||||
"にょ": "nyo",
|
||||
"ぬ": "nu",
|
||||
"ね": "ne",
|
||||
"の": "no",
|
||||
"は": "ha",
|
||||
"ば": "ba",
|
||||
"ぱ": "pa",
|
||||
"ひ": "hi",
|
||||
"ひゃ": "hya",
|
||||
"ひゅ": "hyu",
|
||||
"ひょ": "hyo",
|
||||
"び": "bi",
|
||||
"びゃ": "bya",
|
||||
"びゅ": "byu",
|
||||
"びょ": "byo",
|
||||
"ぴ": "pi",
|
||||
"ぴゃ": "pya",
|
||||
"ぴゅ": "pyu",
|
||||
"ぴょ": "pyo",
|
||||
"ふ": "fu",
|
||||
"ぶ": "bu",
|
||||
"ぷ": "pu",
|
||||
"へ": "he",
|
||||
"べ": "be",
|
||||
"ぺ": "pe",
|
||||
"ほ": "ho",
|
||||
"ぼ": "bo",
|
||||
"ぽ": "po",
|
||||
"ま": "ma",
|
||||
"み": "mi",
|
||||
"みゃ": "mya",
|
||||
"みゅ": "myu",
|
||||
"みょ": "myo",
|
||||
"む": "mu",
|
||||
"め": "me",
|
||||
"も": "mo",
|
||||
"や": "ya",
|
||||
"ゆ": "yu",
|
||||
"よ": "yo",
|
||||
"ら": "ra",
|
||||
"り": "ri",
|
||||
"りゃ": "rya",
|
||||
"りゅ": "ryu",
|
||||
"りょ": "ryo",
|
||||
"る": "ru",
|
||||
"れ": "re",
|
||||
"ろ": "ro",
|
||||
"ゎ": "wa",
|
||||
"わ": "wa",
|
||||
"ゐ": "wi",
|
||||
"ゑ": "we",
|
||||
"を": " wo ",
|
||||
"ん": "n",
|
||||
"ゔ": "vu",
|
||||
"ゕ": "ka",
|
||||
"ゖ": "ke",
|
||||
"ゝ": "iteration_mark",
|
||||
"ゞ": "voiced_iteration_mark",
|
||||
"ゟ": "yori"
|
||||
{
|
||||
"ぁ": "a",
|
||||
"あ": "a",
|
||||
"ぃ": "i",
|
||||
"い": "i",
|
||||
"ぅ": "u",
|
||||
"う": "u",
|
||||
"ぇ": "e",
|
||||
"え": "e",
|
||||
"ぉ": "o",
|
||||
"お": "o",
|
||||
"か": "ka",
|
||||
"が": "ga",
|
||||
"き": "ki",
|
||||
"きゃ": "kya",
|
||||
"きゅ": "kyu",
|
||||
"きょ": "kyo",
|
||||
"ぎ": "gi",
|
||||
"ぎゃ": "gya",
|
||||
"ぎゅ": "gyu",
|
||||
"ぎょ": "gyo",
|
||||
"く": "ku",
|
||||
"ぐ": "gu",
|
||||
"け": "ke",
|
||||
"げ": "ge",
|
||||
"こ": "ko",
|
||||
"ご": "go",
|
||||
"さ": "sa",
|
||||
"ざ": "za",
|
||||
"し": "shi",
|
||||
"しゃ": "sha",
|
||||
"しゅ": "shu",
|
||||
"しょ": "sho",
|
||||
"じ": "ji",
|
||||
"じゃ": "ja",
|
||||
"じゅ": "ju",
|
||||
"じょ": "jo",
|
||||
"す": "su",
|
||||
"ず": "zu",
|
||||
"せ": "se",
|
||||
"ぜ": "ze",
|
||||
"そ": "so",
|
||||
"ぞ": "zo",
|
||||
"た": "ta",
|
||||
"だ": "da",
|
||||
"ち": "chi",
|
||||
"ちゃ": "cha",
|
||||
"ちゅ": "chu",
|
||||
"ちょ": "cho",
|
||||
"ぢ": "ji",
|
||||
"つ": "tsu",
|
||||
"づ": "zu",
|
||||
"て": "te",
|
||||
"で": "de",
|
||||
"と": "to",
|
||||
"ど": "do",
|
||||
"な": "na",
|
||||
"に": "ni",
|
||||
"にゃ": "nya",
|
||||
"にゅ": "nyu",
|
||||
"にょ": "nyo",
|
||||
"ぬ": "nu",
|
||||
"ね": "ne",
|
||||
"の": "no",
|
||||
"は": "ha",
|
||||
"ば": "ba",
|
||||
"ぱ": "pa",
|
||||
"ひ": "hi",
|
||||
"ひゃ": "hya",
|
||||
"ひゅ": "hyu",
|
||||
"ひょ": "hyo",
|
||||
"び": "bi",
|
||||
"びゃ": "bya",
|
||||
"びゅ": "byu",
|
||||
"びょ": "byo",
|
||||
"ぴ": "pi",
|
||||
"ぴゃ": "pya",
|
||||
"ぴゅ": "pyu",
|
||||
"ぴょ": "pyo",
|
||||
"ふ": "fu",
|
||||
"ぶ": "bu",
|
||||
"ぷ": "pu",
|
||||
"へ": "he",
|
||||
"べ": "be",
|
||||
"ぺ": "pe",
|
||||
"ほ": "ho",
|
||||
"ぼ": "bo",
|
||||
"ぽ": "po",
|
||||
"ま": "ma",
|
||||
"み": "mi",
|
||||
"みゃ": "mya",
|
||||
"みゅ": "myu",
|
||||
"みょ": "myo",
|
||||
"む": "mu",
|
||||
"め": "me",
|
||||
"も": "mo",
|
||||
"や": "ya",
|
||||
"ゆ": "yu",
|
||||
"よ": "yo",
|
||||
"ら": "ra",
|
||||
"り": "ri",
|
||||
"りゃ": "rya",
|
||||
"りゅ": "ryu",
|
||||
"りょ": "ryo",
|
||||
"る": "ru",
|
||||
"れ": "re",
|
||||
"ろ": "ro",
|
||||
"ゎ": "wa",
|
||||
"わ": "wa",
|
||||
"ゐ": "wi",
|
||||
"ゑ": "we",
|
||||
"を": " wo ",
|
||||
"ん": "n",
|
||||
"ゔ": "vu",
|
||||
"ゕ": "ka",
|
||||
"ゖ": "ke",
|
||||
"ゝ": "iteration_mark",
|
||||
"ゞ": "voiced_iteration_mark",
|
||||
"ゟ": "yori"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,18 @@
|
||||
{
|
||||
"今日": {
|
||||
"w_type": "noun",
|
||||
"romaji": "kyou"
|
||||
},
|
||||
"明日": {
|
||||
"w_type": "noun",
|
||||
"romaji": "ashita"
|
||||
},
|
||||
"本": {
|
||||
"w_type": "noun",
|
||||
"romaji": "hon"
|
||||
},
|
||||
"中": {
|
||||
"w_type": "noun",
|
||||
"romaji": "naka"
|
||||
}
|
||||
{
|
||||
"今日": {
|
||||
"w_type": "noun",
|
||||
"romaji": "kyou"
|
||||
},
|
||||
"明日": {
|
||||
"w_type": "noun",
|
||||
"romaji": "ashita"
|
||||
},
|
||||
"本": {
|
||||
"w_type": "noun",
|
||||
"romaji": "hon"
|
||||
},
|
||||
"中": {
|
||||
"w_type": "noun",
|
||||
"romaji": "naka"
|
||||
}
|
||||
}
|
@ -1,78 +1,78 @@
|
||||
{
|
||||
"朝日奈丸佳": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Asahina Madoka"
|
||||
},
|
||||
"高海千歌": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Takami Chika"
|
||||
},
|
||||
"鏡音レン": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kagamine Len"
|
||||
},
|
||||
"鏡音リン": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kagamine Rin"
|
||||
},
|
||||
"逢坂大河": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Aisaka Taiga"
|
||||
},
|
||||
"水樹奈々": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Mizuki Nana"
|
||||
},
|
||||
"桜内梨子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Sakurauchi Riko"
|
||||
},
|
||||
"山吹沙綾": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Yamabuki Saaya"
|
||||
},
|
||||
"初音ミク": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Hatsune Miku"
|
||||
},
|
||||
"渡辺曜": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Watanabe You"
|
||||
},
|
||||
"原由実": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Hara Yumi"
|
||||
},
|
||||
"北宇治": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kita Uji"
|
||||
},
|
||||
"六本木": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Roppongi"
|
||||
},
|
||||
"久美子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kumiko"
|
||||
},
|
||||
"政宗": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Masamune"
|
||||
},
|
||||
"小林": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kobayashi"
|
||||
},
|
||||
"奥寺": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Okudera"
|
||||
},
|
||||
"佐藤": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Satou"
|
||||
},
|
||||
"玲子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Reiko"
|
||||
}
|
||||
{
|
||||
"朝日奈丸佳": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Asahina Madoka"
|
||||
},
|
||||
"高海千歌": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Takami Chika"
|
||||
},
|
||||
"鏡音レン": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kagamine Len"
|
||||
},
|
||||
"鏡音リン": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kagamine Rin"
|
||||
},
|
||||
"逢坂大河": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Aisaka Taiga"
|
||||
},
|
||||
"水樹奈々": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Mizuki Nana"
|
||||
},
|
||||
"桜内梨子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Sakurauchi Riko"
|
||||
},
|
||||
"山吹沙綾": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Yamabuki Saaya"
|
||||
},
|
||||
"初音ミク": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Hatsune Miku"
|
||||
},
|
||||
"渡辺曜": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Watanabe You"
|
||||
},
|
||||
"原由実": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Hara Yumi"
|
||||
},
|
||||
"北宇治": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kita Uji"
|
||||
},
|
||||
"六本木": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Roppongi"
|
||||
},
|
||||
"久美子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kumiko"
|
||||
},
|
||||
"政宗": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Masamune"
|
||||
},
|
||||
"小林": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Kobayashi"
|
||||
},
|
||||
"奥寺": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Okudera"
|
||||
},
|
||||
"佐藤": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Satou"
|
||||
},
|
||||
"玲子": {
|
||||
"w_type": "noun",
|
||||
"romaji": "Reiko"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,29 +1,29 @@
|
||||
class KanjiBlock(str):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
obj = str.__new__(cls, "@")
|
||||
kanji = args[0]
|
||||
kanji_dict = args[1]
|
||||
|
||||
obj.kanji = kanji
|
||||
if len(kanji) == 1:
|
||||
obj.romaji = " " + kanji_dict["romaji"]
|
||||
else:
|
||||
if "verb stem" in kanji_dict["w_type"]:
|
||||
obj.romaji = " " + kanji_dict["romaji"]
|
||||
else:
|
||||
obj.romaji = " " + kanji_dict["romaji"] + " "
|
||||
|
||||
if "other_readings" in kanji_dict:
|
||||
obj.w_type = [kanji_dict["w_type"]]
|
||||
obj.w_type.extend(
|
||||
[k for k in kanji_dict["other_readings"].keys()]
|
||||
)
|
||||
else:
|
||||
obj.w_type = kanji_dict["w_type"]
|
||||
return obj
|
||||
|
||||
def __repr__(self):
|
||||
return self.kanji.encode("unicode_escape")
|
||||
|
||||
def __str__(self):
|
||||
return self.romaji.encode("utf-8")
|
||||
class KanjiBlock(str):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
obj = str.__new__(cls, "@")
|
||||
kanji = args[0]
|
||||
kanji_dict = args[1]
|
||||
|
||||
obj.kanji = kanji
|
||||
if len(kanji) == 1:
|
||||
obj.romaji = " " + kanji_dict["romaji"]
|
||||
else:
|
||||
if "verb stem" in kanji_dict["w_type"]:
|
||||
obj.romaji = " " + kanji_dict["romaji"]
|
||||
else:
|
||||
obj.romaji = " " + kanji_dict["romaji"] + " "
|
||||
|
||||
if "other_readings" in kanji_dict:
|
||||
obj.w_type = [kanji_dict["w_type"]]
|
||||
obj.w_type.extend(
|
||||
[k for k in kanji_dict["other_readings"].keys()]
|
||||
)
|
||||
else:
|
||||
obj.w_type = kanji_dict["w_type"]
|
||||
return obj
|
||||
|
||||
def __repr__(self):
|
||||
return self.kanji.encode("unicode_escape")
|
||||
|
||||
def __str__(self):
|
||||
return self.romaji.encode("utf-8")
|
||||
|
@ -1,6 +1,6 @@
|
||||
class Particle(str):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
particle_str = args[0]
|
||||
obj = str.__new__(cls, " " + particle_str + " ")
|
||||
obj.pname = particle_str
|
||||
return obj
|
||||
class Particle(str):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
particle_str = args[0]
|
||||
obj = str.__new__(cls, " " + particle_str + " ")
|
||||
obj.pname = particle_str
|
||||
return obj
|
||||
|
@ -1,4 +1,4 @@
|
||||
# noinspection PyClassHasNoInit
|
||||
class UnicodeRomajiMapping: # caching
|
||||
kana_mapping = {}
|
||||
kanji_mapping = {}
|
||||
# noinspection PyClassHasNoInit
|
||||
class UnicodeRomajiMapping: # caching
|
||||
kana_mapping = {}
|
||||
kanji_mapping = {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
from .UnicodeRomajiMapping import UnicodeRomajiMapping
|
||||
from .KanjiBlock import KanjiBlock
|
||||
from .Particle import Particle
|
||||
|
||||
__all__ = ["UnicodeRomajiMapping", "KanjiBlock", "Particle"]
|
||||
from .UnicodeRomajiMapping import UnicodeRomajiMapping
|
||||
from .KanjiBlock import KanjiBlock
|
||||
from .Particle import Particle
|
||||
|
||||
__all__ = ["UnicodeRomajiMapping", "KanjiBlock", "Particle"]
|
||||
|
@ -0,0 +1,5 @@
|
||||
import asyncio
|
||||
from noawait import NoAwaitPool
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
noawait = NoAwaitPool(loop)
|
@ -1,51 +1,65 @@
|
||||
import asyncio
|
||||
from typing import TypedDict
|
||||
from aiohttp import web
|
||||
import asyncpg
|
||||
import config
|
||||
import api.route
|
||||
import utils.web
|
||||
from service.database import DatabaseService
|
||||
from service.mediawiki_api import MediaWikiApi
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
|
||||
|
||||
from service.tiktoken import TikTokenService
|
||||
|
||||
async def index(request: web.Request):
|
||||
return utils.web.api_response(1, data={"message": "Isekai toolkit API"}, request=request)
|
||||
|
||||
async def init_mw_api(app: web.Application):
|
||||
mw_api = MediaWikiApi.create()
|
||||
if config.MW_BOT_LOGIN_USERNAME and config.MW_BOT_LOGIN_PASSWORD:
|
||||
await mw_api.robot_login(config.MW_BOT_LOGIN_USERNAME, config.MW_BOT_LOGIN_PASSWORD)
|
||||
|
||||
site_meta = await mw_api.get_site_meta()
|
||||
|
||||
print("Connected to Wiki %s, Robot username: %s" % (site_meta["sitename"], site_meta["user"]))
|
||||
|
||||
async def init_database(app: web.Application):
|
||||
dbs = await DatabaseService.create(app)
|
||||
print("Database connected.")
|
||||
|
||||
async def init_tiktoken(app: web.Application):
|
||||
await TikTokenService.create()
|
||||
print("Tiktoken model loaded.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
app = web.Application()
|
||||
|
||||
if config.DATABASE:
|
||||
app.on_startup.append(init_database)
|
||||
|
||||
if config.MW_API:
|
||||
app.on_startup.append(init_mw_api)
|
||||
|
||||
if config.OPENAI_TOKEN:
|
||||
app.on_startup.append(init_tiktoken)
|
||||
|
||||
app.router.add_route('*', '/', index)
|
||||
api.route.init(app)
|
||||
web.run_app(app, host='0.0.0.0', port=config.PORT, loop=loop)
|
||||
|
||||
from local import loop, noawait
|
||||
|
||||
from aiohttp import web
|
||||
import config
|
||||
import api.route
|
||||
import utils.web
|
||||
from service.database import DatabaseService
|
||||
from service.mediawiki_api import MediaWikiApi
|
||||
|
||||
# Auto create Table
|
||||
from api.model.base import BaseModel
|
||||
from api.model.toolkit_ui.conversation import ConversationModel as _
|
||||
from api.model.chat_complete.conversation import ConversationChunkModel as _
|
||||
from api.model.embedding_search.title_collection import TitleCollectionModel as _
|
||||
from api.model.embedding_search.title_index import TitleIndexModel as _
|
||||
|
||||
from service.tiktoken import TikTokenService
|
||||
|
||||
async def index(request: web.Request):
|
||||
return utils.web.api_response(1, data={"message": "Isekai toolkit API"}, request=request)
|
||||
|
||||
async def init_mw_api(app: web.Application):
|
||||
mw_api = MediaWikiApi.create()
|
||||
if config.MW_BOT_LOGIN_USERNAME and config.MW_BOT_LOGIN_PASSWORD:
|
||||
try:
|
||||
await mw_api.robot_login(config.MW_BOT_LOGIN_USERNAME, config.MW_BOT_LOGIN_PASSWORD)
|
||||
except Exception as e:
|
||||
print("Cannot login to Robot account, please check config.")
|
||||
|
||||
site_meta = await mw_api.get_site_meta()
|
||||
|
||||
print("Connected to Wiki %s, Robot username: %s" % (site_meta["sitename"], site_meta["user"]))
|
||||
|
||||
async def init_database(app: web.Application):
|
||||
dbs = await DatabaseService.create(app)
|
||||
print("Database connected.")
|
||||
|
||||
async with dbs.engine.begin() as conn:
|
||||
await conn.run_sync(BaseModel.metadata.create_all)
|
||||
|
||||
async def init_tiktoken(app: web.Application):
|
||||
await TikTokenService.create()
|
||||
print("Tiktoken model loaded.")
|
||||
|
||||
async def stop_noawait_pool(app: web.Application):
|
||||
await noawait.end()
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = web.Application()
|
||||
|
||||
if config.DATABASE:
|
||||
app.on_startup.append(init_database)
|
||||
|
||||
if config.MW_API:
|
||||
app.on_startup.append(init_mw_api)
|
||||
|
||||
if config.OPENAI_TOKEN:
|
||||
app.on_startup.append(init_tiktoken)
|
||||
|
||||
app.on_shutdown.append(stop_noawait_pool)
|
||||
|
||||
app.router.add_route('*', '/', index)
|
||||
api.route.init(app)
|
||||
|
||||
web.run_app(app, host='0.0.0.0', port=config.PORT, loop=loop)
|
@ -0,0 +1,72 @@
|
||||
from __future__ import annotations
|
||||
from asyncio import AbstractEventLoop, Task
|
||||
import asyncio
|
||||
from functools import wraps
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
from typing import Callable, Coroutine
|
||||
|
||||
class NoAwaitPool:
|
||||
def __init__(self, loop: AbstractEventLoop):
|
||||
self.task_list: list[Task] = []
|
||||
self.loop = loop
|
||||
self.running = True
|
||||
|
||||
self.on_error: list[Callable] = []
|
||||
|
||||
self.gc_task = loop.create_task(self._run_gc())
|
||||
|
||||
async def end(self):
|
||||
print("Stopping NoAwait Tasks...")
|
||||
self.running = False
|
||||
for task in self.task_list:
|
||||
await self._finish_task(task)
|
||||
|
||||
await self.gc_task
|
||||
|
||||
def add_task(self, coroutine: Coroutine):
|
||||
task = self.loop.create_task(coroutine)
|
||||
self.task_list.append(task)
|
||||
|
||||
def wrap(self, f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
coroutine = f(*args, **kwargs)
|
||||
self.add_task(coroutine)
|
||||
|
||||
return decorated_function
|
||||
|
||||
async def _finish_task(self, task: Task):
|
||||
try:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
await task
|
||||
except Exception as e:
|
||||
handled = False
|
||||
for handler in self.on_error:
|
||||
try:
|
||||
handler_ret = handler(e)
|
||||
if handler_ret is Coroutine:
|
||||
await handler_ret
|
||||
handled = True
|
||||
except Exception as handler_err:
|
||||
print("Exception on error handler: " + str(handler_err), file=sys.stderr)
|
||||
traceback.print_exc()
|
||||
|
||||
if not handled:
|
||||
print(e, file=sys.stderr)
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
async def _run_gc(self):
|
||||
while self.running:
|
||||
should_remove = []
|
||||
for task in self.task_list:
|
||||
if task.done():
|
||||
await self._finish_task(task)
|
||||
should_remove.append(task)
|
||||
for task in should_remove:
|
||||
self.task_list.remove(task)
|
||||
|
||||
await asyncio.sleep(0.1)
|
@ -1,16 +1,17 @@
|
||||
aiohttp==3.8.4
|
||||
jieba==0.42.1
|
||||
pypinyin==0.37.0
|
||||
simplejson==3.17.0
|
||||
beautifulsoup4==4.11.2
|
||||
markdownify==0.11.6
|
||||
asyncpg==0.27.0
|
||||
aiofiles==23.1.0
|
||||
pgvector==0.1.6
|
||||
websockets==11.0
|
||||
PyJWT==2.6.0
|
||||
asyncpg-stubs==0.27.0
|
||||
sqlalchemy==2.0.9
|
||||
aiohttp-sse-client2==0.3.0
|
||||
OpenCC==1.1.6
|
||||
event-emitter-asyncio==1.0.4
|
||||
aiohttp==3.8.4
|
||||
jieba==0.42.1
|
||||
pypinyin==0.37.0
|
||||
simplejson==3.17.0
|
||||
beautifulsoup4==4.11.2
|
||||
markdownify==0.11.6
|
||||
asyncpg==0.27.0
|
||||
aiofiles==23.1.0
|
||||
pgvector==0.1.6
|
||||
websockets==11.0
|
||||
PyJWT==2.6.0
|
||||
asyncpg-stubs==0.27.0
|
||||
sqlalchemy==2.0.9
|
||||
aiohttp-sse-client2==0.3.0
|
||||
OpenCC==1.1.6
|
||||
event-emitter-asyncio==1.0.4
|
||||
tiktoken-async==0.3.2
|
Loading…
Reference in New Issue