Spaces:
Paused
Paused
Commit
·
1e30c19
1
Parent(s):
2ef20aa
Update answerer.py
Browse files- answerer.py +5 -4
answerer.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
from typing import Dict, List
|
2 |
import os, gc
|
3 |
from rwkv.model import RWKV
|
4 |
from rwkv.utils import PIPELINE, PIPELINE_ARGS
|
|
|
5 |
|
6 |
class Answerer:
|
7 |
def __init__(self, model: str, vocab: str, strategy: str, ctx_limit: int):
|
@@ -12,7 +12,7 @@ class Answerer:
|
|
12 |
self.__pipeline = PIPELINE(self.__model, vocab)
|
13 |
self.ctx_limit = ctx_limit
|
14 |
|
15 |
-
def __call__(
|
16 |
self,
|
17 |
input: str,
|
18 |
max_output_length_tk: int,
|
@@ -34,8 +34,8 @@ class Answerer:
|
|
34 |
|
35 |
result: str = ""
|
36 |
|
37 |
-
occurrences:
|
38 |
-
tokens:
|
39 |
current_token = None
|
40 |
state = None
|
41 |
for _ in range(max_output_length_tk):
|
@@ -68,6 +68,7 @@ class Answerer:
|
|
68 |
tokens.clear()
|
69 |
result += tmp
|
70 |
yield result
|
|
|
71 |
|
72 |
tokens.clear()
|
73 |
occurrences.clear()
|
|
|
|
|
1 |
import os, gc
|
2 |
from rwkv.model import RWKV
|
3 |
from rwkv.utils import PIPELINE, PIPELINE_ARGS
|
4 |
+
from asyncio import sleep
|
5 |
|
6 |
class Answerer:
|
7 |
def __init__(self, model: str, vocab: str, strategy: str, ctx_limit: int):
|
|
|
12 |
self.__pipeline = PIPELINE(self.__model, vocab)
|
13 |
self.ctx_limit = ctx_limit
|
14 |
|
15 |
+
async def __call__(
|
16 |
self,
|
17 |
input: str,
|
18 |
max_output_length_tk: int,
|
|
|
34 |
|
35 |
result: str = ""
|
36 |
|
37 |
+
occurrences: dict[int, int] = {}
|
38 |
+
tokens: list[int] = []
|
39 |
current_token = None
|
40 |
state = None
|
41 |
for _ in range(max_output_length_tk):
|
|
|
68 |
tokens.clear()
|
69 |
result += tmp
|
70 |
yield result
|
71 |
+
await sleep(.2)
|
72 |
|
73 |
tokens.clear()
|
74 |
occurrences.clear()
|