Skip to content

Commit

Permalink
Change Thread#addMetaData interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed May 1, 2024
1 parent 7e237d7 commit 6325103
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "experts",
"version": "0.2.0",
"version": "0.3.0",
"description": "An opinionated panel of experts implementation using OpenAI's Assistants API",
"type": "module",
"main": "./src/index.js",
Expand Down
10 changes: 5 additions & 5 deletions src/experts/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Thread {
return this.thread.metadata;
}

async addMetaData(key, value) {
this.metadata[key] = value;
async addMetaData(metadata) {
const newMetaData = { ...this.metadata, ...metadata };
await openai.beta.threads.update(this.id, {
metadata: this.metadata,
metadata: newMetaData,
});
debug("🧵 Update: " + JSON.stringify(this.thread));
}
Expand All @@ -41,8 +41,8 @@ class Thread {
const threadID = this.thread.metadata[threadKey];
if (!threadID) {
thread = await Thread.create();
await this.addMetaData(threadKey, thread.id);
await thread.addMetaData("tool", tool.agentName);
await this.addMetaData({ threadKey: thread.id });
await thread.addMetaData({ tool: tool.agentName });
} else {
thread = await Thread.find(threadID);
}
Expand Down
4 changes: 2 additions & 2 deletions test/experts/thread.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ test("creates a thread", async () => {

test("can add metadata for various tracking purposes", async () => {
let thread = await Thread.create();
await thread.addMetaData("somekey", "somevalue");
await thread.addMetaData({ somekey: "somevalue" });
thread = await Thread.find(thread.id);
expect(thread.metadata).toStrictEqual({ somekey: "somevalue" });
await thread.addMetaData("one", "two");
await thread.addMetaData({ one: "two" });
thread = await Thread.find(thread.id);
expect(thread.metadata).toStrictEqual({ somekey: "somevalue", one: "two" });
});

0 comments on commit 6325103

Please sign in to comment.