Fix: recover bot; llama.cpp fix
This commit is contained in:
		| @@ -37,18 +37,35 @@ type DSResp struct { | ||||
| 	Object            string `json:"object"` | ||||
| } | ||||
|  | ||||
| // type LLMResp struct { | ||||
| // 	Choices []struct { | ||||
| // 		FinishReason string `json:"finish_reason"` | ||||
| // 		Index        int    `json:"index"` | ||||
| // 		Message      struct { | ||||
| // 			Content string `json:"content"` | ||||
| // 			Role    string `json:"role"` | ||||
| // 		} `json:"message"` | ||||
| // 	} `json:"choices"` | ||||
| // 	Created int    `json:"created"` | ||||
| // 	Model   string `json:"model"` | ||||
| // 	Object  string `json:"object"` | ||||
| // } | ||||
|  | ||||
| type LLMResp struct { | ||||
| 	Choices []struct { | ||||
| 		FinishReason string `json:"finish_reason"` | ||||
| 		Index        int    `json:"index"` | ||||
| 		Message      struct { | ||||
| 			Content string `json:"content"` | ||||
| 			Role    string `json:"role"` | ||||
| 		} `json:"message"` | ||||
| 	} `json:"choices"` | ||||
| 	Created int    `json:"created"` | ||||
| 	Model   string `json:"model"` | ||||
| 	Object  string `json:"object"` | ||||
| 	Index           int    `json:"index"` | ||||
| 	Content         string `json:"content"` | ||||
| 	Tokens          []any  `json:"tokens"` | ||||
| 	IDSlot          int    `json:"id_slot"` | ||||
| 	Stop            bool   `json:"stop"` | ||||
| 	Model           string `json:"model"` | ||||
| 	TokensPredicted int    `json:"tokens_predicted"` | ||||
| 	TokensEvaluated int    `json:"tokens_evaluated"` | ||||
| 	Prompt          string `json:"prompt"` | ||||
| 	HasNewLine      bool   `json:"has_new_line"` | ||||
| 	Truncated       bool   `json:"truncated"` | ||||
| 	StopType        string `json:"stop_type"` | ||||
| 	StoppingWord    string `json:"stopping_word"` | ||||
| 	TokensCached    int    `json:"tokens_cached"` | ||||
| } | ||||
|  | ||||
| type MimeResp struct { | ||||
| @@ -63,13 +80,13 @@ type GusserResp struct { | ||||
| } | ||||
|  | ||||
| type Bot struct { | ||||
| 	Role      string // gueeser | mime | ||||
| 	Team      string | ||||
| 	cfg       *config.Config | ||||
| 	RoomID    string // can we get a room from here? | ||||
| 	BotName   string | ||||
| 	log       *slog.Logger | ||||
| 	LLMParser RespParser | ||||
| 	Role      string         `json:"role"` | ||||
| 	Team      string         `json:"team"` | ||||
| 	cfg       *config.Config `json:"-"` | ||||
| 	RoomID    string         `json:"room_id"` // can we get a room from here? | ||||
| 	BotName   string         `json:"bot_name"` | ||||
| 	log       *slog.Logger   `json:"-"` | ||||
| 	LLMParser RespParser     `json:"-"` | ||||
| 	// channels for communicaton | ||||
| 	// channels are not serializable | ||||
| 	// SignalsCh chan bool | ||||
| @@ -271,7 +288,7 @@ func NewBot(role, team, name, roomID string, cfg *config.Config) (*Bot, error) { | ||||
| } | ||||
|  | ||||
| func saveBot(bot *Bot) error { | ||||
| 	key := "botkey_" + bot.RoomID + bot.BotName | ||||
| 	key := models.CacheBotPredix + bot.RoomID + bot.BotName | ||||
| 	data, err := json.Marshal(bot) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
|   | ||||
| @@ -66,12 +66,13 @@ func (p *lcpRespParser) ParseBytes(body []byte) (map[string]any, error) { | ||||
| 		p.log.Error("failed to unmarshal", "error", err) | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if len(resp.Choices) == 0 { | ||||
| 		p.log.Error("empty choices", "resp", resp) | ||||
| 		err := errors.New("empty choices in resp") | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	text := resp.Choices[0].Message.Content | ||||
| 	// if len(resp.Choices) == 0 { | ||||
| 	// 	p.log.Error("empty choices", "resp", resp) | ||||
| 	// 	err := errors.New("empty choices in resp") | ||||
| 	// 	return nil, err | ||||
| 	// } | ||||
| 	// text := resp.Choices[0].Message.Content | ||||
| 	text := resp.Content | ||||
| 	li := strings.Index(text, "{") | ||||
| 	ri := strings.LastIndex(text, "}") | ||||
| 	if li < 0 || ri < 1 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder