-
Couldn't load subscription status.
- Fork 113
Description
Wanted to start by saying thanks for all of the great work to build and maintain this package!
TL;DR:
I believe I've found a bug where retrieving any Assistant that has a function defined via the OpenAI Playground results in an error.
The impact is that this bug hinders development of an assistant using OpenAI Playground, which is super useful in applications where programmatic assistant setup is cumbersome (e.g. one assistant that serves every instance of your application and you only need to define once). Note: programmatic assistant creation assistant via .createAssistant(parameters: AssistantParameters) by supplying the function as an AssistantObject.Tool works fine.
Full context:
Based on my experimentation retrieving any Assistant that has a function defined via the OpenAI Playground results in the following error:
Key 'additionalProperties' not found: No value associated with key CodingKeys(stringValue: "additionalProperties", intValue: nil) ("additionalProperties").codingPath: [CodingKeys(stringValue: "tools", intValue: nil), _CodingKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "function", intValue: nil), CodingKeys(stringValue: "parameters", intValue: nil), CodingKeys(stringValue: "properties", intValue: nil), _CodingKey(stringValue: "symbol", intValue: nil)]
Note that this is true regardless of whether or not the function definition explicitly includes an additionalProperties field as a result of requiring a strict schema adherence via strict: true, although hopefully doing so would also not result in an error. Following are minimum steps to reproduce:
- Create an assistant
- Add a function to the assistant in the OpenAI Playground. From my experiments any function will do but you can use this modified version of an example function to test. Note how
strictis set to false and there is noadditionalPropertiesfield defined:
{
"name": "get_stock_price",
"description": "Get the current stock price",
"strict": false,
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The stock symbol"
}
},
"required": [
"symbol"
]
}
}
- Then attempt to retrieve the assistant:
let service: OpenAIService = OpenAIServiceFactory.service(apiKey: "your_api_key", debugEnabled: true) //enabled debug for logging purposes
let assistant = try await service.retrieveAssistant(id: "your_assistant_id") // provide the ID of an assistant that has a function created via the OpenAI Playground
And the respective log output:
DEBUG JSON FETCH API = Optional(["response_format": auto, "model": gpt-4o, "metadata": {
}, "tool_resources": {
}, "id": your_assistant_id, "name": Test Assistant, "description": , "instructions": You are a helpful assistant., "top_p": 1, "tools": <__NSSingleObjectArrayI 0x600000009d20>(
{
function = {
description = "Get the current stock price";
name = "get_stock_price";
parameters = {
properties = {
symbol = {
description = "The stock symbol";
type = string;
};
};
required = (
symbol
);
type = object;
};
strict = 0;
};
type = function;
}
)
, "object": assistant, "created_at": 1725322306, "temperature": 1])
Key 'additionalProperties' not found: No value associated with key CodingKeys(stringValue: "additionalProperties", intValue: nil) ("additionalProperties").codingPath: [CodingKeys(stringValue: "tools", intValue: nil), _CodingKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "function", intValue: nil), CodingKeys(stringValue: "parameters", intValue: nil), CodingKeys(stringValue: "properties", intValue: nil), _CodingKey(stringValue: "symbol", intValue: nil)]
Happy to provide any other context if helpful - hopefully I'm not just doing something wrong!