feat: pictures for the assistant - the models make and edit them by themselves through the Vertex API (a new picture, or the user's attached photo, or the last picture made), with an API key in Настройки and a switch for the prompt improver; folded descriptions of pictures and searches; the name of an attached file opens or saves it; a deleted chat is wiped from the database files, attachments included
This commit is contained in:
1 parent
c72fcfebf3
commit
dd1244a169
13 files changed
+925
-20
No files matched your search
@@ -763,6 +763,7 @@ func (s *Server) aiDeleteChat(owner, chat int64) {
|
||||
}
|
||||
_, _ = s.db.sql.Exec(`DELETE FROM ai_messages WHERE chat_id = ? AND admin_id = ?`, chat, owner)
|
||||
_, _ = s.db.sql.Exec(`DELETE FROM ai_chats WHERE id = ? AND admin_id = ?`, chat, owner)
|
||||
s.db.wipeDeleted()
|
||||
}
|
||||
|
||||
// aiAppendTo keeps a message of owner's chat; the first question names it.
|
||||
@@ -781,6 +782,7 @@ func (s *Server) aiKeepMsg(owner, chat int64, m aiMsg) {
|
||||
now := time.Now().Unix()
|
||||
_, _ = s.db.sql.Exec(`INSERT INTO ai_messages (admin_id, chat_id, role, content, at, think_ms) VALUES (?, ?, ?, ?, ?, ?)`, owner, chat, role, content, now, m.ThinkMS)
|
||||
_, _ = s.db.sql.Exec(`DELETE FROM ai_messages WHERE chat_id = ? AND id <= (SELECT id FROM ai_messages WHERE chat_id = ? ORDER BY id DESC LIMIT 1 OFFSET ?)`, chat, chat, aiKeep)
|
||||
s.db.wipeDeleted()
|
||||
_, _ = s.db.sql.Exec(`UPDATE ai_chats SET updated = ? WHERE id = ?`, now, chat)
|
||||
if role == "user" {
|
||||
t := strings.Join(strings.Fields(content), " ")
|
||||
@@ -950,6 +952,7 @@ func (s *Server) handleAIChat(w http.ResponseWriter, r *http.Request) {
|
||||
system += "\n\nК последнему сообщению пользователя приложены файлы (" + strings.Join(media, ", ") +
|
||||
"): ты получаешь их сам - видишь изображения и видео, слышишь аудио. Отвечай на вопросы о них по существу."
|
||||
}
|
||||
system += s.imagePrompt()
|
||||
if in.Agent {
|
||||
system += aiAgent
|
||||
}
|
||||
@@ -1152,7 +1155,8 @@ func (s *Server) handleAIState(w http.ResponseWriter, r *http.Request) {
|
||||
for _, m := range s.aiModels() {
|
||||
ms = append(ms, pick{m.ID, m.label(), m.Short})
|
||||
}
|
||||
writeJSON(w, map[string]any{"on": on != "0", "models": ms})
|
||||
_, imgKey := s.imageConf()
|
||||
writeJSON(w, map[string]any{"on": on != "0", "models": ms, "image": imgKey != ""})
|
||||
}
|
||||
|
||||
// POST /api/panel/ai/toggle - {on}: the user's own switch.
|
||||
@@ -1220,6 +1224,8 @@ func (s *Server) handleSetAI(w http.ResponseWriter, r *http.Request) {
|
||||
_ = s.db.SetConfig(cfgSearchEngine, eng)
|
||||
_ = s.db.SetConfig(cfgSearchURL, strings.TrimSpace(r.FormValue("ai_search_url")))
|
||||
_ = s.db.SetConfig(cfgSearchKey, strings.TrimSpace(r.FormValue("ai_search_key")))
|
||||
// The key of the image service («Генерация изображений»).
|
||||
_ = s.db.SetConfig(cfgImageKey, strings.TrimSpace(r.FormValue("ai_image_key")))
|
||||
http.Redirect(w, r, "/settings#ai", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user