#Using an automation to strip out llm thinking

1 messages · Page 1 of 1 (latest)

trail pawn
#

Hi,

I'm using an LLM with a thinking stage. The thinking output starts with <think> and ends with </think>. Then the response is straight after.

Is there an easy way to strip out the thinking before text to speech?

#

I'm hoping this is as simple as a regex replace in the right spot to delete the relevant thinking text before it is passed to piper

ivory tundra
#

Yeah but you will need to call it manually with conversation.process in custom intent script in order to be able to modify response before sending it to TTS.

trail pawn
#

Easy enough. Thanks for the response. Can you provide an example yaml? Or link me to the relevant docs?

ivory tundra
#

Ping me tomorrow, I'll scrap something.

ivory tundra
#

Ok, so here's what you can do (although it's a bit ugly on second look)

ivory tundra
#
# sentence part:

intents:
  AskThinkingModel:
    data:
      - sentences:
        - "think of {request}"
        
lists:
  request:
    wildcard: true


# then the script itself:

AskThinkingModel:
  action:
    - data:
        agent_id: conversation.#your_conversation_agent#
        text: '{{ request }}'
      response_variable: processed
      action: conversation.process
    - variables:
        result:
          speech: '{{ processed.response.speech.plain.speech | regex_replace('<think>.*?</think>', '', ignorecase=True) | trim }}'
    - stop: ""
      response_variable: result
  speech:
    text: "{{ action_response['speech'] }}"