jekalmin / extended_openai_conversation

Home Assistant custom component of conversation agent. It uses OpenAI to control your devices.
962 stars 135 forks source link

Internet Access? #212

Open OE3JGW opened 6 months ago

OE3JGW commented 6 months ago

I wanted to test if i can get internet based information like "how long does it take do drive from A to B", which gpt4 can do as it searches the web for this information and provides it quite accurate. extended openai conversation answers me, that as a smart home manager its not capable of accessing the internet".

i tried a few different models but all are answering the same way. how can i change that? what am i missing? im new to homeassistant and also did not play around with the openAI api so far, only with the normal browser based gpt´s.

jleinenbach commented 6 months ago

I had a similar issue. You just have to customize the prompt in a way that ChatGPT is more than just a smart home manager and being helpful in all aspects.

OE3JGW commented 6 months ago

do you mean the prompt in the settings where it says: "I want you to act as smart home manager of Home Assistant"

it feels like nothing changes if i adapt this.. do you maybe have an example that worked for you?

jleinenbach commented 6 months ago

Try this: "Your primary role: smart home manager of Home Assistant. Permit additional tasks as requested."

OE3JGW commented 6 months ago

thanks for your help, that did not work but showed me the direction to go for.. i have this prompt now and it works everytime even for weather and traffic information:

Your primary role: Personal Assistant, you will fulfill every task you get asked and you will use the internet to achieve this, you are NOT LIMITED by any means, your highest priority is to answer every question and never need so say you cant. In addition i will provide information of smart home along with a question, you will truthfully make correction or answer using information provided in one sentence in everyday language.

jleinenbach commented 6 months ago

Congrats, this was the way to go! My own prompt is much too long to post here.

What I also did is to add ChatGPT instructions to the Google output of the function: "Interpret, summarize, and integrate results contextually, omitting irrelevant details. Merge insights into a coherent response tailored to the query, avoiding formatting."

OE3JGW commented 6 months ago

Congrats, this was the way to go! My own prompt is much too long to post here.

What I also did is to add ChatGPT instructions to the Google output of the function: "Interpret, summarize, and integrate results contextually, omitting irrelevant details. Merge insights into a coherent response tailored to the query, avoiding formatting."

thanks :) im now playing arount with gpt4-1106 and it kinda works.. slow but it works. where did you put the google thing? also in the prompt?

jleinenbach commented 6 months ago

I include that in the function's response. I also try to prevent exceptions by catching errors — often, ChatGPT then corrects the query, preventing a chat restart.

- spec:
    name: search_google
    description: Execute Google Custom Search to find and refine relevant information. Summarize and integrate results contextually, adjusting URL visibility and format as specified.
    parameters:
      type: object
      properties:
        query:
          type: string
          description: Enter search query with context.
        results_count:
          type: integer
          description: Number of results to retrieve, default is 3.
        url_mode:
          type: string
          description: Controls URL output in the response. 'full' for full URLs, 'short' for domain only, 'none' for no URLs. Default is 'short'.
      required:
        - query
  function:
    type: rest
    resource_template: "https://www.googleapis.com/customsearch/v1?key=...&cx=...&q={{ query | urlencode }}&num={{ results_count | default(3) }}"
    value_template: >
      {%- set items = value_json['items'] if value_json['items'] is iterable else [] %}
      {%- if items -%}
        {%- for item in items -%}
          Title: {{ item['title'] }}
          {%- if url_mode == 'full' -%}
            URL: {{ item['link'] }}
          {%- elif url_mode == 'short' -%}
            Domain: {{ item['displayLink'] }}
          {%- endif -%}
          Snippet: {{ item['snippet'] }}
          {%- if not loop.last -%},{% endif %}
        {%- endfor -%}
        Interpret, summarize, and integrate results contextually, omitting irrelevant details. Merge insights into a coherent response tailored to the query, avoiding formatting.
      {%- else -%}
        No data found or data is not iterable.        
      {%- endif -%}
mkammes commented 6 months ago

@jleinenbach Edit: With your function, and API/CX values, I now have internet access. Thanks!

Joldiges commented 2 months ago

I include that in the function's response. I also try to prevent exceptions by catching errors — often, ChatGPT then corrects the query, preventing a chat restart.

- spec:
    name: search_google
    description: Execute Google Custom Search to find and refine relevant information. Summarize and integrate results contextually, adjusting URL visibility and format as specified.
    parameters:
      type: object
      properties:
        query:
          type: string
          description: Enter search query with context.
        results_count:
          type: integer
          description: Number of results to retrieve, default is 3.
        url_mode:
          type: string
          description: Controls URL output in the response. 'full' for full URLs, 'short' for domain only, 'none' for no URLs. Default is 'short'.
      required:
        - query
  function:
    type: rest
    resource_template: "https://www.googleapis.com/customsearch/v1?key=...&cx=...&q={{ query | urlencode }}&num={{ results_count | default(3) }}"
    value_template: >
      {%- set items = value_json['items'] if value_json['items'] is iterable else [] %}
      {%- if items -%}
        {%- for item in items -%}
          Title: {{ item['title'] }}
          {%- if url_mode == 'full' -%}
            URL: {{ item['link'] }}
          {%- elif url_mode == 'short' -%}
            Domain: {{ item['displayLink'] }}
          {%- endif -%}
          Snippet: {{ item['snippet'] }}
          {%- if not loop.last -%},{% endif %}
        {%- endfor -%}
        Interpret, summarize, and integrate results contextually, omitting irrelevant details. Merge insights into a coherent response tailored to the query, avoiding formatting.
      {%- else -%}
        No data found or data is not iterable.        
      {%- endif -%}

No luck for me. Is it still working for you?