Compare commits
2 Commits
8458edf5a8
...
4bddce3700
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bddce3700 | ||
|
|
fcc71987bf |
4
bot.go
4
bot.go
@@ -64,6 +64,8 @@ var (
|
|||||||
"meta-llama/llama-3.3-70b-instruct:free",
|
"meta-llama/llama-3.3-70b-instruct:free",
|
||||||
}
|
}
|
||||||
LocalModels = []string{}
|
LocalModels = []string{}
|
||||||
|
localModelsData *models.LCPModels
|
||||||
|
orModelsData *models.ORModels
|
||||||
)
|
)
|
||||||
|
|
||||||
var thinkBlockRE = regexp.MustCompile(`(?s)<think>.*?</think>`)
|
var thinkBlockRE = regexp.MustCompile(`(?s)<think>.*?</think>`)
|
||||||
@@ -355,6 +357,7 @@ func fetchORModels(free bool) ([]string, error) {
|
|||||||
if err := json.NewDecoder(resp.Body).Decode(data); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
orModelsData = data
|
||||||
freeModels := data.ListModels(free)
|
freeModels := data.ListModels(free)
|
||||||
return freeModels, nil
|
return freeModels, nil
|
||||||
}
|
}
|
||||||
@@ -416,6 +419,7 @@ func fetchLCPModelsWithStatus() (*models.LCPModels, error) {
|
|||||||
if err := json.NewDecoder(resp.Body).Decode(data); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(data); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
localModelsData = data
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
82
helpfuncs.go
82
helpfuncs.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
@@ -376,9 +377,90 @@ func makeStatusLine() string {
|
|||||||
roleInject := fmt.Sprintf(" | [%s:-:b]role injection[-:-:-] (alt+7)", boolColors[injectRole])
|
roleInject := fmt.Sprintf(" | [%s:-:b]role injection[-:-:-] (alt+7)", boolColors[injectRole])
|
||||||
statusLine += roleInject
|
statusLine += roleInject
|
||||||
}
|
}
|
||||||
|
// context tokens
|
||||||
|
contextTokens := getContextTokens()
|
||||||
|
maxCtx := getMaxContextTokens()
|
||||||
|
if maxCtx == 0 {
|
||||||
|
maxCtx = 16384
|
||||||
|
}
|
||||||
|
if contextTokens > 0 {
|
||||||
|
contextInfo := fmt.Sprintf(" | context-estim: [orange:-:b]%d/%d[-:-:-]", contextTokens, maxCtx)
|
||||||
|
statusLine += contextInfo
|
||||||
|
}
|
||||||
return statusLine + imageInfo + shellModeInfo
|
return statusLine + imageInfo + shellModeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getContextTokens() int {
|
||||||
|
if chatBody == nil || chatBody.Messages == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
total := 0
|
||||||
|
messages := chatBody.Messages
|
||||||
|
for i := range messages {
|
||||||
|
msg := &messages[i]
|
||||||
|
if msg.Stats != nil && msg.Stats.Tokens > 0 {
|
||||||
|
total += msg.Stats.Tokens
|
||||||
|
} else if msg.GetText() != "" {
|
||||||
|
total += len(msg.GetText()) / 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
const deepseekContext = 128000
|
||||||
|
|
||||||
|
func getMaxContextTokens() int {
|
||||||
|
if chatBody == nil || chatBody.Model == "" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
modelName := chatBody.Model
|
||||||
|
switch {
|
||||||
|
case strings.Contains(cfg.CurrentAPI, "openrouter"):
|
||||||
|
if orModelsData != nil {
|
||||||
|
for i := range orModelsData.Data {
|
||||||
|
m := &orModelsData.Data[i]
|
||||||
|
if m.ID == modelName {
|
||||||
|
return m.ContextLength
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case strings.Contains(cfg.CurrentAPI, "deepseek"):
|
||||||
|
return deepseekContext
|
||||||
|
default:
|
||||||
|
if localModelsData != nil {
|
||||||
|
for i := range localModelsData.Data {
|
||||||
|
m := &localModelsData.Data[i]
|
||||||
|
if m.ID == modelName {
|
||||||
|
for _, arg := range m.Status.Args {
|
||||||
|
if strings.HasPrefix(arg, "--ctx-size") {
|
||||||
|
if strings.Contains(arg, "=") {
|
||||||
|
val := strings.Split(arg, "=")[1]
|
||||||
|
if n, err := strconv.Atoi(val); err == nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
idx := -1
|
||||||
|
for j, a := range m.Status.Args {
|
||||||
|
if a == "--ctx-size" && j+1 < len(m.Status.Args) {
|
||||||
|
idx = j + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if idx != -1 {
|
||||||
|
if n, err := strconv.Atoi(m.Status.Args[idx]); err == nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// set of roles within card definition and mention in chat history
|
// set of roles within card definition and mention in chat history
|
||||||
func listChatRoles() []string {
|
func listChatRoles() []string {
|
||||||
currentChat, ok := chatMap[activeChatName]
|
currentChat, ok := chatMap[activeChatName]
|
||||||
|
|||||||
Reference in New Issue
Block a user