Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
New handler for prompt from assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
hlomzik committed Dec 13, 2023
1 parent 4b3dc54 commit f604500
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/sdk/api-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,13 @@ export const APIConfig = {
path: "/../comments/:id",
method: "delete",
},

mlBackends: "/../ml",

// Test for LLM assistant
mlInteractive: {
path: "/../ml/:pk/interactive-annotating",
method: "post",
},
},
};
38 changes: 38 additions & 0 deletions src/sdk/lsf-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class LSFWrapper {
onLabelStudioLoad: this.onLabelStudioLoad,
onTaskLoad: this.onTaskLoad,
onPresignUrlForProject: this.onPresignUrlForProject,
onAssistantPrompt: this.onAssistantPrompt,
onStorageInitialized: this.onStorageInitialized,
onSubmitAnnotation: this.onSubmitAnnotation,
onUpdateAnnotation: this.onUpdateAnnotation,
Expand All @@ -209,6 +210,7 @@ export class LSFWrapper {
this.lsfInstance = new LSF(this.root, settings);

this.lsfInstance.on('presignUrlForProject', this.onPresignUrlForProject);
this.lsfInstance.on('assistantPrompt', this.onAssistantPrompt);

const names = Array.from(this.datamanager.callbacks.keys())
.filter(k => k.startsWith('lsf:'));
Expand Down Expand Up @@ -563,6 +565,42 @@ export class LSFWrapper {
return api.createUrl(api.endpoints.presignUrlForProject, { projectId, fileuri }).url;
};

onAssistantPrompt = async (ls, prompt) => {
// const fields = [];
const annotation = ls.annotationStore.selected;
const user = this.lsf.user;
// default value just in case
const object = Object.keys(this.project.data_types)[0] ?? "text";
const result = [
{
from_name: "prompt",
to_name: object,
type: "textarea",
value: { text: prompt },
},
];

const mlBackends = await this.datamanager.apiCall("mlBackends", {}, { project: this.project.id });

const interactive = (mlBackends ?? []).find(({ is_interactive }) => is_interactive);

const results = await this.datamanager.apiCall(
"mlInteractive",
{ pk: interactive.id },
{ body: {
task: this.task.id,
context: {
annotation_id: annotation.pk,
draft_id: annotation.draftId,
user_id: user.id,
result,
},
} },
);

console.log(results);
};

onStorageInitialized = async (ls) => {
this.datamanager.invoke("onStorageInitialized", ls);

Expand Down

0 comments on commit f604500

Please sign in to comment.