API: Move OpenAI-compatible API from extensions/openai to modules/api

This commit is contained in:
oobabooga 2026-03-20 14:46:00 -03:00
parent 2e4232e02b
commit bf6fbc019d
23 changed files with 51 additions and 65 deletions

26
modules/api/tokens.py Normal file
View file

@ -0,0 +1,26 @@
from modules.text_generation import decode, encode
def token_count(prompt):
tokens = encode(prompt)[0]
return {
'length': len(tokens)
}
def token_encode(input):
tokens = encode(input)[0]
if tokens.__class__.__name__ in ['Tensor', 'ndarray']:
tokens = tokens.tolist()
return {
'tokens': tokens,
'length': len(tokens),
}
def token_decode(tokens):
output = decode(tokens)
return {
'text': output
}