Skip to content

Commit 33cd5d2

Browse files
committed
add
add
1 parent 99b8981 commit 33cd5d2

File tree

10 files changed

+1183
-344
lines changed

10 files changed

+1183
-344
lines changed

backend/app/core/prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_writer_prompt(
7575
skill:熟练掌握{format_output}排版,
7676
output:你需要按照要求的格式排版,只输出{format_output}排版的内容
7777
78-
1. 当你输入图像引用时候,image_name.png,就可正确引用显示
78+
1. 当你输入图像引用时候,使用![image_name](image_name.png)
7979
2. 你不需要输出markdown的这个```markdown格式,只需要输出markdown的内容
8080
3. 严格按照参考用户输入的格式模板以及**正确的编号顺序**
8181
4. 不需要询问用户

backend/app/tools/code_interpreter.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ async def _push_to_websocket(self, content_to_display: list[OutputItem] | None):
323323
async def get_created_images(self, section: str) -> list[str]:
324324
"""获取当前 section 创建的图片列表"""
325325
if not self.sbx:
326+
logger.warning("沙箱环境未初始化")
326327
return []
327328

328329
try:
@@ -335,6 +336,7 @@ async def get_created_images(self, section: str) -> list[str]:
335336
self.created_images = list(
336337
set(self.section_output[section]["images"]) - set(self.created_images)
337338
)
339+
logger.info(f"{section}-获取创建的图片列表: {self.created_images}")
338340
return self.created_images
339341
except Exception as e:
340342
logger.error(f"获取创建的图片列表失败: {str(e)}")
@@ -388,6 +390,10 @@ async def download_all_files_from_sandbox(self) -> None:
388390
# 下载新文件或更新已修改的文件
389391
for file in sandbox_files:
390392
try:
393+
# 排除 .bash_logout、.bashrc 和 .profile 文件
394+
if file.name in [".bash_logout", ".bashrc", ".profile"]:
395+
continue
396+
391397
local_path = os.path.join(self.work_dir, file.name)
392398
should_download = True
393399

@@ -398,19 +404,14 @@ async def download_all_files_from_sandbox(self) -> None:
398404
pass
399405

400406
if should_download:
401-
content = await self.sbx.files.read(file.path)
407+
# 使用 bytes 格式读取文件内容,确保正确处理二进制数据
408+
content = await self.sbx.files.read(file.path, format="bytes")
402409

403410
# 确保目标目录存在
404411
os.makedirs(self.work_dir, exist_ok=True)
405412

406413
# 写入文件
407414
with open(local_path, "wb") as f:
408-
if isinstance(content, str):
409-
if "," in content: # 处理data URL格式
410-
content = content.split(",")[1]
411-
content = base64.b64decode(content)
412-
else:
413-
content = content.encode("utf-8")
414415
f.write(content)
415416
logger.info(f"同步文件: {file.name}")
416417

frontend/src/components/CoderEditor.vue

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
<script lang="ts">
2-
export const description = 'A sidebar with a collapsible file tree.'
3-
export const iframeHeight = '800px'
4-
</script>
51
<script setup lang="ts">
6-
import { ref, computed } from 'vue'
2+
import { ref } from 'vue'
73
import {
84
SidebarInset,
95
SidebarProvider,
@@ -16,86 +12,6 @@ import {
1612
ResizablePanel,
1713
ResizableHandle,
1814
} from '@/components/ui/resizable'
19-
import type { CoderMessage } from '@/utils/response'
20-
21-
interface Cell {
22-
type: 'markdown' | 'code'
23-
content: string
24-
output: {
25-
type: 'text' | 'table' | 'plot'
26-
content?: string
27-
data?: {
28-
headers?: string[]
29-
rows?: any[][]
30-
}
31-
} | null
32-
isPreview?: boolean
33-
}
34-
35-
const props = defineProps<{
36-
messages: CoderMessage[]
37-
}>()
38-
39-
// 将代码执行结果转换为Notebook单元格
40-
const cells = computed<Cell[]>(() => {
41-
const notebookCells: Cell[] = []
42-
43-
for (const msg of props.messages) {
44-
// 如果有普通内容,创建markdown单元格
45-
if (msg.content) {
46-
notebookCells.push({
47-
type: 'markdown',
48-
content: msg.content,
49-
output: null,
50-
isPreview: true
51-
})
52-
}
53-
54-
// 如果有代码,创建代码单元格
55-
if (msg.code) {
56-
const cell: Cell = {
57-
type: 'code',
58-
content: msg.code,
59-
output: null
60-
}
61-
62-
// 如果有执行结果,添加到输出
63-
if (msg.code_results && msg.code_results.length > 0) {
64-
const result = msg.code_results[0] // 暂时只取第一个结果
65-
66-
if (result.res_type === 'result') {
67-
cell.output = {
68-
type: 'table',
69-
data: {
70-
headers: [],
71-
rows: []
72-
}
73-
}
74-
try {
75-
const data = JSON.parse(result.msg || '{}')
76-
if (data.headers && data.rows) {
77-
cell.output.data = data
78-
}
79-
} catch (e) {
80-
cell.output = {
81-
type: 'text',
82-
content: result.msg || ''
83-
}
84-
}
85-
} else {
86-
cell.output = {
87-
type: 'text',
88-
content: result.msg || ''
89-
}
90-
}
91-
}
92-
93-
notebookCells.push(cell)
94-
}
95-
}
96-
97-
return notebookCells
98-
})
9915
10016
const isCollapsed = ref(false)
10117
@@ -104,7 +20,6 @@ const handleCollapse = () => {
10420
isCollapsed.value = !isCollapsed.value
10521
}
10622
107-
10823
</script>
10924
<template>
11025
<SidebarProvider :collapsed="isCollapsed">
@@ -121,8 +36,8 @@ const handleCollapse = () => {
12136
<header class="flex h-10 shrink-0 items-center gap-2 border-b px-4">
12237
<SidebarTrigger class="-ml-1" @click="handleCollapse" />
12338
</header>
124-
<div class="flex-1 min-h-0 min-w-0 overflow-auto">
125-
<NotebookArea :cells="cells" class="h-full min-w-0" />
39+
<div class="flex-1 min-h-0 min-w-0 overflow-auto h-full">
40+
<NotebookArea class="h-full min-w-0 pb-4" />
12641
</div>
12742
</SidebarInset>
12843
</ResizablePanel>

0 commit comments

Comments
 (0)