Chore: fix linter complaints
This commit is contained in:
@@ -3,6 +3,7 @@ package rag
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gf-lt/config"
|
||||
"log/slog"
|
||||
@@ -69,7 +70,7 @@ func (a *APIEmbedder) Embed(text []string) ([][]float32, error) {
|
||||
}
|
||||
|
||||
if len(emb) == 0 {
|
||||
err = fmt.Errorf("empty embedding response")
|
||||
err = errors.New("empty embedding response")
|
||||
a.logger.Error("empty embedding response")
|
||||
return nil, err
|
||||
}
|
||||
@@ -83,7 +84,7 @@ func (a *APIEmbedder) EmbedSingle(text string) ([]float32, error) {
|
||||
return nil, err
|
||||
}
|
||||
if len(result) == 0 {
|
||||
return nil, fmt.Errorf("no embeddings returned")
|
||||
return nil, errors.New("no embeddings returned")
|
||||
}
|
||||
return result[0], nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package rag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gf-lt/config"
|
||||
"gf-lt/models"
|
||||
@@ -108,7 +109,7 @@ func (r *RAG) LoadRAG(fpath string) error {
|
||||
}
|
||||
|
||||
if len(paragraphs) == 0 {
|
||||
return fmt.Errorf("no valid paragraphs found in file")
|
||||
return errors.New("no valid paragraphs found in file")
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -222,7 +223,7 @@ func (r *RAG) fetchEmb(lines []string, errCh chan error, vectorCh chan<- []model
|
||||
}
|
||||
|
||||
if len(embeddings) == 0 {
|
||||
err := fmt.Errorf("no embeddings returned")
|
||||
err := errors.New("no embeddings returned")
|
||||
r.logger.Error("empty embeddings")
|
||||
errCh <- 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
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -198,7 +198,7 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
|
||||
}
|
||||
|
||||
// Convert back to VectorRow slice
|
||||
var results []models.VectorRow
|
||||
results := make([]models.VectorRow, 0, len(topResults))
|
||||
for _, result := range topResults {
|
||||
result.vector.Distance = result.distance
|
||||
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
|
||||
func (vs *VectorStorage) ListFiles() ([]string, error) {
|
||||
var fileLists [][]string
|
||||
fileLists := make([][]string, 0)
|
||||
|
||||
// Query both tables and combine results
|
||||
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)
|
||||
if err != nil {
|
||||
// Continue if one table doesn't exist
|
||||
|
||||
@@ -75,9 +75,7 @@ func (p ProviderSQL) WriteVector(row *models.VectorRow) error {
|
||||
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) {
|
||||
// TODO: This function has been temporarily disabled to avoid deprecated library usage.
|
||||
|
||||
47
tools.go
47
tools.go
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gf-lt/config"
|
||||
"gf-lt/extra"
|
||||
"gf-lt/models"
|
||||
"regexp"
|
||||
@@ -82,29 +81,29 @@ After that you are free to respond to the user.
|
||||
sysLabels = []string{"basic_sys", "tool_sys"}
|
||||
)
|
||||
|
||||
func populateTools(cfg config.Config) {
|
||||
// if we have access to some server with funcs we can populate funcs (tools|toolbelt?) with it
|
||||
// there must be a better way
|
||||
if cfg.SearchAPI == "" || cfg.SearchDescribe == "" {
|
||||
return
|
||||
}
|
||||
resp, err := httpClient.Get(cfg.SearchDescribe)
|
||||
if err != nil {
|
||||
logger.Error("failed to get websearch tool description",
|
||||
"link", cfg.SearchDescribe, "error", err)
|
||||
return
|
||||
}
|
||||
descResp := models.Tool{}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&descResp); err != nil {
|
||||
logger.Error("failed to unmarshal websearch tool description",
|
||||
"link", cfg.SearchDescribe, "error", err)
|
||||
return
|
||||
}
|
||||
fnMap["web_search"] = websearch
|
||||
baseTools = append(baseTools, descResp)
|
||||
logger.Info("added web_search tool", "tool", descResp)
|
||||
return
|
||||
}
|
||||
// func populateTools(cfg config.Config) {
|
||||
// // if we have access to some server with funcs we can populate funcs (tools|toolbelt?) with it
|
||||
// // there must be a better way
|
||||
// if cfg.SearchAPI == "" || cfg.SearchDescribe == "" {
|
||||
// return
|
||||
// }
|
||||
// resp, err := httpClient.Get(cfg.SearchDescribe)
|
||||
// if err != nil {
|
||||
// logger.Error("failed to get websearch tool description",
|
||||
// "link", cfg.SearchDescribe, "error", err)
|
||||
// return
|
||||
// }
|
||||
// defer resp.Body.Close()
|
||||
// descResp := models.Tool{}
|
||||
// if err := json.NewDecoder(resp.Body).Decode(&descResp); err != nil {
|
||||
// logger.Error("failed to unmarshal websearch tool description",
|
||||
// "link", cfg.SearchDescribe, "error", err)
|
||||
// return
|
||||
// }
|
||||
// fnMap["web_search"] = websearch
|
||||
// baseTools = append(baseTools, descResp)
|
||||
// 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"]}}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user