Version: 0.9.80.dev.260506
后端: 1. LLM 独立服务与统一计费出口落地:新增 `cmd/llm`、`client/llm` 与 `services/llm/rpc`,补齐 BillingContext、CreditBalanceGuard、价格规则解析、stream usage 归集与 `credit.charge.requested` outbox 发布,active-scheduler / agent / course / memory / gateway fallback 全部改走 llm zrpc,不再各自本地初始化模型。 2. TokenStore 收口为 Credit 权威账本:新增 credit account / ledger / product / order / price-rule / reward-rule 能力与 Redis 快照缓存,扩展 tokenstore rpc/client 支撑余额快照、消耗看板、商品、订单、流水、价格规则和奖励规则,并接入 LLM charge 事件消费完成 Credit 扣费落账。 3. 计费旧链路下线与网关切口切换:`/token-store` 语义整体切到 `/credit-store`,agent chat 移除旧 TokenQuotaGuard,userauth 的 CheckTokenQuota / AdjustTokenUsage 改为废弃,聊天历史落库不再同步旧 token 额度账本,course 图片解析请求补 user_id 进入新计费口径。 前端: 4. 计划广场从 mock 数据切到真实接口:新增 forum api/types,首页支持真实列表、标签、搜索、防抖、点赞、导入和发布计划,详情页补齐帖子详情、评论树、回复和删除评论链路,同时补上“至少一个标签”的前后端约束与默认标签兜底。 5. 商店页切到 Credit 体系并重做展示:顶部改为余额 + Credit/Token 消耗看板,支持 24h/7d/30d/all 周期切换;套餐区展示原价与当前价;历史区改为当前用户 Credit 流水并支持查看更多,整体视觉和交互同步收口。 仓库: 6. 配置与本地启动体系补齐 llm / outbox 编排:`config.example.yaml` 增加 llm rpc 和统一 outbox service 配置,`dev-common.ps1` 把 llm 纳入多服务依赖并自动建 Kafka topic,`docker-compose.yml` 同步初始化 agent/task/memory/active-scheduler/notification/taskclass-forum/llm/token-store 全量 outbox topic。
This commit is contained in:
131
backend/shared/contracts/llm/contracts.go
Normal file
131
backend/shared/contracts/llm/contracts.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/cloudwego/eino/schema"
|
||||
)
|
||||
|
||||
const (
|
||||
ModelAliasLite = "lite"
|
||||
ModelAliasPro = "pro"
|
||||
ModelAliasMax = "max"
|
||||
ModelAliasCourseImageResponses = "course_image_responses"
|
||||
|
||||
DefaultTextModelAlias = ModelAliasPro
|
||||
ProviderNameArk = "ark"
|
||||
)
|
||||
|
||||
// PingRequest 只用于跨进程探活,不承载业务字段。
|
||||
type PingRequest struct{}
|
||||
|
||||
// PingResponse 只用于跨进程探活,不承载业务字段。
|
||||
type PingResponse struct{}
|
||||
|
||||
// BillingContext 是 LLM RPC 透传的计费上下文副本。
|
||||
type BillingContext struct {
|
||||
UserID uint64 `json:"user_id"`
|
||||
EventID string `json:"event_id"`
|
||||
Scene string `json:"scene"`
|
||||
RequestID string `json:"request_id"`
|
||||
ConversationID string `json:"conversation_id"`
|
||||
ModelAlias string `json:"model_alias"`
|
||||
SkipCharge bool `json:"skip_charge"`
|
||||
}
|
||||
|
||||
// GenerateOptions 是文本模型跨进程调用时的最小公共参数。
|
||||
type GenerateOptions struct {
|
||||
Temperature float64 `json:"temperature"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
Thinking string `json:"thinking"`
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// TextRequest 描述一次非流式文本调用。
|
||||
type TextRequest struct {
|
||||
ModelAlias string `json:"model_alias"`
|
||||
Messages []*schema.Message `json:"messages"`
|
||||
Options GenerateOptions `json:"options"`
|
||||
Billing *BillingContext `json:"billing,omitempty"`
|
||||
}
|
||||
|
||||
// StreamTextRequest 描述一次流式文本调用。
|
||||
type StreamTextRequest struct {
|
||||
ModelAlias string `json:"model_alias"`
|
||||
Messages []*schema.Message `json:"messages"`
|
||||
Options GenerateOptions `json:"options"`
|
||||
Billing *BillingContext `json:"billing,omitempty"`
|
||||
}
|
||||
|
||||
// TextResult 保存文本模型最终输出。
|
||||
type TextResult struct {
|
||||
Text string `json:"text"`
|
||||
Usage *schema.TokenUsage `json:"usage,omitempty"`
|
||||
FinishReason string `json:"finish_reason,omitempty"`
|
||||
}
|
||||
|
||||
// TextResponse 统一包住文本调用结果,便于后续扩字段。
|
||||
type TextResponse struct {
|
||||
Result *TextResult `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
// StreamChunk 是流式返回的最小块协议。
|
||||
type StreamChunk struct {
|
||||
Message *schema.Message `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// ResponsesMessage 描述 Responses 模型单条输入。
|
||||
type ResponsesMessage struct {
|
||||
Role string `json:"role"`
|
||||
Text string `json:"text,omitempty"`
|
||||
ImageURL string `json:"image_url,omitempty"`
|
||||
ImageDetail string `json:"image_detail,omitempty"`
|
||||
}
|
||||
|
||||
// ResponsesOptions 描述 Responses 模型公共参数。
|
||||
type ResponsesOptions struct {
|
||||
Model string `json:"model,omitempty"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
MaxOutputTokens int `json:"max_output_tokens"`
|
||||
Thinking string `json:"thinking"`
|
||||
TextFormat string `json:"text_format,omitempty"`
|
||||
}
|
||||
|
||||
// ResponsesRequest 描述一次 Responses 文本调用。
|
||||
type ResponsesRequest struct {
|
||||
ModelAlias string `json:"model_alias"`
|
||||
Messages []ResponsesMessage `json:"messages"`
|
||||
Options ResponsesOptions `json:"options"`
|
||||
Billing *BillingContext `json:"billing,omitempty"`
|
||||
}
|
||||
|
||||
// ResponsesUsage 是 Responses 结果里的最小 usage 结构。
|
||||
type ResponsesUsage struct {
|
||||
InputTokens int64 `json:"input_tokens"`
|
||||
OutputTokens int64 `json:"output_tokens"`
|
||||
TotalTokens int64 `json:"total_tokens"`
|
||||
}
|
||||
|
||||
// ResponsesResult 统一承载 Responses 输出。
|
||||
type ResponsesResult struct {
|
||||
Text string `json:"text"`
|
||||
Status string `json:"status,omitempty"`
|
||||
IncompleteReason string `json:"incomplete_reason,omitempty"`
|
||||
ErrorCode string `json:"error_code,omitempty"`
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
Usage *ResponsesUsage `json:"usage,omitempty"`
|
||||
}
|
||||
|
||||
// ResponsesResponse 统一包住 Responses 结果。
|
||||
type ResponsesResponse struct {
|
||||
Result *ResponsesResult `json:"result,omitempty"`
|
||||
}
|
||||
|
||||
// NormalizeModelAlias 负责把空别名收敛到默认文本模型。
|
||||
func NormalizeModelAlias(raw string) string {
|
||||
trimmed := strings.TrimSpace(raw)
|
||||
if trimmed == "" {
|
||||
return DefaultTextModelAlias
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
Reference in New Issue
Block a user