alexrudall / ruby-openai

OpenAI API + Ruby! 🤖❤️ NEW: Assistant Vector Stores
MIT License
2.61k stars 302 forks source link

How can I add a custom tool (a function) to an assistant? #442

Closed leandrosardi closed 3 months ago

leandrosardi commented 3 months ago

How can I add a custom tool (a function) to an assistant?

I am trying this code, but it is not working. I can't find good documentation.

            response = @@openai_client.assistants.create(
                parameters: {
                    model: @@openai_model,         # Retrieve via client.models.list. Assistants need 'gpt-3.5-turbo-1106' or later.
                    name: "OpenAI-Ruby test assistant", 
                    description: nil,
                    instructions: OPENAI_INSTRUCTIONS,
                    tools: [
                        {"type": "code_interpreter"}, 
                        {"type": "retrieval"}, 
                        {
                            type: "function",
                            name: "run_command_in_local_computer",
                            description: "Run a bash command in the local computer",
                            parameters: {
                                type: :object,
                                properties: {
                                    command: {
                                        type: :string,
                                        description: "A bash command.",
                                    },
                                },
                                required: ["command"],
                            },
                        }
                    ],
                    metadata: { my_internal_version_id: '1.0.0' },
                }
            )
            @@openai_assistant_id = response["id"]
leandrosardi commented 3 months ago

I already found the solution for this too. Closing ticket.

alexrudall commented 3 months ago

Thanks @leandrosardi - the docs are now updated here

leandrosardi commented 3 months ago

Thank you @alexrudall.

This ticket has some urgency for us too: https://github.com/alexrudall/ruby-openai/issues/443

I will appreciate your support.