Update assumes "set to None"
CakeCrusher opened this issue · comments
@louis030195
Whenever you update assistant all fields not passed are set to None
or empty arrays (defaults).
assistant = openai.beta.assistants.create(
instructions="You are a weather bot. Use the provided functions to answer questions.",
model="gpt-3.5-turbo-1106",
name="Weather Bot",
metadata={
"asd": "1",
}
)
new_metadata = {**assistant.metadata, "sad": "123"}
updated_assistant = openai.beta.assistants.update(assistant_id=assistant.id,model="gpt-3.5-turbo-1106", metadata=new_metadata)
openai.beta.assistants.retrieve(assistant_id=assistant.id)
notice how instructions is now set to None
Assistant(id='a1f35333-95e6-4632-91cb-8a777e4f2920', created_at=1704597945, description=None, file_ids=[], instructions=None, metadata={'sad': '123', 'asd': '1'}, model='gpt-3.5-turbo-1106', name=None, object='', tools=[])
I tried to resolve it but I'm a newbie on Rust, here is what I tried:
https://chat.openai.com/share/64fe31d2-6078-4759-9982-be3924e50bba
thanks for noticing this!
indeed the problem is that if props are none it will none them in the db, here's how i prompted a solution:
![Screenshot 2024-01-07 at 09 01 03](https://private-user-images.githubusercontent.com/25003283/294773085-a5395c43-b4af-4740-9180-6e6dabba2230.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzNzkxMzksIm5iZiI6MTcyMTM3ODgzOSwicGF0aCI6Ii8yNTAwMzI4My8yOTQ3NzMwODUtYTUzOTVjNDMtYjRhZi00NzQwLTkxODAtNmU2ZGFiYmEyMjMwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE5VDA4NDcxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI3YjAyNTBkNWM0ZWNiMjVmMWNlZjZmZmRkYTNkODI2YzViYTViNzRlOTQzMjI2NGJlNmY2ZjFkZTUxYmUwNDgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.B7SjemeKrOhjEAr7a-pEHYSZoPJbzUWCU_d4qPZTspQ)
let row = sqlx::query!(
r#"
UPDATE assistants
SET instructions = COALESCE($2, instructions),
name = COALESCE($3, name),
tools = COALESCE($4, tools),
model = COALESCE($5, model),
file_ids = COALESCE($7, file_ids)
WHERE id::text = $1 AND user_id::text = $6
RETURNING *
"#,
assistant_id,
assistant.inner.instructions,
assistant.inner.name,
&tools_json,
assistant.inner.model,
assistant.user_id,
&assistant.inner.file_ids,
)
should work i guess?
would love a PR!
with a unit test that do:
- create assistant with instructions etc
- update assistant with just metadata for example and check if the properties are gone or not