Closed pbuergi closed 2 months ago
Not sure if your error has anything to do with it, but this line comes from Google and it's actually wrong:
resource_template: "https://www.googleapis.com/customsearch/v1?key=[GOOGLE_API_KEY]&cx=[GOOGLE_PROGRAMMING_SEARCH_ENGINE]:omuauf_lfve&q={{ query }}&num=3"
You will need to replace it with this:
resource_template: "https://www.googleapis.com/customsearch/v1?key=[GOOGLE_API_KEY]&cx=[GOOGLE_PROGRAMMING_SEARCH_ENGINE]&q={{ query }}&num=3"
Just pitching in that I also can't get this to work. I've spent the last hour trying to no avail. Pretty much the same error. TIA.
title,link
{% for item in value_json["items"] %}
"{{ item.title | replace(',', ' ') }}","{{ item.link }}"
{% endfor %}
{% else %} No results found, {% endif %}
Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/assist_pipeline/pipeline.py", line 993, in recognize_intent conversation_result = await conversation.async_converse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/conversation/init.py", line 544, in async_converse result = await agent.async_process( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 196, in async_process query_response = await self.query(user_input, messages, exposed_entities, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 380, in query return await self.execute_function_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 406, in execute_function_call return await self.execute_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 432, in execute_function result = await function_executor.execute( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/helpers.py", line 496, in execute value = value_template.async_render_with_possible_json_value( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 766, in async_render_with_possible_json_value render_result = _render_with_context( ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2545, in _render_with_context return template.render(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "", line 1, in top-level template code TypeError: 'builtin_function_or_method' object is not iterable
It is important that you have a working API key and a CX code or it will fail. Get it here: https://developers.google.com/custom-search/v1/overview
Then you should test the URL in your browser first, eg.: https://www.googleapis.com/customsearch/v1?key=YOUR-LONG-API-KEY&cx=YOUR-CX-CODE&q=birds&num=3
This is my working customized code, maybe it helps:
- 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 'none'.
required:
- query
function:
type: rest
resource_template: "https://www.googleapis.com/customsearch/v1?key=[API-KEY]&cx=[CX-CODE]&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 -%}
This issue should be related: https://github.com/jekalmin/extended_openai_conversation/issues/173
Yes i found it out by myself
Same as here: https://github.com/jekalmin/extended_openai_conversation/issues/173#issuecomment-2028499357
The Google Example should be updated.
My edited code to get the data:
value_template: >-
{{value_json['items'] | tojson}}
Thanks jleinerbach, this worked great. Truly appreciate it.
when i use google search i get this error:
Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/assist_pipeline/pipeline.py", line 993, in recognize_intent conversation_result = await conversation.async_converse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/conversation/init.py", line 544, in async_converse result = await agent.async_process( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 196, in async_process query_response = await self.query(user_input, messages, exposed_entities, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 380, in query return await self.execute_function_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 406, in execute_function_call return await self.execute_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/init.py", line 432, in execute_function result = await function_executor.execute( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/helpers.py", line 496, in execute value = value_template.async_render_with_possible_json_value( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 766, in async_render_with_possible_json_value render_result = _render_with_context( ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2545, in _render_with_context return template.render(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "", line 1, in top-level template code TypeError: 'builtin_function_or_method' object is not iterable