609f7d06cf
- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导), 服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar - pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页, 微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台 - 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package service
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/sundynix/pets-be/internal/model"
|
|
)
|
|
|
|
// AIChat 记录一问一答:启用模型则真调(注入宠物档案),否则规则化文案
|
|
func (s *Service) AIChat(userID uint, petID *uint, session, text string) (string, error) {
|
|
reply := "我会先判断风险等级,再建议你记录关键观察项。若出现频繁呕吐、便血、精神明显变差或持续超过 24 小时,建议尽快就医。"
|
|
if s.ai != nil && s.ai.Enabled() {
|
|
if r, err := s.llmChat(petID, text); err == nil && r != "" {
|
|
reply = r
|
|
}
|
|
}
|
|
|
|
msgs := []model.AIMessage{
|
|
{UserID: userID, PetID: petID, Session: session, Role: "user", Text: text},
|
|
{UserID: userID, PetID: petID, Session: session, Role: "ai", Text: reply},
|
|
}
|
|
if err := s.db.Create(&msgs).Error; err != nil {
|
|
return "", err
|
|
}
|
|
return reply, nil
|
|
}
|
|
|
|
// Upload 代理到对象存储
|
|
func (s *Service) Upload(objectName string, reader io.Reader, size int64, contentType string) (string, error) {
|
|
return s.storage.Upload(objectName, reader, size, contentType)
|
|
}
|