pet-ai/server/plugin/volcengine/router/llm_router.go

31 lines
960 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package router
import (
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
"github.com/flipped-aurora/gin-vue-admin/server/plugin/volcengine/api"
"github.com/gin-gonic/gin"
)
type LLMRouter struct{}
// InitLLMRouter 初始化LLM路由
func (l *LLMRouter) InitLLMRouter(Router *gin.RouterGroup) {
// LLM相关路由组使用操作记录中间件
llmRouter := Router.Group("llm").Use(middleware.OperationRecord())
// LLM查询路由组不使用操作记录中间件用于GET请求
llmRouterWithoutRecord := Router.Group("llm")
// 获取API实例
llmApi := api.ApiGroupApp.LLMApi
{
// 需要记录操作的路由POST请求
llmRouter.POST("chat", llmApi.ChatCompletion) // LLM聊天完成
llmRouter.POST("stop", llmApi.StopGeneration) // 停止LLM生成
}
{
// 不需要记录操作的路由GET请求
llmRouterWithoutRecord.GET("sessions", llmApi.GetActiveSessionsCount) // 获取活跃会话数量
}
}