Skip to content

Commit

Permalink
lint: fixup lint settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tmc committed Sep 13, 2024
1 parent 2124f7f commit 0929c6d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 38 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
name: ci

# GitHub Actions CI workflow for Go project
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
# Cache is managed by golangci-lint
# https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs
cache: false
- name: golangci-lint
uses: golangci/[email protected]
go-version-file: go.mod
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=4m
version: v1.59.1
version: v1.60
args: --timeout=5m
build-examples:
name: Build Examples
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
cache: false
- uses: actions/checkout@v3
- name: Build examples
run: make build-examples
build-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: actions/checkout@v3
- name: Build
run: go build -v ./...
- name: Test
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GENAI_API_KEY: ${{ secrets.GENAI_API_KEY }}
run: go test -v ./...

1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- test
- unused
disable:
- gci # We don't use gci.
- godox # We allow TODO lines.
- tagliatelle # As we're dealing with third parties we must accept snake case.
- wsl # We don't agree with wsl's style rules
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lint-all:
lint-deps:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo >&2 "golangci-lint not found. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.1; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0; \
}

.PHONY: docs
Expand Down
3 changes: 1 addition & 2 deletions documentloaders/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func (c CSV) Load(_ context.Context) ([]schema.Document, error) {

var content []string
for i, value := range row {
if c.columns != nil &&
len(c.columns) > 0 &&
if len(c.columns) > 0 &&
!slices.Contains(c.columns, header[i]) {
continue
}
Expand Down
41 changes: 28 additions & 13 deletions llms/llamafile/llamafilellm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package llamafile
import (
"context"
"errors"
"math"

"github.com/tmc/langchaingo/callbacks"
"github.com/tmc/langchaingo/llms"
Expand Down Expand Up @@ -167,19 +168,33 @@ func makeLlamaOptionsFromOptions(input *llamafileclient.ChatRequest, opts llms.C
// Initialize llamaOptions with values from opts
streamValue := opts.StreamingFunc != nil

input.FrequencyPenalty = opts.FrequencyPenalty // Assuming FrequencyPenalty correlates to FrequencyPenalty; adjust if necessary
input.MinP = float64(opts.MinLength) // Assuming there's a direct correlation; adjust if necessary
input.Model = opts.Model // Assuming Model correlates to Model; adjust if necessary
input.NCtx = opts.N // Assuming N corresponds to NCtx; if not, adjust.
input.NPredict = opts.MaxTokens // Assuming MaxTokens correlates to NPredict;
input.PresencePenalty = opts.PresencePenalty // Assuming PresencePenalty correlates to PresencePenalty;
input.RepeatPenalty = opts.RepetitionPenalty // Assuming RepetitionPenalty correlates to RepeatPenalty;
input.Seed = uint32(opts.Seed) // Convert int to uint32
input.Stop = opts.StopWords // Assuming StopWords correlates to Stop;
input.Stream = &streamValue // True if StreamingFunc provided; adjust logic as needed.
input.Temperature = opts.Temperature // Assuming Temperature correlates to Temperature for precision;
input.TopK = opts.TopK // Assuming TopK correlates to TopK;
input.TopP = opts.TopP // Assuming TopP correlates to TopP;
input.FrequencyPenalty = opts.FrequencyPenalty // Assuming FrequencyPenalty correlates to FrequencyPenalty; adjust if necessary
input.MinP = float64(opts.MinLength) // Assuming there's a direct correlation; adjust if necessary
input.Model = opts.Model // Assuming Model correlates to Model; adjust if necessary
input.NCtx = opts.N // Assuming N corresponds to NCtx; if not, adjust.
input.NPredict = opts.MaxTokens // Assuming MaxTokens correlates to NPredict;
input.PresencePenalty = opts.PresencePenalty // Assuming PresencePenalty correlates to PresencePenalty;
input.RepeatPenalty = opts.RepetitionPenalty // Assuming RepetitionPenalty correlates to RepeatPenalty;
input.Seed = uint32(max(0, min(opts.Seed, math.MaxUint32))) // Convert int to uint32
input.Stop = opts.StopWords // Assuming StopWords correlates to Stop;
input.Stream = &streamValue // True if StreamingFunc provided; adjust logic as needed.
input.Temperature = opts.Temperature // Assuming Temperature correlates to Temperature for precision;
input.TopK = opts.TopK // Assuming TopK correlates to TopK;
input.TopP = opts.TopP // Assuming TopP correlates to TopP;

return input
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
13 changes: 10 additions & 3 deletions llms/watsonx/watsonxllm.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ func toWatsonxOptions(options *[]llms.CallOption) []wx.GenerateOption {
o = append(o, wx.WithTopP(opts.TopP))
}
if opts.TopK != -1 {
o = append(o, wx.WithTopK(uint(opts.TopK)))
o = append(o, wx.WithTopK(uint(max(0, opts.TopK))))
}
if opts.Temperature != -1 {
o = append(o, wx.WithTemperature(opts.Temperature))
}
if opts.Seed != -1 {
o = append(o, wx.WithRandomSeed(uint(opts.Seed)))
o = append(o, wx.WithRandomSeed(uint(max(0, opts.Seed))))
}
if opts.RepetitionPenalty != -1 {
o = append(o, wx.WithRepetitionPenalty(opts.RepetitionPenalty))
}
if opts.MaxTokens != -1 {
o = append(o, wx.WithMaxNewTokens(uint(opts.MaxTokens)))
o = append(o, wx.WithMaxNewTokens(uint(max(0, opts.MaxTokens))))
}
if len(opts.StopWords) > 0 {
o = append(o, wx.WithStopSequences(opts.StopWords))
Expand All @@ -143,3 +143,10 @@ func toWatsonxOptions(options *[]llms.CallOption) []wx.GenerateOption {

return o
}

func max(a, b int) int {
if a > b {
return a
}
return b
}
2 changes: 1 addition & 1 deletion memory/sqlite3/sqlite3_history_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func WithDB(db *sql.DB) SqliteChatMessageHistoryOption {
// to use a context internally when running Schema.
func WithContext(ctx context.Context) SqliteChatMessageHistoryOption {
return func(m *SqliteChatMessageHistory) {
m.Ctx = ctx
m.Ctx = ctx //nolint:fatcontext
}
}

Expand Down
17 changes: 16 additions & 1 deletion vectorstores/chroma/chroma.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"

chromago "github.com/amikos-tech/chroma-go"
"github.com/amikos-tech/chroma-go/openai"
Expand Down Expand Up @@ -139,7 +140,7 @@ func (s Store) SimilaritySearch(ctx context.Context, query string, numDocuments
}

filter := s.getNamespacedFilter(opts)
qr, queryErr := s.collection.Query(ctx, []string{query}, int32(numDocuments), filter, nil, s.includes)
qr, queryErr := s.collection.Query(ctx, []string{query}, int32(max(0, min(numDocuments, math.MaxInt32))), filter, nil, s.includes)
if queryErr != nil {
return nil, queryErr
}
Expand Down Expand Up @@ -212,3 +213,17 @@ func (s Store) getNamespacedFilter(opts vectorstores.Options) map[string]any {

return map[string]any{"$and": []map[string]any{nameSpaceFilter, filter}}
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
17 changes: 16 additions & 1 deletion vectorstores/pinecone/pinecone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"math"

"github.com/google/uuid"
"github.com/pinecone-io/go-pinecone/pinecone"
Expand Down Expand Up @@ -159,7 +160,7 @@ func (s Store) SimilaritySearch(ctx context.Context, query string, numDocuments
&ctx,
&pinecone.QueryByVectorValuesRequest{
Vector: vector,
TopK: uint32(numDocuments),
TopK: uint32(max(0, min(numDocuments, math.MaxUint32))),
Filter: protoFilterStruct,
IncludeMetadata: true,
IncludeValues: true,
Expand Down Expand Up @@ -245,3 +246,17 @@ func (s Store) createProtoStructFilter(filter any) (*structpb.Struct, error) {

return &filterStruct, nil
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

0 comments on commit 0929c6d

Please sign in to comment.