llm-edge / hal-9100

Edge full-stack LLM platform. Written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
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:

  1. create assistant with instructions etc
  2. update assistant with just metadata for example and check if the properties are gone or not