Skip to content

Commit

Permalink
Merge pull request #640 from helixml/introduce-linter
Browse files Browse the repository at this point in the history
Introduce golangci linter
  • Loading branch information
milosgajdos authored Dec 14, 2024
2 parents b0bafca + 8111e98 commit a4720ed
Show file tree
Hide file tree
Showing 61 changed files with 209 additions and 913 deletions.
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
linters:
enable:
- staticcheck
- unconvert
- gofmt
- goimports
- ineffassign
- gosimple
- govet
- misspell
- unused
- bodyclose
- tparallel
#- errcheck
#- revive

issues:
deadline: 2m
exlude-dirs:
- vendor
4 changes: 0 additions & 4 deletions api/cmd/helix/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,15 @@ func runnerCLI(cmd *cobra.Command, options *RunnerOptions) error {
model.API_HOST = options.Runner.ApiHost
model.API_TOKEN = options.Runner.ApiToken

useWarmupSessions := []types.Session{}
if !options.Runner.MockRunner {
// Axolotl runtime warmup
if options.Runner.Config.Runtimes.Axolotl.Enabled {
for _, modelName := range options.Runner.Config.Runtimes.Axolotl.WarmupModels {
switch modelName {
case model.Model_Axolotl_Mistral7b:
log.Info().Msgf("Adding warmup session for model %s", modelName)
useWarmupSessions = append(useWarmupSessions, WarmupSession_Model_Mistral7b)
case model.Model_Cog_SDXL:
log.Info().Msgf("Adding warmup session for model %s", modelName)
useWarmupSessions = append(useWarmupSessions, WarmupSession_Model_SDXL)
default:
log.Error().Msgf("Unknown warmup model %s", modelName)
}
Expand All @@ -281,7 +278,6 @@ func runnerCLI(cmd *cobra.Command, options *RunnerOptions) error {
switch modelName {
case model.Model_Ollama_Llama3_8b:
log.Info().Msgf("Adding warmup session for model %s", modelName)
useWarmupSessions = append(useWarmupSessions, WarmupSession_Model_Ollama_Llama3_8b)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions api/cmd/helix/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/spf13/cobra"
)

// nolint:unused
func printStackTrace() {
// Allocate a buffer large enough to store the stack trace
buf := make([]byte, 1024)
Expand Down
98 changes: 49 additions & 49 deletions api/cmd/helix/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ const htmlTemplate = `
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Helix Test Results</title>
<style>
body, html {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
body, html {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
.main-container {
display: flex;
flex-direction: column;
height: 100vh;
}
.header {
padding: 10px 20px;
.header {
padding: 10px 20px;
background-color: #f8f8f8;
border-bottom: 1px solid #ddd;
display: flex;
Expand All @@ -122,64 +122,64 @@ const htmlTemplate = `
align-items: center;
gap: 10px;
}
.results-container {
.results-container {
flex: 1;
overflow-y: auto;
padding: 0 20px;
}
table {
border-collapse: collapse;
width: 100%;
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
th {
background-color: #f2f2f2;
position: sticky;
top: 0;
z-index: 10;
}
tr.pass { background-color: #e6ffe6; }
tr.fail { background-color: #ffe6e6; }
#iframe-container {
display: none;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 70%;
border: none;
#iframe-container {
display: none;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 70%;
border: none;
}
#iframe-container iframe {
width: 100%;
height: calc(100% - 10px);
border: none;
#iframe-container iframe {
width: 100%;
height: calc(100% - 10px);
border: none;
}
#close-iframe {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
#close-iframe {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
}
#resize-handle {
width: 100%;
height: 10px;
background: #f0f0f0;
cursor: ns-resize;
border-top: 1px solid #ccc;
#resize-handle {
width: 100%;
height: 10px;
background: #f0f0f0;
cursor: ns-resize;
border-top: 1px solid #ccc;
}
#view-helix-yaml {
#view-helix-yaml {
padding: 5px 10px;
font-size: 0.9em;
}
.truncate {
max-width: 400px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.truncate {
max-width: 400px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
position: relative;
cursor: pointer;
}
Expand Down Expand Up @@ -462,7 +462,6 @@ func getHelixURL() string {
}

func runTests(appConfig types.AppHelixConfig, appID, apiKey, helixURL, evaluationModel string) ([]TestResult, time.Duration, error) {
var results []TestResult
totalStartTime := time.Now()

resultsChan := make(chan TestResult)
Expand Down Expand Up @@ -503,6 +502,7 @@ func runTests(appConfig types.AppHelixConfig, appID, apiKey, helixURL, evaluatio
close(resultsChan)
}()

var results []TestResult
for result := range resultsChan {
results = append(results, result)
}
Expand Down Expand Up @@ -932,7 +932,7 @@ func getAvailableModels(apiKey, helixURL string) ([]string, error) {
}

// Extract model IDs from the response
var models []string
models := make([]string, 0, len(modelResp.Data))
for _, model := range modelResp.Data {
models = append(models, model.ID)
}
Expand Down
2 changes: 2 additions & 0 deletions api/cmd/helix/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func getDefaultServeOptionInt(envName string, defaultValue int) int {
return defaultValue
}

// nolint:unused
func getDefaultServeOptionFloat(envName string, defaultValue float32) float32 {
envValue := os.Getenv(envName)
if envValue != "" {
Expand All @@ -58,6 +59,7 @@ func getDefaultServeOptionFloat(envName string, defaultValue float32) float32 {
return defaultValue
}

// nolint:unused
// comma separated strings
func getDefaultServeOptionStringArray(envName string, defaultValue []string) []string {
envValue, ok := os.LookupEnv(envName)
Expand Down
5 changes: 0 additions & 5 deletions api/pkg/cli/app/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ func NewApplyCmd() *cobra.Command {
return applyCmd
}

type applyOptions struct {
filename string
refreshKnowledge bool
}

// applyCmd represents the apply command
var applyCmd = &cobra.Command{
Use: "apply",
Expand Down
23 changes: 5 additions & 18 deletions api/pkg/controller/dataprep.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"errors"
"fmt"
"io"
"path"
Expand All @@ -20,19 +21,6 @@ import (
"github.com/rs/zerolog/log"
)

type convertDocumentsToChunksRequest struct {
URL string `json:"url"`
}

type convertDocumentsToChunksResponse struct {
Text string `json:"text"`
}

type convertTextItem struct {
Name string `json:"name"`
Content string `json:"content"`
}

func (c *Controller) getDocumentsToConvertToText(session *types.Session) ([]string, error) {
userInteraction, err := data.GetUserInteraction(session.Interactions)
if err != nil {
Expand Down Expand Up @@ -69,10 +57,9 @@ func (c *Controller) getDocumentsToConvertToText(session *types.Session) ([]stri
// }

// check if we have already got the chunks for this file
_, ok := existingFileNames[fmt.Sprintf("%s.txt", filename)]
if ok {
if _, ok := existingFileNames[fmt.Sprintf("%s.txt", filename)]; ok {
// we've already chunked this file into chunks
return false
return !ok
}

// check if we have already got the chunks for this file
Expand Down Expand Up @@ -536,7 +523,7 @@ func (c *Controller) convertChunksToQuestions(session *types.Session) (*types.Se
session = c.WriteInteraction(session, assistantInteraction)
c.BroadcastProgress(session, 1, initialMessage)

return session, 0, fmt.Errorf(msg)
return session, 0, errors.New(msg)
}

// Get the progress bar to display
Expand Down Expand Up @@ -571,7 +558,7 @@ func (c *Controller) convertChunksToQuestions(session *types.Session) (*types.Se
session = c.WriteInteraction(session, assistantInteraction)
c.BroadcastProgress(session, 1, initialMessage)

return session, 0, fmt.Errorf(msg)
return session, 0, errors.New(msg)
}

// Get the progress bar to display
Expand Down
5 changes: 0 additions & 5 deletions api/pkg/controller/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"github.com/helixml/helix/api/pkg/types"
)

type userPathTemplateData struct {
Owner string
OwnerType types.OwnerType
}

//go:embed filestore_folders.json
var jsonFile embed.FS

Expand Down
2 changes: 1 addition & 1 deletion api/pkg/controller/inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func (c *Controller) evaluateRAG(ctx context.Context, user *types.User, req open
return nil, fmt.Errorf("error querying RAG: %w", err)
}

var ragContent []*prompts.RagContent
ragContent := make([]*prompts.RagContent, 0, len(ragResults))
for _, result := range ragResults {
ragContent = append(ragContent, &prompts.RagContent{
DocumentID: result.DocumentID,
Expand Down
3 changes: 0 additions & 3 deletions api/pkg/controller/knowledge/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"net/url"
"strings"
"time"

"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
Expand Down Expand Up @@ -126,8 +125,6 @@ func (b *Browser) getBrowser() (*rod.Browser, error) {
return browser, nil
}

var pageLoadTimeout = 5 * time.Second

func (b *Browser) GetPage(browser *rod.Browser, opts proto.TargetCreateTarget) (*rod.Page, error) {
create := func() (*rod.Page, error) {
// Open a blank page on first create
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/controller/knowledge/crawler/firecrawl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (f *Firecrawl) Crawl(ctx context.Context) ([]*types.CrawledDocument, error)
Int("num_docs", len(docs)).
Msg("crawling completed")

var crawledDocs []*types.CrawledDocument
crawledDocs := make([]*types.CrawledDocument, 0, len(docs))
for _, doc := range docs {
crawledDocs = append(crawledDocs, &types.CrawledDocument{
ID: doc.ID,
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/controller/knowledge/knowledge_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *Reconciler) extractDataFromWebWithCrawler(ctx context.Context, k *types
return nil, fmt.Errorf("failed to crawl: %w", err)
}

var data []*indexerData
data := make([]*indexerData, 0, len(result))

for _, doc := range result {
data = append(data, &indexerData{
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/controller/knowledge/knowledge_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func convertChunksIntoBatches(chunks []*text.DataPrepTextSplitterChunk, batchSiz

func convertTextSplitterChunks(k *types.Knowledge, version string, chunks []*text.DataPrepTextSplitterChunk) []*types.SessionRAGIndexChunk {

var indexChunks []*types.SessionRAGIndexChunk
indexChunks := make([]*types.SessionRAGIndexChunk, 0, len(chunks))

for _, chunk := range chunks {
indexChunks = append(indexChunks, &types.SessionRAGIndexChunk{
Expand Down
1 change: 0 additions & 1 deletion api/pkg/controller/knowledge/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (q *Query) getDocuments(ctx context.Context, prompt string, knowledges []*t
// listKnowledge retrieves all knowledge for an assistant to query documents for
func (q *Query) listKnowledge(ctx context.Context, appID string, assistant *types.AssistantConfig) ([]*types.Knowledge, error) {
var knowledge []*types.Knowledge

for _, k := range assistant.Knowledge {

k, err := q.store.LookupKnowledge(ctx, &store.LookupKnowledgeQuery{
Expand Down
12 changes: 5 additions & 7 deletions api/pkg/controller/knowledge/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/helixml/helix/api/pkg/config"
"github.com/helixml/helix/api/pkg/openai"
oai "github.com/helixml/helix/api/pkg/openai"
"github.com/helixml/helix/api/pkg/rag"
"github.com/helixml/helix/api/pkg/store"
"github.com/helixml/helix/api/pkg/types"
Expand All @@ -20,12 +19,11 @@ import (

type QuerySuite struct {
suite.Suite
ctrl *gomock.Controller
ctx context.Context
store *store.MockStore
rag rag.RAG
openAiClient *oai.MockClient
query *Query
ctrl *gomock.Controller
ctx context.Context
store *store.MockStore
rag rag.RAG
query *Query
}

func TestQuerySuite(t *testing.T) {
Expand Down
Loading

0 comments on commit a4720ed

Please sign in to comment.