feat: a short name of up to 7 characters for each model, on the chat's model button, always whole; the message field back to the normal 14px
This commit is contained in:
1 parent
351e4ad28d
commit
6a17f40042
6 files changed
+39
-23
No files matched your search
+16
-8
@@ -43,11 +43,13 @@ const (
|
||||
// default; an explicit "0" means the user turned it off.
|
||||
func aiUserKey(id int64) string { return "ai_user_" + strconv.FormatInt(id, 10) }
|
||||
|
||||
// aiConfig is one model the assistant can ask: its id and the name the chat
|
||||
// shows, the kind of API, its address, model and key.
|
||||
// aiConfig is one model the assistant can ask: its id and the names the chat
|
||||
// shows (Short, up to 7 characters, on the button of the model in use), the
|
||||
// kind of API, its address, model and key.
|
||||
type aiConfig struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Short string `json:"short,omitempty"`
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
@@ -75,6 +77,11 @@ func (c aiConfig) tidy() aiConfig {
|
||||
c.Type = "gradio"
|
||||
}
|
||||
c.Name, c.Model, c.Key = strings.TrimSpace(c.Name), strings.TrimSpace(c.Model), strings.TrimSpace(c.Key)
|
||||
if r := []rune(strings.TrimSpace(c.Short)); len(r) > 7 {
|
||||
c.Short = strings.TrimSpace(string(r[:7]))
|
||||
} else {
|
||||
c.Short = string(r)
|
||||
}
|
||||
c.URL = strings.TrimRight(strings.TrimSpace(c.URL), "/")
|
||||
if c.URL == "" && c.Type == "gradio" {
|
||||
c.URL = DefaultAIURL
|
||||
@@ -930,12 +937,13 @@ func (s *Server) handleAIState(w http.ResponseWriter, r *http.Request) {
|
||||
on, _ := s.db.GetConfig(aiUserKey(s.currentAdmin(r).ID))
|
||||
// The models to choose from: ids and names, never a key.
|
||||
type pick struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Short string `json:"short,omitempty"`
|
||||
}
|
||||
var ms []pick
|
||||
for _, m := range s.aiModels() {
|
||||
ms = append(ms, pick{m.ID, m.label()})
|
||||
ms = append(ms, pick{m.ID, m.label(), m.Short})
|
||||
}
|
||||
writeJSON(w, map[string]any{"on": on != "0", "models": ms})
|
||||
}
|
||||
@@ -968,7 +976,7 @@ func (s *Server) handleSetAI(w http.ResponseWriter, r *http.Request) {
|
||||
// what it holds is the key (empty: none). A card left empty is dropped;
|
||||
// a new one gets an id.
|
||||
f := r.PostForm
|
||||
ids, names, types, urls, models, keys := f["m_id"], f["m_name"], f["m_type"], f["m_url"], f["m_model"], f["m_key"]
|
||||
ids, names, shorts, types, urls, models, keys := f["m_id"], f["m_name"], f["m_short"], f["m_type"], f["m_url"], f["m_model"], f["m_key"]
|
||||
at := func(v []string, i int) string {
|
||||
if i < len(v) {
|
||||
return v[i]
|
||||
@@ -978,8 +986,8 @@ func (s *Server) handleSetAI(w http.ResponseWriter, r *http.Request) {
|
||||
var ms []aiConfig
|
||||
seen := map[string]bool{}
|
||||
for i := range types {
|
||||
m := aiConfig{ID: at(ids, i), Name: at(names, i), Type: at(types, i), URL: at(urls, i), Model: at(models, i), Key: at(keys, i)}
|
||||
if strings.TrimSpace(m.Name+m.Type+m.URL+m.Model+m.Key) == "" {
|
||||
m := aiConfig{ID: at(ids, i), Name: at(names, i), Short: at(shorts, i), Type: at(types, i), URL: at(urls, i), Model: at(models, i), Key: at(keys, i)}
|
||||
if strings.TrimSpace(m.Name+m.Short+m.Type+m.URL+m.Model+m.Key) == "" {
|
||||
continue
|
||||
}
|
||||
if m.ID == "" || seen[m.ID] || len(m.ID) > 32 {
|
||||
|
||||
Reference in new issue
Block a user