I’ve tried various permutations of this and found a work around solution but would prefer if there was something better. I want to define a function with a fixed value parameter:
I tried defining it as “const” and “value” or setting it as the parameter value directly but the only way that seemed to work was defining an enum with one value which isn’t my preference.
get_test_data({path:‘/api/test’}); in this case
Is there a way to force a method to return a fixed value?
Some background is I will have some routing in my backend and can look up the method that needs to be called from the route so I only need to define one method and will be changing a value in parameter object. the name of the method in my case is just meta information and not needed for the backend to return a value.
This probably relates to limitations in OpenAI’s “parser” that transforms the json we give it into these TypeScript-like definitions in the system message, which I’m not sure if they support the const expressions of json.
Your work-around is one way, but at the same time it feels meaningless to ask it to repeat a value you already know, you could set it to the default value of the path parameter of the actual function you’re calling in your code (get_test_data)?
Otherwise I think your workaround is probably the most reliable way you have. You can also specify the default to be “/api/test” to make it even more reliable if you actually need this pattern in the first place~
I appreciate the response. The way the server routes information is via a route/relative path so the best way at least in this implementation context is to send a fixed value in the parameter. The backend implementation looks like this:
This allows me to generalize the method call, otherwise I have to both stub all the routes with another method which defeats the purpose of what I’m trying to do. I’ll play around with it further.
I might change the routing to use the function name to achieve the same thing.
I think, if this is possible, it may be the superior choice. Makes the calls faster as well because you don’t need to wait for those extra N tokens in the response.
but perhaps you can still make some abstraction
perhaps using string parsing, maybe use prefixes in the function name for extra “meta-data”
Sometimes we make assumptions. When it comes down to it, the name of the function in the JSON Schema can be /some/route/etc. I don’t think there is any rule on it as it worked fine so it solves my original issue.
You can do this:
"name": "/api/get/weather",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"c",
"f"
]
}
},
"required": [
"location"
]
},
"description": "Determine weather in my location"
}
Using the “hallucination” of the AI to use the example written in the description, you can probably make it to supply a fixed value. I made a sample function and tested several times and it always gives the same value. I added default but I don’t think it is actually handled.
{
"name": "turn_on_light",
"description": "Turn on light bulb using iOT device",
"parameters": {
"type": "object",
"properties": {
"metadata": {
"type": "string",
"description": "Fixed value metadata, e.g. /api/route/123",
"default": "/api/route/123"
}
},
"required": [
"metadata"
]
}
}
If you have a function that can only output one thing, why not have it output no-thing?
It sounds like it would basically be a trigger.
instead of string, use a null type, and you’ll get back an “any->null” all the time.
Or give the function a name like “get_test_data_from_api_test” reflective of the path, or two properties where one is described one way and one described the other, and any invocation is considered to be your “enum”.