@@ -21,7 +21,7 @@ import {
2121import { CSSProperties , useEffect , useMemo , useRef , useState } from "react" ;
2222import { defineMessage , FormattedMessage , useIntl } from "react-intl" ;
2323import { Entries } from "type-fest" ;
24-
24+ import { trunc } from "@cocalc/util/misc" ;
2525import { LanguageSelector } from "@cocalc/frontend/account/i18n-selector" ;
2626import { useAsyncEffect } from "@cocalc/frontend/app-framework" ;
2727import getChatActions from "@cocalc/frontend/chat/get-actions" ;
@@ -601,7 +601,7 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
601601
602602 async function getExplanation ( preview : boolean ) {
603603 if ( actions == null ) return ; // shouldn't happen
604- const { message } = await createMessage ( preview ) ;
604+ const { message, name } = await createMessage ( preview ) ;
605605 if ( ! message ) {
606606 console . warn ( "getExplanation -- no cell with id" , id ) ;
607607 return ;
@@ -613,6 +613,7 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
613613 input : message ,
614614 tag : `jupyter-cell-llm:${ mode } ` ,
615615 noNotification : true ,
616+ name,
616617 } ) ;
617618
618619 // we also log this
@@ -628,7 +629,7 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
628629
629630 async function createMessage (
630631 preview : boolean ,
631- ) : Promise < { message : string ; tokens : number } > {
632+ ) : Promise < { message : string ; tokens : number ; name ?: string } > {
632633 const empty = { message : "" , tokens : 0 } ;
633634 if ( actions == null || mode == null || llmTools == null ) return empty ;
634635 const { model } = llmTools ;
@@ -637,14 +638,15 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
637638 const cell = actions . store . get ( "cells" ) . get ( id ) ;
638639 if ( ! cell ) return empty ;
639640
640- const { message, tokens } = await createMessageText ( {
641+ const { message, tokens, name } = await createMessageText ( {
641642 cell,
642643 model,
643644 preview,
644645 } ) ;
645646 return {
646647 message : preview ? message : `${ modelToMention ( model ) } ${ message } ` ,
647648 tokens,
649+ name,
648650 } ;
649651 }
650652
@@ -656,7 +658,7 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
656658 model : LanguageModel ;
657659 preview : boolean ;
658660 cell : any ;
659- } ) : Promise < { message : string ; tokens : number } > {
661+ } ) : Promise < { message : string ; tokens : number ; name ?: string } > {
660662 if ( mode == null || actions == null )
661663 return { message : "Error: no mode selected." , tokens : 0 } ;
662664
@@ -739,6 +741,7 @@ export function LLMCellTool({ actions, id, style, llmTools, cellType }: Props) {
739741 return {
740742 message,
741743 tokens : numTokensUpperBound ( message , getMaxTokens ( model ) ) ,
744+ name : trunc ( input ) ,
742745 } ;
743746 }
744747
0 commit comments