oobabooga / text-generation-webui

A Gradio web UI for Large Language Models.
GNU Affero General Public License v3.0
40.37k stars 5.3k forks source link

Silero_tts extension conflict with Api calls #4944

Closed mercuryyy closed 9 months ago

mercuryyy commented 10 months ago

Describe the bug

When Using Silero_tts there is a conflict when calling the built in api http://127.0.0.1:5000/v1/chat/completions" ...

From what i can make of it, the audio file is inserted into the prompt but it does not get generated in time and cause an error.

Iv been playing with setting and trying to recode script.py for the extension but i can not figure it out.

Is there an existing issue for this?

Reproduction

Enable Silero_tts

And just make a regular api request:

`

import requests

url = "http://127.0.0.1:5000/v1/chat/completions"

headers = { "Content-Type": "application/json" }

history = []

while True: user_message = input("> ") history.append({"role": "user", "content": user_message}) data = { "mode": "chat", "character": "Llama8", "messages": history, "stream": False }

response = requests.post(url, headers=headers, json=data, verify=False)

# Debugging: Print the response text and status code
print("Response Text:", response.text)
print("Status Code:", response.status_code)

try:
    assistant_message = response.json()['choices'][0]['message']['content']
    history.append({"role": "assistant", "content": assistant_message})
    print(assistant_message)
except json.decoder.JSONDecodeError:
    print("Failed to decode JSON from response.")

`

Screenshot

No response

Logs

File "/home/izzy/text-generation-webui/extensions/openai/completions.py", line 283, in chat_completions_common
    for a in generator:
  File "/home/izzy/text-generation-webui/modules/chat.py", line 323, in generate_chat_reply
    for history in chatbot_wrapper(text, state, regenerate=regenerate, _continue=_continue, loading_message=loading_message, for_ui=for_ui):
  File "/home/izzy/text-generation-webui/modules/chat.py", line 291, in chatbot_wrapper
    output['visible'][-1][1] = apply_extensions('output', output['visible'][-1][1], state, is_chat=True)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/izzy/text-generation-webui/modules/extensions.py", line 224, in apply_extensions
    return EXTENSION_MAP[typ](*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/izzy/text-generation-webui/modules/extensions.py", line 82, in _apply_string_extensions
    text = func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/izzy/text-generation-webui/extensions/silero_tts/script.py", line 132, in output_modifier
    output_file = Path(f'extensions/silero_tts/outputs/{state["character_menu"]}_{int(time.time())}.wav')
                                                        ~~~~~^^^^^^^^^^^^^^^^^^
KeyError: 'character_menu'

System Info

Local, ubuntu, 4090 Nv
mercuryyy commented 10 months ago

I was able to bypass the bug but now i am not able to figure out how i can include the audio file in the api response.

   print("State keys:", state.keys())
    print("Is 'character_menu' in state:", "character_menu" in state)
    try:
        if "character_menu" in state:
            character_menu = state["character_menu"]
        else:
            character_menu = "default_value"
    except KeyError as e:
        print("KeyError encountered:", e)        
    output_file = Path(f'extensions/silero_tts/outputs/{character_menu}_{int(time.time())}.wav')
    # output_file = Path(f'extensions/silero_tts/outputs/{state["character_menu"]}_{int(time.time())}.wav')

I was able to bypass the error but i want it to send the $output_file url in the api response, should probably be the default behavior

github-actions[bot] commented 9 months ago

This issue has been closed due to inactivity for 6 weeks. If you believe it is still relevant, please leave a comment below. You can tag a developer in your comment.