Advertisement
-Miura-

Set Input Text with ChatGPT

Sep 26th, 2024
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.02 KB | None | 0 0
  1. alias: Set Input Text with ChatGPT
  2. sequence:
  3.   - data:
  4.       prompt: "{{ prompt }}"
  5.       language: "{{ language }}"
  6.       instruction: "{{ instruction }}"
  7.       model: "{{ model }}"
  8.     response_variable: chatGptResponse
  9.     action: script.get_chatgpt_response
  10.   - if:
  11.       - condition: template
  12.         value_template: "{{ chatGptResponse.success != true }}"
  13.     then:
  14.       - metadata: {}
  15.         data:
  16.           service:
  17.            - Home Assistant
  18.           message: Failed to get valid ChatGPT response!
  19.           title: Set ChatGPT Script
  20.         action: script.notify_self
  21.       - stop: Invalid ChatGPT response
  22.         error: true
  23.   - variables:
  24.       message: >
  25.        {% set msg = chatGptResponse.message %} {% if
  26.         remove_first_and_last_quotes == true %}
  27.           {% if msg[:1] == '"' %}
  28.             {% set msg = msg[1:] %}
  29.           {% endif %}
  30.           {% if msg[-1:] == '"' %}
  31.             {% set msg = msg[:-1] %}
  32.           {% endif %}
  33.         {% endif %} {{ msg }}
  34.   - data:
  35.       value: "{{ message }}"
  36.     target:
  37.       entity_id: "{{ input_text }}"
  38.     action: input_text.set_value
  39. fields:
  40.   prompt:
  41.     selector:
  42.       text: null
  43.     name: Prompt
  44.     required: true
  45.   language:
  46.     selector:
  47.       select:
  48.         options:
  49.          - nl
  50.     name: Language
  51.     required: true
  52.     default: nl
  53.   instruction:
  54.     selector:
  55.       text: {}
  56.     name: Instruction
  57.     required: false
  58.     default: >-
  59.       You are a voice assistant for Home Assistant. Answer in plain text. Keep
  60.       it simple and to the point.
  61.   model:
  62.     selector:
  63.       select:
  64.         options:
  65.          - chatgpt_3_5_turbo
  66.           - chatgpt_4o
  67.           - gpt_4o_mini
  68.     name: Model
  69.     required: true
  70.     default: chatgpt_3_5_turbo
  71.   input_text:
  72.     selector:
  73.       entity: {}
  74.     name: Input Text Entity
  75.     required: true
  76.   remove_first_and_last_quotes:
  77.     selector:
  78.       boolean: {}
  79.     name: Remove First And Last Quotes
  80.     default: false
  81.     required: true
  82. description: ""
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement