diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-12-19 11:45:00 -0500 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-12-19 11:45:00 -0500 |
commit | f915013d2ccfaeb7f04bf8bfea57e6d7d1f66b81 (patch) | |
tree | 69cde0426434a687a096ebe987145628afd145b0 /src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx | |
parent | 9b4c554cca11f5c3105085b54646e684dd235f1d (diff) |
image generation works better
Diffstat (limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx')
-rw-r--r-- | src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx index e5a90ab4a..d2931106a 100644 --- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx +++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx @@ -40,6 +40,11 @@ import { DiagramBox } from '../../DiagramBox'; import { ImageField } from '../../../../../fields/URLField'; import { DashUploadUtils } from '../../../../../server/DashUploadUtils'; import { DocCreatorMenu, Field, FieldUtils } from '../../DataVizBox/DocCreatorMenu'; +import { ImageUtils } from '../../../../util/Import & Export/ImageUtils'; +import { ScriptManager } from '../../../../util/ScriptManager'; +import { CompileError, CompileScript } from '../../../../util/Scripting'; +import { ScriptField } from '../../../../../fields/ScriptField'; +import { ScriptingBox } from '../../ScriptingBox'; dotenv.config(); @@ -96,7 +101,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { this.vectorstore_id = StrCast(this.dataDoc.vectorstore_id); } this.vectorstore = new Vectorstore(this.vectorstore_id, this.retrieveDocIds); - this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createDocInDash, this.createCSVInDash); + this.agent = new Agent(this.vectorstore, this.retrieveSummaries, this.retrieveFormattedHistory, this.retrieveCSVData, this.addLinkedUrlDoc, this.createDocInDash, this.createCSVInDash, this.createImageInDash); this.messagesRef = React.createRef<HTMLDivElement>(); // Reaction to update dataDoc when chat history changes @@ -400,20 +405,17 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }; @action - createImageInDash = async (url: string, title: string, id: string, data: string) => { - const doc = FieldUtils.ImageField( - { - tl: [0, 0], - br: [300, 300], - }, - 300, - 300, - title, - url ?? '', - {} - ); - - return doc; + createImageInDash = async (result: any, options: DocumentOptions) => { + const newImgSrc = + result.accessPaths.agnostic.client.indexOf('dashblobstore') === -1 // + ? ClientUtils.prepend(result.accessPaths.agnostic.client) + : result.accessPaths.agnostic.client; + const doc = Docs.Create.ImageDocument(newImgSrc, options); + this.addDocument(ImageUtils.AssignImgInfo(doc, result)); + const linkDoc = Docs.Create.LinkDocument(this.Document, doc); + LinkManager.Instance.addLink(linkDoc); + doc && this._props.addDocument?.(doc); + await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => {}); }; /** @@ -431,10 +433,6 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { case 'text': doc = Docs.Create.TextDocument(data || '', options); break; - case 'image': - console.log('imageURL: ' + data); - doc = await this.createImageInDash(data || '', options.title as string, '', data || ''); - break; case 'pdf': doc = Docs.Create.PdfDocument(data || '', options); break; @@ -471,6 +469,24 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { case 'chat': doc = Docs.Create.ChatDocument(options); break; + case 'script': + const result = !data!.trim() ? ({ compiled: false, errors: [] } as CompileError) : CompileScript(data!, {}); + const script_field = result.compiled ? new ScriptField(result, undefined, data!) : undefined; + doc = Docs.Create.ScriptingDocument(script_field, options); + await DocumentManager.Instance.showDocument(doc, { willZoomCentered: true }, () => { + const firstView = Array.from(doc[DocViews])[0] as DocumentView; + (firstView.ComponentView as ScriptingBox)?.onApply?.(); + (firstView.ComponentView as ScriptingBox)?.onRun?.(); + }); + + break; + // this.dataDoc.script = this.rawScript; + + // ScriptManager.Instance.addScript(this.dataDoc); + + // this._scriptKeys = ScriptingGlobals.getGlobals(); + // this._scriptingDescriptions = ScriptingGlobals.getDescriptions(); + // this._scriptingParams = ScriptingGlobals.getParameters(); // Add more cases for other document types default: console.error('Unknown or unsupported document type:', doc_type); |