refractoring
This commit is contained in:
@@ -32,8 +32,6 @@ async def announcement_from_german_text(
|
||||
caster: multicast_control.Multicaster,
|
||||
text_de
|
||||
):
|
||||
TRANSLATOR_LLM = 'llama3.2:3b-instruct-q4_0'
|
||||
|
||||
base_lang = "deu"
|
||||
|
||||
for i, trans in enumerate(translator_config):
|
||||
@@ -43,7 +41,7 @@ async def announcement_from_german_text(
|
||||
text = llm_translator.translate_de_to_x(
|
||||
text_de,
|
||||
trans.big.language,
|
||||
model=TRANSLATOR_LLM,
|
||||
model=trans.translator_llm,
|
||||
client = trans.llm_client,
|
||||
host=trans.llm_host_url,
|
||||
token=trans.llm_host_token
|
||||
@@ -98,6 +96,7 @@ async def command_line_ui(global_conf, translator_conf, caster: multicast_contro
|
||||
await announcement_from_german_text(caster, command)
|
||||
await asyncio.wait([caster.streamer.task])
|
||||
|
||||
|
||||
async def main():
|
||||
log.basicConfig(
|
||||
level=log.INFO,
|
||||
|
||||
@@ -16,12 +16,10 @@ def synth_piper(text, model="en_US-lessac-medium"):
|
||||
os.chdir(PIPER_DIR)
|
||||
start = time.time()
|
||||
|
||||
# make sure piper has voices.json in working directory, otherwise it attempts to always load models
|
||||
ret = subprocess.run( # TODO: wrap this whole thing in a class and open a permanent pipe to the model
|
||||
[translator_config.PIPER_EXE_PATH,
|
||||
'--cuda',
|
||||
#'--data-dir', PIPER_DIR, # not working, change workdir instead
|
||||
#'--download-dir', PIPER_DIR,
|
||||
#'--model', f'{PIPER_DIR}/{model}.onnx',
|
||||
'--model', model,
|
||||
'--output-raw'
|
||||
],
|
||||
@@ -62,7 +60,6 @@ def synthesize(text, target_sample_rate, framework, model="en_US-lessac-medium",
|
||||
if return_lc3:
|
||||
audio_pcm = (audio * 2**15-1).astype(np.int16)
|
||||
lc3 = encode_lc3.encode(audio_pcm, target_sample_rate, 40) # TODO: octetts per frame should be parameter
|
||||
|
||||
return lc3
|
||||
else:
|
||||
return audio
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
from .credentials import *
|
||||
from .syspromts import *
|
||||
@@ -1,2 +0,0 @@
|
||||
BASE_URL='https://ollama.pstruebi.xyz'
|
||||
TOKEN = 'sk-17124cb84df14cc6ab2d9e17d0724d13'
|
||||
@@ -5,7 +5,6 @@ import logging as log
|
||||
import time
|
||||
import ollama
|
||||
|
||||
from multilang_translator.translator import credentials
|
||||
from multilang_translator.translator import syspromts
|
||||
|
||||
# ollama.create( # TODO: create models on startup
|
||||
@@ -13,13 +12,11 @@ from multilang_translator.translator import syspromts
|
||||
# from_='llama3.2', system="You are Mario from Super Mario Bros."
|
||||
# )
|
||||
|
||||
|
||||
async def chat():
|
||||
message = {'role': 'user', 'content': 'Why is the sky blue?'}
|
||||
response = await ollama.AsyncClient().chat(model='llama3.2', messages=[message])
|
||||
|
||||
|
||||
|
||||
def query_openwebui(model, system, query, url, token):
|
||||
url = f'{url}/api/chat/completions'
|
||||
headers = {
|
||||
@@ -38,12 +35,12 @@ def query_openwebui(model, system, query, url, token):
|
||||
return response.json()['choices'][0]['message']['content']
|
||||
|
||||
|
||||
def query_ollama(model, system, query, host=None):
|
||||
# client = ollama.Client(
|
||||
# host=host,
|
||||
# )
|
||||
def query_ollama(model, system, query, host='http://localhost:11434'):
|
||||
client = ollama.Client(
|
||||
host=host,
|
||||
)
|
||||
|
||||
response = ollama.chat(
|
||||
response = client.chat(
|
||||
model = model,
|
||||
messages = [
|
||||
{'role': 'system', 'content': system},
|
||||
@@ -52,6 +49,7 @@ def query_ollama(model, system, query, host=None):
|
||||
)
|
||||
return response.message.content
|
||||
|
||||
|
||||
def translate_de_to_x( # TODO: use async ollama client later - implenent a translate async function
|
||||
text:str,
|
||||
target_language: str,
|
||||
|
||||
@@ -10,7 +10,7 @@ class TranslatorBaseconfig(BaseModel):
|
||||
big: auracast_config.AuracastBigConfig = auracast_config.AuracastBigConfigDe()
|
||||
translator_llm: str = 'llama3.2:3b-instruct-q4_0'
|
||||
llm_client: str = 'ollama'
|
||||
llm_host_url: str | None = None
|
||||
llm_host_url: str | None = 'http://localhost:11434'
|
||||
llm_host_token: str | None = None
|
||||
tts_system: str = 'piper'
|
||||
tts_model: str ='de_DE-kerstin-low'
|
||||
|
||||
Reference in New Issue
Block a user