model_routing

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CandidatesResponse

type CandidatesResponse struct {
	Models         []string `json:"models"`
	GlobalRoutings []string `json:"global_routings"`
}

CandidatesResponse 是 admin 端 GET /admin/model-routings/candidates 的响应。 user portal 改用 RoutingNamesResp(见 PortalGlobalRoutingNames)。

type CreateRequest

type CreateRequest struct {
	Name    string        `json:"name" binding:"required"`
	Scope   string        `json:"scope" binding:"required"`
	UserID  uint          `json:"user_id"`
	Members []MemberInput `json:"members" binding:"required"`
	Enabled bool          `json:"enabled"`
	Remark  string        `json:"remark"`
}

type EffectiveWeight

type EffectiveWeight struct {
	Ref     string  `json:"ref"`
	Percent float64 `json:"percent"`
}

EffectiveWeight 表示某个真实 model 的最终权重百分比。

type GetResponse

type GetResponse struct {
	models.ModelRouting
	ExpandedModels []string `json:"expanded_models"`
}

GetResponse 在 ModelRouting 基础上附加展开后的真实模型名列表。

type Handler

type Handler struct {
	Bus app.EventBus
}

Handler 是 model-routings 的 admin 路由处理器。

func (*Handler) Candidates

func (h *Handler) Candidates(c *app.Context, _ struct{}) (CandidatesResponse, error)

func (*Handler) Create

func (h *Handler) Create(c *app.Context, req CreateRequest) (models.ModelRouting, error)

func (*Handler) Delete

func (h *Handler) Delete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)

func (*Handler) Get

func (h *Handler) Get(c *app.Context, req api.IDPathRequest) (GetResponse, error)

func (*Handler) List

func (*Handler) PortalCreate

func (h *Handler) PortalCreate(c *app.Context, req CreateRequest) (models.ModelRouting, error)

PortalCreate 强制 scope=user, user_id=current,忽略客户端传入的这两个字段。

func (*Handler) PortalDelete

func (h *Handler) PortalDelete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)

PortalDelete 仅允许删除自己的 routing。

func (*Handler) PortalGet

func (h *Handler) PortalGet(c *app.Context, req api.IDPathRequest) (GetResponse, error)

PortalGet 返回单条 routing;越权访问其他用户的 routing 返回 404 (404 而非 403:避免泄露 routing 是否存在的信息)。

func (*Handler) PortalGlobalRoutingNames

func (h *Handler) PortalGlobalRoutingNames(c *app.Context, _ struct{}) (RoutingNamesResp, error)

PortalGlobalRoutingNames 返回所有 enabled global routing 名(升序)。 用户作用域的 routing 不在此处暴露——它们由 PortalList 列出。 真实 model 候选不再由后端计算:前端用所选 token 直接调 /v1/models 取得, 与运行时过滤逻辑(internal/agent/relay/models.go:33)共用同一真相源。

func (*Handler) PortalList

PortalList 列出当前用户可管理的 routings: scope=user + user_id=current(不含 global,global 只读,不在 portal 管理范围)。

func (*Handler) PortalUpdate

func (h *Handler) PortalUpdate(c *app.Context, req UpdateRequest) (models.ModelRouting, error)

PortalUpdate 仅允许更新自己的 routing;scope/user_id/id 字段被剥离,不可被客户端修改。

func (*Handler) Preview

func (h *Handler) Preview(c *app.Context, req PreviewRequest) (PreviewResponse, error)

func (*Handler) Update

func (h *Handler) Update(c *app.Context, req UpdateRequest) (models.ModelRouting, error)

type ListRequest

type ListRequest struct {
	api.PaginationQuery
	Scope  string `form:"scope"`
	UserID *uint  `form:"user_id"`
	Q      string `form:"q"`
}

type MemberInput

type MemberInput struct {
	Ref      string `json:"ref"`
	Priority int    `json:"priority"`
	Weight   int    `json:"weight"`
}

type PreviewNode

type PreviewNode struct {
	Ref          string        `json:"ref"`
	Kind         string        `json:"kind"`            // model | routing | invalid
	Scope        string        `json:"scope,omitempty"` // routing 节点的 scope
	Priority     int           `json:"priority"`
	Weight       int           `json:"weight"`
	EffectivePct float64       `json:"effective_pct"`
	Children     []PreviewNode `json:"children,omitempty"`
	Error        string        `json:"error,omitempty"` // not_found | disabled | cycle | max_depth
}

PreviewNode 是预览树的一个节点。 kind=routing 时是中间节点(含 children),kind=model 时是叶子。

type PreviewRequest

type PreviewRequest struct {
	Members    []MemberInput `json:"members" binding:"required"`
	SelfName   string        `json:"self_name"`
	SelfScope  string        `json:"self_scope"`
	SelfUserID uint          `json:"self_user_id"`
}

type PreviewResponse

type PreviewResponse struct {
	Root             PreviewNode       `json:"root"`
	EffectiveWeights []EffectiveWeight `json:"effective_weights"`
	Warnings         []string          `json:"warnings"`
}

PreviewResponse 是 preview 接口的响应结构。

type RoutingNamesResp

type RoutingNamesResp struct {
	Names []string `json:"names"`
}

RoutingNamesResp 是 PortalGlobalRoutingNames 的响应:仅含 enabled global routing 名称(升序)。

type UpdateRequest

type UpdateRequest struct {
	ID     string         `uri:"id" binding:"required"`
	Fields map[string]any `json:"-"`
}

func (*UpdateRequest) SetBodyMap

func (r *UpdateRequest) SetBodyMap(fs map[string]any)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL