Skip to content

v0.4: 多模态支持 + gRPC 插件骨架 #6

Description

@Yukk1o

概述

v0.4 两个核心目标:

  1. 多模态支持 — Message 从纯文本升级为结构化 ContentPart,适配图片输入
  2. gRPC 外部插件骨架 — Guard/PreProcessor/PostProcessor 通过 gRPC 作为独立进程加载,首个外部插件跑通

多模态

数据模型

  • Message.Contentstring 改为 []ContentPart 结构
  • ContentPart 类型:text / image_url / image_base64 / audio / file
  • 向后兼容:纯文本 string 自动转为 [{type: "text", text: "..."}]

Adapter 适配

  • adapter-openai — 透传 image_url(原生兼容)
  • adapter-anthropic — image_url 转 base64,content block 格式
  • adapter-ollama — 图片 base64 透传
  • 流式场景下多模态响应处理

PreProcessor 扩展

  • image-to-text 插件:图片 → 视觉模型描述 → 注入文本,让纯文本模型间接支持图片理解

gRPC 外部插件

Proto 定义

  • api/grpc/plugin.proto — Guard / PreProcessor / PostProcessor / PluginMeta / Init / Health 服务定义
  • oneof request 支持 ChatRequest(未来可扩展 Embedding/Rerank)
  • 代码生成:pb/plugin.pb.go + pb/plugin_grpc.pb.go

启动器

  • internal/plugin/grpc_launcher.go — 子进程启动,Unix socket 监听
  • plugins.yaml 新增 runtime: grpc + command 字段
  • 启动健康检查(gRPC Health Check)

Wrapper

  • internal/plugin/grpc_wrapper.go — 实现 api.Guard / PreProcessor / PostProcessor
  • api/grpc/convert.go — api.PipelineContext ↔ proto 互转
  • internal/plugin/grpc_errors.go — gRPC status → api.PluginError 映射

插件 SDK

  • plugin/sdk/server.goServe() 一行启动 gRPC server
  • plugin/sdk/testing.go — TestHarness 测试工具

连接

  • 单连接(无连接池),后续版本优化

完成标志

  • /v1/chat/completions 可接收图片输入,OpenAI/Anthropic/Ollama 三个 adapter 均支持多模态
  • 首个外部插件通过 plugins.yaml runtime: grpc 加载并参与管线执行

设计文档

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions