theodo-group / LLPhant

LLPhant - A comprehensive PHP Generative AI Framework using OpenAI GPT 4. Inspired by Langchain
MIT License
806 stars 80 forks source link

Ollama lastFunctionCalled doesn't have the arguments used to call the function #208

Closed fballiano closed 1 month ago

fballiano commented 1 month ago

Hi everybody, so when using ollama for function calling, I've got $ollamachat->lastFunctionCalled and $ollamachat->lastToolsOutput to see what went on.

But.. lastFunctionCalled is something like:

"function": {
    "name": "testFunction123",
    "instance": {},
    "description": "description of the function",
    "parameters": [
        {
            "name": "paramID",
            "type": "string",
            "description": "param description",
            "enum": [],
            "format": null,
            "itemsOrProperties": null
        }
    ],
    "requiredParameters": [
        {
            "name": "paramID",
            "type": "string",
            "description": "param description",
            "enum": [],
            "format": null,
            "itemsOrProperties": null
        }
    ]
}

problem is that I don't have the values of the parameters used to call the function, in this example maybe the call was testFunction123('sampleParameter') but we've no way of knowing.

I wanted to create a PR about that but I'm wondering, should we modify the LLPhant\Chat\FunctionInfo\Parameter class adding a $value property as last parameter?

namespace LLPhant\Chat\FunctionInfo;

class Parameter
{
    /**
     * @param  mixed[]  $enum
     * @param  mixed[]|null  $itemsOrProperties
     */
    public function __construct(public string $name, public string $type, public string $description, public array $enum = [], public ?string $format = null, public array|string|null $itemsOrProperties = null)
    {
    }
}

it doesn't seem the right place for that since FunctionInfo seems more oriented to describe the definition of the funcion and nothing else.

other ideas?

f-lombardo commented 1 month ago

@fballiano I agree with you that FunctionInfo is not the right place for infos on the actual parameters. Maybe we need to look at the problem from another angle. What are you trying to achieve? Can you tell more about your use case?

fballiano commented 1 month ago

well, it's just that we have

but we don't have the values of the arguments used to call the function, which, for debugging reasons, are kinda necessary.

now, as a workaround, I've modified all my functions to gather the arguments, but I think the framework could also provide this data.

fballiano commented 1 month ago

I also found another problem, we now have only a "lastFunctionCalled", "lastToolsOutput" but, native ollama function calling is able to call multiple tools in a single call (I wasn't even expecting it but it does) so "lastFunctionCalled" and "lastToolsOutput" are not enough and should be replaced with arrays, something like "functionsCalled", "toolsOutput".

But at that point I'd rework everything in

functionsCalled: [
  0 => [
    'definition' =>
    'arguments' =>
    'output' =>
  ]
]
MaximeThoonsen commented 1 month ago

hey @fballiano, I agree with you. When I started only one function could be called. I also think it can be usefull to have the args.