home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.25k stars 28.47k forks source link

LLM Tools support for OpenAI integration #117645

Closed Shulyaka closed 1 week ago

Shulyaka commented 2 weeks ago

Breaking change

Proposed change

Implement LLM Tools feature (https://github.com/home-assistant/core/pull/115464) for openai_conversation.

Type of change

Additional information

Checklist

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

To help with the load of incoming pull requests:

home-assistant[bot] commented 2 weeks ago

Hey there @balloob, mind taking a look at this pull request as it has been labeled with an integration (openai_conversation) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `openai_conversation` can trigger bot actions by commenting: - `@home-assistant close` Closes the pull request. - `@home-assistant rename Awesome new title` Renames the pull request. - `@home-assistant reopen` Reopen the pull request. - `@home-assistant unassign openai_conversation` Removes the current integration label and assignees on the pull request, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
synesthesiam commented 1 week ago

@Shulyaka There seems to be an issue when converting the parameters with voluptuous_openapi if the intent does not have any parameters. OpenAI seems to expected properties to be present no matter what in the tool spec parameters (at least for GPT 3.5 turbo).

I added this to _format_tool to get it to work:

    if "properties" not in tool_spec["parameters"]:
        tool_spec["parameters"]["properties"] = {}

but I think this may be better suited for voluptuous_openapi. What do you think?

Shulyaka commented 1 week ago

@Shulyaka There seems to be an issue when converting the parameters with voluptuous_openapi if the intent does not have any parameters. OpenAI seems to expected properties to be present no matter what in the tool spec parameters (at least for GPT 3.5 turbo).

I added this to _format_tool to get it to work:

    if "properties" not in tool_spec["parameters"]:
        tool_spec["parameters"]["properties"] = {}

but I think this may be better suited for voluptuous_openapi. What do you think?

Yes, you are right, I will make the fix.

Shulyaka commented 1 week ago

https://github.com/home-assistant-libs/voluptuous-openapi/pull/13