Sam 5cbc9190eb
FEATURE: RAG search within tools (#802)
This allows custom tools access to uploads and sophisticated searches using embedding.

It introduces:

 - A shared front end for listing and uploading files (shared with personas)
 -  Backend implementation of index.search function within a custom tool.

Custom tools now may search through uploaded files

function invoke(params) {
   return index.search(params.query)
}

This means that RAG implementers now may preload tools with knowledge and have high fidelity over
the search.

The search function support

    specifying max results
    specifying a subset of files to search (from uploads)

Also

 - Improved documentation for tools (when creating a tool a preamble explains all the functionality)
  - uploads were a bit finicky, fixed an edge case where the UI would not show them as updated
2024-09-30 17:27:50 +10:00

48 lines
1.1 KiB
JavaScript

import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
import RestModel from "discourse/models/rest";
const CREATE_ATTRIBUTES = [
"id",
"name",
"description",
"parameters",
"script",
"summary",
"rag_uploads",
"rag_chunk_tokens",
"rag_chunk_overlap_tokens",
"enabled",
];
export default class AiTool extends RestModel {
createProperties() {
return this.getProperties(CREATE_ATTRIBUTES);
}
updateProperties() {
return this.getProperties(CREATE_ATTRIBUTES);
}
trackParameters(parameters) {
return new TrackedArray(
parameters?.map((p) => {
const parameter = new TrackedObject(p);
if (parameter.enum && parameter.enum.length) {
parameter.enum = new TrackedArray(parameter.enum);
} else {
parameter.enum = null;
}
return parameter;
})
);
}
workingCopy() {
const attrs = this.getProperties(CREATE_ATTRIBUTES);
attrs.parameters = this.trackParameters(attrs.parameters);
return this.store.createRecord("ai-tool", attrs);
}
}