chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,75 @@
|
||||
package vlm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"academy/internal/logger"
|
||||
)
|
||||
|
||||
// debugVLM wraps a VLM with LLM debug logging.
|
||||
type debugVLM struct {
|
||||
inner VLM
|
||||
}
|
||||
|
||||
func (d *debugVLM) Predict(ctx context.Context, imgBytes [][]byte, prompt string) (string, error) {
|
||||
return d.call(ctx, imgBytes, prompt, nil)
|
||||
}
|
||||
|
||||
func (d *debugVLM) PredictWithOptions(
|
||||
ctx context.Context, imgBytes [][]byte, prompt string, opts *PredictOptions,
|
||||
) (string, error) {
|
||||
return d.call(ctx, imgBytes, prompt, opts)
|
||||
}
|
||||
|
||||
func (d *debugVLM) call(
|
||||
ctx context.Context, imgBytes [][]byte, prompt string, opts *PredictOptions,
|
||||
) (string, error) {
|
||||
start := time.Now()
|
||||
result, err := d.inner.PredictWithOptions(ctx, imgBytes, prompt, opts)
|
||||
logVLMDebug(ctx, d.inner.GetModelName(), imgBytes, prompt, result, err, time.Since(start))
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (d *debugVLM) GetModelName() string { return d.inner.GetModelName() }
|
||||
func (d *debugVLM) GetModelID() string { return d.inner.GetModelID() }
|
||||
|
||||
func logVLMDebug(ctx context.Context, model string, imgBytes [][]byte, prompt string, response string, callErr error, dur time.Duration) {
|
||||
if !logger.LLMDebugEnabled() {
|
||||
return
|
||||
}
|
||||
|
||||
record := &logger.LLMCallRecord{
|
||||
CallType: "VLM",
|
||||
Model: model,
|
||||
Duration: dur,
|
||||
}
|
||||
|
||||
// Input section
|
||||
var inputBuf strings.Builder
|
||||
inputBuf.WriteString(fmt.Sprintf("Images: count=%d", len(imgBytes)))
|
||||
totalSize := 0
|
||||
for _, img := range imgBytes {
|
||||
totalSize += len(img)
|
||||
}
|
||||
inputBuf.WriteString(fmt.Sprintf(", total_size=%d bytes\n\n", totalSize))
|
||||
inputBuf.WriteString("[prompt]\n")
|
||||
inputBuf.WriteString(prompt)
|
||||
inputBuf.WriteString("\n")
|
||||
record.Sections = append(record.Sections, logger.RecordSection{Title: "Input", Content: inputBuf.String()})
|
||||
|
||||
// Response section
|
||||
if response != "" {
|
||||
record.Sections = append(record.Sections, logger.RecordSection{
|
||||
Title: "Response",
|
||||
Content: response,
|
||||
})
|
||||
}
|
||||
|
||||
if callErr != nil {
|
||||
record.Error = callErr.Error()
|
||||
}
|
||||
logger.LLMDebugLog(ctx, record)
|
||||
}
|
||||
Reference in new issue
Block a user