Files

50 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-06-28 00:59:51 +02:00
import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
2024-06-27 17:27:40 +10:00
import RestModel from "discourse/models/rest";
const CREATE_ATTRIBUTES = [
"id",
"name",
2025-02-07 14:34:47 +11:00
"tool_name",
2024-06-27 17:27:40 +10:00
"description",
"parameters",
"script",
"summary",
2024-09-30 16:27:50 +09:00
"rag_uploads",
"rag_chunk_tokens",
"rag_chunk_overlap_tokens",
"rag_llm_model_id",
2024-06-27 17:27:40 +10:00
"enabled",
];
export default class AiTool extends RestModel {
createProperties() {
return this.getProperties(CREATE_ATTRIBUTES);
}
updateProperties() {
return this.getProperties(CREATE_ATTRIBUTES);
}
2024-08-29 16:05:38 +10:00
trackParameters(parameters) {
return new TrackedArray(
parameters?.map((p) => {
2024-06-28 00:59:51 +02:00
const parameter = new TrackedObject(p);
2024-08-29 16:05:38 +10:00
if (parameter.enum && parameter.enum.length) {
parameter.enum = new TrackedArray(parameter.enum);
2024-08-29 16:05:38 +10:00
} else {
parameter.enum = null;
2024-06-28 00:59:51 +02:00
}
return parameter;
})
);
2024-08-29 16:05:38 +10:00
}
2024-06-28 00:59:51 +02:00
2024-08-29 16:05:38 +10:00
workingCopy() {
const attrs = this.getProperties(CREATE_ATTRIBUTES);
attrs.parameters = this.trackParameters(attrs.parameters);
2024-06-28 00:59:51 +02:00
return this.store.createRecord("ai-tool", attrs);
2024-06-27 17:27:40 +10:00
}
}