Skip to content

Commit

Permalink
Merge pull request #319 from ainft-team/fix/jiyoung/assistant-resp-fo…
Browse files Browse the repository at this point in the history
…rmat

[fix] unify assistant response format
  • Loading branch information
jiyoung-an authored Sep 26, 2024
2 parents 2d978cb + d88d734 commit 24fa858
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/ai/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export class Assistants extends FactoryBase {
options: AssistantCreateOptions = {}
): Promise<AssistantTransactionResult> {
const address = await this.ain.signer.getAddress();
const appId = AinftObject.getAppId(objectId);
const token = await getToken(this.ain, appId, tokenId);

// TODO(jiyoung): limit character count for 'instruction' and 'description'.
await validateObject(this.ain, objectId);
Expand Down Expand Up @@ -105,12 +107,28 @@ export class Assistants extends FactoryBase {
data: body,
});

const assistant = {
id: data.id,
objectId: objectId,
tokenId: tokenId,
owner: token.owner,
model: data.model,
name: data.name,
instructions: data.instructions,
description: data.description,
metadata: data.metadata,
created_at: data.created_at,
metric: {
numThreads: 0,
},
};

if (role === Role.OWNER) {
const txBody = this.buildTxBodyForCreateAssistant(address, objectId, tokenId, data);
const result = await sendTx(txBody, this.ain);
return { ...result, assistant: data };
return { ...result, assistant };
} else {
return { assistant: data };
return { assistant };
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const address = '0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0';
export const objectId = '0xD42cfE651c3ED79F5FE68A7D257d227f1b5282A9';
export const appId = 'ainft721_0xd42cfe651c3ed79f5fe68a7d257d227f1b5282a9';
export const tokenId = '7';
export const serviceName = 'openai_backend';
export const serviceName = 'aina_backend';

export const assistantId = 'asst_4ZfyVxKP7IG89DzJjSyQTEmv';
export const threadId = 'thread_8nrYM2UCxnhGTMotlolno9aL';
Expand Down

0 comments on commit 24fa858

Please sign in to comment.