mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Fix storing code results on server and rendering them on web app
- Fix code context data type for validation on server. This would prevent the chat message from being written to history - Handle null code results on web app
This commit is contained in:
@@ -205,7 +205,7 @@ export function renderCodeGenImageInline(message: string, codeContext: CodeConte
|
||||
if (!codeContext) return message;
|
||||
|
||||
Object.values(codeContext).forEach((contextData) => {
|
||||
contextData.results.output_files?.forEach((file) => {
|
||||
contextData.results?.output_files?.forEach((file) => {
|
||||
const regex = new RegExp(`!?\\[.*?\\]\\(.*${file.filename}\\)`, "g");
|
||||
if (file.filename.match(/\.(png|jpg|jpeg)$/i)) {
|
||||
const replacement = `.pop()};base64,${file.b64_data})`;
|
||||
|
||||
@@ -129,7 +129,7 @@ export interface CodeContextData {
|
||||
output_files: CodeContextFile[];
|
||||
std_out: string;
|
||||
std_err: string;
|
||||
code_runtime: number;
|
||||
code_runtime?: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>((props, ref) =>
|
||||
// Add code context files to the message
|
||||
if (props.chatMessage.codeContext) {
|
||||
Object.entries(props.chatMessage.codeContext).forEach(([key, value]) => {
|
||||
value.results.output_files?.forEach((file) => {
|
||||
value.results?.output_files?.forEach((file) => {
|
||||
if (file.filename.endsWith(".png") || file.filename.endsWith(".jpg")) {
|
||||
// Don't add the image again if it's already in the message!
|
||||
if (!message.includes(`) {
|
||||
|
||||
@@ -36,12 +36,12 @@ class CodeContextResult(PydanticBaseModel):
|
||||
output_files: List[CodeContextFile]
|
||||
std_out: str
|
||||
std_err: str
|
||||
code_runtime: int
|
||||
code_runtime: Optional[int] = None
|
||||
|
||||
|
||||
class CodeContextData(PydanticBaseModel):
|
||||
code: str
|
||||
result: Optional[CodeContextResult] = None
|
||||
results: Optional[CodeContextResult] = None
|
||||
|
||||
|
||||
class WebPage(PydanticBaseModel):
|
||||
|
||||
Reference in New Issue
Block a user