Chore: fix linter complaints
This commit is contained in:
@@ -3,6 +3,7 @@ package rag
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gf-lt/config"
|
"gf-lt/config"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
@@ -69,7 +70,7 @@ func (a *APIEmbedder) Embed(text []string) ([][]float32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(emb) == 0 {
|
if len(emb) == 0 {
|
||||||
err = fmt.Errorf("empty embedding response")
|
err = errors.New("empty embedding response")
|
||||||
a.logger.Error("empty embedding response")
|
a.logger.Error("empty embedding response")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ func (a *APIEmbedder) EmbedSingle(text string) ([]float32, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
return nil, fmt.Errorf("no embeddings returned")
|
return nil, errors.New("no embeddings returned")
|
||||||
}
|
}
|
||||||
return result[0], nil
|
return result[0], nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package rag
|
package rag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gf-lt/config"
|
"gf-lt/config"
|
||||||
"gf-lt/models"
|
"gf-lt/models"
|
||||||
@@ -108,7 +109,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(paragraphs) == 0 {
|
if len(paragraphs) == 0 {
|
||||||
return fmt.Errorf("no valid paragraphs found in file")
|
return errors.New("no valid paragraphs found in file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -222,7 +223,7 @@ func (r *RAG) fetchEmb(lines []string, errCh chan error, vectorCh chan<- []model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(embeddings) == 0 {
|
if len(embeddings) == 0 {
|
||||||
err := fmt.Errorf("no embeddings returned")
|
err := errors.New("no embeddings returned")
|
||||||
r.logger.Error("empty embeddings")
|
r.logger.Error("empty embeddings")
|
||||||
errCh <- err
|
errCh <- err
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
|
|||||||
// we'll implement batching and potentially add L2 distance-based pre-filtering
|
// we'll implement batching and potentially add L2 distance-based pre-filtering
|
||||||
// since cosine similarity is related to L2 distance for normalized vectors
|
// since cosine similarity is related to L2 distance for normalized vectors
|
||||||
|
|
||||||
querySQL := fmt.Sprintf("SELECT embeddings, slug, raw_text, filename FROM %s", tableName)
|
querySQL := "SELECT embeddings, slug, raw_text, filename FROM " + tableName
|
||||||
rows, err := vs.sqlxDB.Query(querySQL)
|
rows, err := vs.sqlxDB.Query(querySQL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -198,7 +198,7 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert back to VectorRow slice
|
// Convert back to VectorRow slice
|
||||||
var results []models.VectorRow
|
results := make([]models.VectorRow, 0, len(topResults))
|
||||||
for _, result := range topResults {
|
for _, result := range topResults {
|
||||||
result.vector.Distance = result.distance
|
result.vector.Distance = result.distance
|
||||||
results = append(results, result.vector)
|
results = append(results, result.vector)
|
||||||
@@ -209,11 +209,11 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
|
|||||||
|
|
||||||
// ListFiles returns a list of all loaded files
|
// ListFiles returns a list of all loaded files
|
||||||
func (vs *VectorStorage) ListFiles() ([]string, error) {
|
func (vs *VectorStorage) ListFiles() ([]string, error) {
|
||||||
var fileLists [][]string
|
fileLists := make([][]string, 0)
|
||||||
|
|
||||||
// Query both tables and combine results
|
// Query both tables and combine results
|
||||||
for _, table := range []string{"embeddings_384", "embeddings_5120"} {
|
for _, table := range []string{"embeddings_384", "embeddings_5120"} {
|
||||||
query := fmt.Sprintf("SELECT DISTINCT filename FROM %s", table)
|
query := "SELECT DISTINCT filename FROM " + table
|
||||||
rows, err := vs.sqlxDB.Query(query)
|
rows, err := vs.sqlxDB.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Continue if one table doesn't exist
|
// Continue if one table doesn't exist
|
||||||
|
|||||||
@@ -75,9 +75,7 @@ func (p ProviderSQL) WriteVector(row *models.VectorRow) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeUnsafe(bs []byte) []float32 {
|
|
||||||
return unsafe.Slice((*float32)(unsafe.Pointer(&bs[0])), len(bs)/4)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p ProviderSQL) SearchClosest(q []float32) ([]models.VectorRow, error) {
|
func (p ProviderSQL) SearchClosest(q []float32) ([]models.VectorRow, error) {
|
||||||
// TODO: This function has been temporarily disabled to avoid deprecated library usage.
|
// TODO: This function has been temporarily disabled to avoid deprecated library usage.
|
||||||
|
|||||||
47
tools.go
47
tools.go
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gf-lt/config"
|
|
||||||
"gf-lt/extra"
|
"gf-lt/extra"
|
||||||
"gf-lt/models"
|
"gf-lt/models"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -82,29 +81,29 @@ After that you are free to respond to the user.
|
|||||||
sysLabels = []string{"basic_sys", "tool_sys"}
|
sysLabels = []string{"basic_sys", "tool_sys"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func populateTools(cfg config.Config) {
|
// func populateTools(cfg config.Config) {
|
||||||
// if we have access to some server with funcs we can populate funcs (tools|toolbelt?) with it
|
// // if we have access to some server with funcs we can populate funcs (tools|toolbelt?) with it
|
||||||
// there must be a better way
|
// // there must be a better way
|
||||||
if cfg.SearchAPI == "" || cfg.SearchDescribe == "" {
|
// if cfg.SearchAPI == "" || cfg.SearchDescribe == "" {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
resp, err := httpClient.Get(cfg.SearchDescribe)
|
// resp, err := httpClient.Get(cfg.SearchDescribe)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
logger.Error("failed to get websearch tool description",
|
// logger.Error("failed to get websearch tool description",
|
||||||
"link", cfg.SearchDescribe, "error", err)
|
// "link", cfg.SearchDescribe, "error", err)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
descResp := models.Tool{}
|
// defer resp.Body.Close()
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&descResp); err != nil {
|
// descResp := models.Tool{}
|
||||||
logger.Error("failed to unmarshal websearch tool description",
|
// if err := json.NewDecoder(resp.Body).Decode(&descResp); err != nil {
|
||||||
"link", cfg.SearchDescribe, "error", err)
|
// logger.Error("failed to unmarshal websearch tool description",
|
||||||
return
|
// "link", cfg.SearchDescribe, "error", err)
|
||||||
}
|
// return
|
||||||
fnMap["web_search"] = websearch
|
// }
|
||||||
baseTools = append(baseTools, descResp)
|
// fnMap["web_search"] = websearch
|
||||||
logger.Info("added web_search tool", "tool", descResp)
|
// baseTools = append(baseTools, descResp)
|
||||||
return
|
// logger.Info("added web_search tool", "tool", descResp)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// {"type":"function","function":{"name":"web_search","description":"Perform a web search to find information on varioust topics","parameters":{"type":"object","properties":{"num_results":{"type":"integer","description":"Maximum number of results to return (default: 10)"},"query":{"type":"string","description":"The search query to find information about"},"search_type":{"type":"string","description":"Type of search to perform: 'api' for SearXNG API search or 'scraper' for web scraping (default: 'scraper')"}},"required":["query"]}}}
|
// {"type":"function","function":{"name":"web_search","description":"Perform a web search to find information on varioust topics","parameters":{"type":"object","properties":{"num_results":{"type":"integer","description":"Maximum number of results to return (default: 10)"},"query":{"type":"string","description":"The search query to find information about"},"search_type":{"type":"string","description":"Type of search to perform: 'api' for SearXNG API search or 'scraper' for web scraping (default: 'scraper')"}},"required":["query"]}}}
|
||||||
|
|
||||||
|
|||||||
2
tui.go
2
tui.go
@@ -950,7 +950,7 @@ func init() {
|
|||||||
persona = cfg.WriteNextMsgAs
|
persona = cfg.WriteNextMsgAs
|
||||||
}
|
}
|
||||||
// check if plain text
|
// check if plain text
|
||||||
if injectRole == false {
|
if !injectRole {
|
||||||
matches := roleRE.FindStringSubmatch(msgText)
|
matches := roleRE.FindStringSubmatch(msgText)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
persona = matches[1]
|
persona = matches[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user