Skip to content

Commit

Permalink
Finders also update.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed May 21, 2024
1 parent ee0da80 commit d5109a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/experts/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class Assistant {
if (!this.id) return;
const assistant = await openai.beta.assistants.retrieve(this.id);
debug(`💁‍♂️ Found by id ${this.agentName} assistant ${this.id}`);
await this.#update(assistant);
return assistant;
}

Expand All @@ -286,6 +287,7 @@ class Assistant {
await openai.beta.assistants.list({ limit: "100" })
).data.find((a) => a.name === this.agentName);
debug(`💁‍♂️ Found by name ${this.agentName} assistant`);
await this.#update(assistant);
return assistant;
}

Expand All @@ -294,6 +296,23 @@ class Assistant {
return assistant;
}

async #update(assistant) {
if (!assistant) return;
await openai.beta.assistants.update(assistant.id, {
model: this.model,
name: this.agentName,
description: this.description,
instructions: this.instructions,
tools: this.tools,
tool_resources: this.tool_resources,
metadata: this._metadata,
temperature: this.temperature,
top_p: this.top_p,
response_format: this.response_format,
});
debug(`💁‍♂️ Updated ${this.agentName} assistant ${assistant.id}`);
}

async #create() {
const assistant = await openai.beta.assistants.create({
model: this.model,
Expand Down
5 changes: 5 additions & 0 deletions test/experts/assistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ beforeEach(() => {
delete process.env.TEST_ASSISTANT_ID;
});

test("find by id safely supports not found", async () => {
const assistant = await TestAssistant.create({ id: "asst_neverfound" });
expect(assistant.id).toMatch(/^asst_/);
});

test("send images with messages image_file", async () => {
const path = helperPath("test/fixtures/unremarkable-banner.png");
const file = await openai.files.create({
Expand Down

0 comments on commit d5109a3

Please sign in to comment.