Skip to content

Commit 34b8562

Browse files
committed
refactoring and consolidation
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent dba884e commit 34b8562

194 files changed

Lines changed: 243605 additions & 242835 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/gallery-agent/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func getHuggingFaceAvatarURL(author string) string {
406406
}
407407

408408
// Parse the response to get avatar URL
409-
var userInfo map[string]interface{}
409+
var userInfo map[string]any
410410
body, err := io.ReadAll(resp.Body)
411411
if err != nil {
412412
return ""

.github/gallery-agent/testing.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"math/rand"
6+
"math/rand/v2"
77
"strings"
88
"time"
99
)
@@ -13,11 +13,11 @@ func runSyntheticMode() error {
1313
generator := NewSyntheticDataGenerator()
1414

1515
// Generate a random number of synthetic models (1-3)
16-
numModels := generator.rand.Intn(3) + 1
16+
numModels := generator.rand.IntN(3) + 1
1717
fmt.Printf("Generating %d synthetic models for testing...\n", numModels)
1818

1919
var models []ProcessedModel
20-
for i := 0; i < numModels; i++ {
20+
for i := range numModels {
2121
model := generator.GenerateProcessedModel()
2222
models = append(models, model)
2323
fmt.Printf("Generated synthetic model: %s\n", model.ModelID)
@@ -42,14 +42,14 @@ type SyntheticDataGenerator struct {
4242
// NewSyntheticDataGenerator creates a new synthetic data generator
4343
func NewSyntheticDataGenerator() *SyntheticDataGenerator {
4444
return &SyntheticDataGenerator{
45-
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
45+
rand: rand.New(rand.NewPCG(uint64(time.Now().UnixNano()), 0)),
4646
}
4747
}
4848

4949
// GenerateProcessedModelFile creates a synthetic ProcessedModelFile
5050
func (g *SyntheticDataGenerator) GenerateProcessedModelFile() ProcessedModelFile {
5151
fileTypes := []string{"model", "readme", "other"}
52-
fileType := fileTypes[g.rand.Intn(len(fileTypes))]
52+
fileType := fileTypes[g.rand.IntN(len(fileTypes))]
5353

5454
var path string
5555
var isReadme bool
@@ -68,7 +68,7 @@ func (g *SyntheticDataGenerator) GenerateProcessedModelFile() ProcessedModelFile
6868

6969
return ProcessedModelFile{
7070
Path: path,
71-
Size: int64(g.rand.Intn(1000000000) + 1000000), // 1MB to 1GB
71+
Size: int64(g.rand.IntN(1000000000) + 1000000), // 1MB to 1GB
7272
SHA256: g.randomSHA256(),
7373
IsReadme: isReadme,
7474
FileType: fileType,
@@ -80,19 +80,19 @@ func (g *SyntheticDataGenerator) GenerateProcessedModel() ProcessedModel {
8080
authors := []string{"microsoft", "meta", "google", "openai", "anthropic", "mistralai", "huggingface"}
8181
modelNames := []string{"llama", "gpt", "claude", "mistral", "gemma", "phi", "qwen", "codellama"}
8282

83-
author := authors[g.rand.Intn(len(authors))]
84-
modelName := modelNames[g.rand.Intn(len(modelNames))]
83+
author := authors[g.rand.IntN(len(authors))]
84+
modelName := modelNames[g.rand.IntN(len(modelNames))]
8585
modelID := fmt.Sprintf("%s/%s-%s", author, modelName, g.randomString(6))
8686

8787
// Generate files
88-
numFiles := g.rand.Intn(5) + 2 // 2-6 files
88+
numFiles := g.rand.IntN(5) + 2 // 2-6 files
8989
files := make([]ProcessedModelFile, numFiles)
9090

9191
// Ensure at least one model file and one readme
9292
hasModelFile := false
9393
hasReadme := false
9494

95-
for i := 0; i < numFiles; i++ {
95+
for i := range numFiles {
9696
files[i] = g.GenerateProcessedModelFile()
9797
if files[i].FileType == "model" {
9898
hasModelFile = true
@@ -140,27 +140,27 @@ func (g *SyntheticDataGenerator) GenerateProcessedModel() ProcessedModel {
140140

141141
// Generate sample metadata
142142
licenses := []string{"apache-2.0", "mit", "llama2", "gpl-3.0", "bsd", ""}
143-
license := licenses[g.rand.Intn(len(licenses))]
143+
license := licenses[g.rand.IntN(len(licenses))]
144144

145145
sampleTags := []string{"llm", "gguf", "gpu", "cpu", "text-to-text", "chat", "instruction-tuned"}
146-
numTags := g.rand.Intn(4) + 3 // 3-6 tags
146+
numTags := g.rand.IntN(4) + 3 // 3-6 tags
147147
tags := make([]string, numTags)
148-
for i := 0; i < numTags; i++ {
149-
tags[i] = sampleTags[g.rand.Intn(len(sampleTags))]
148+
for i := range numTags {
149+
tags[i] = sampleTags[g.rand.IntN(len(sampleTags))]
150150
}
151151
// Remove duplicates
152152
tags = g.removeDuplicates(tags)
153153

154154
// Optionally include icon (50% chance)
155155
icon := ""
156-
if g.rand.Intn(2) == 0 {
156+
if g.rand.IntN(2) == 0 {
157157
icon = fmt.Sprintf("https://cdn-avatars.huggingface.co/v1/production/uploads/%s.png", g.randomString(24))
158158
}
159159

160160
return ProcessedModel{
161161
ModelID: modelID,
162162
Author: author,
163-
Downloads: g.rand.Intn(1000000) + 1000,
163+
Downloads: g.rand.IntN(1000000) + 1000,
164164
LastModified: g.randomDate(),
165165
Files: files,
166166
PreferredModelFile: preferredModelFile,
@@ -180,7 +180,7 @@ func (g *SyntheticDataGenerator) randomString(length int) string {
180180
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
181181
b := make([]byte, length)
182182
for i := range b {
183-
b[i] = charset[g.rand.Intn(len(charset))]
183+
b[i] = charset[g.rand.IntN(len(charset))]
184184
}
185185
return string(b)
186186
}
@@ -189,14 +189,14 @@ func (g *SyntheticDataGenerator) randomSHA256() string {
189189
const charset = "0123456789abcdef"
190190
b := make([]byte, 64)
191191
for i := range b {
192-
b[i] = charset[g.rand.Intn(len(charset))]
192+
b[i] = charset[g.rand.IntN(len(charset))]
193193
}
194194
return string(b)
195195
}
196196

197197
func (g *SyntheticDataGenerator) randomDate() string {
198198
now := time.Now()
199-
daysAgo := g.rand.Intn(365) // Random date within last year
199+
daysAgo := g.rand.IntN(365) // Random date within last year
200200
pastDate := now.AddDate(0, 0, -daysAgo)
201201
return pastDate.Format("2006-01-02T15:04:05.000Z")
202202
}
@@ -220,5 +220,5 @@ func (g *SyntheticDataGenerator) generateReadmeContent(modelName, author string)
220220
fmt.Sprintf("# %s Language Model\n\nDeveloped by %s, this model represents state-of-the-art performance in natural language understanding and generation.\n\n## Key Features\n\n- Multilingual support\n- Context-aware responses\n- Efficient memory usage\n- Fast inference speed\n\n## Applications\n\n- Chatbots and virtual assistants\n- Content generation\n- Code completion\n- Educational tools", strings.Title(modelName), author),
221221
}
222222

223-
return templates[g.rand.Intn(len(templates))]
223+
return templates[g.rand.IntN(len(templates))]
224224
}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
go-version: ['1.25.x']
24+
go-version: ['1.26.x']
2525
steps:
2626
- name: Free Disk Space (Ubuntu)
2727
uses: jlumbroso/free-disk-space@main
@@ -179,7 +179,7 @@ jobs:
179179
runs-on: macos-latest
180180
strategy:
181181
matrix:
182-
go-version: ['1.25.x']
182+
go-version: ['1.26.x']
183183
steps:
184184
- name: Clone
185185
uses: actions/checkout@v6

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ ENV PATH=/opt/rocm/bin:${PATH}
176176
# The requirements-core target is common to all images. It should not be placed in requirements-core unless every single build will use it.
177177
FROM requirements-drivers AS build-requirements
178178

179-
ARG GO_VERSION=1.25.4
179+
ARG GO_VERSION=1.26.0
180180
ARG CMAKE_VERSION=3.31.10
181181
ARG CMAKE_FROM_SOURCE=false
182182
ARG TARGETARCH

backend/go/acestep-cpp/acestepcpp_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ func TestLoadModel(t *testing.T) {
106106
defer conn.Close()
107107

108108
client := pb.NewBackendClient(conn)
109-
109+
110110
// Get base directory from main model file for relative paths
111111
mainModelPath := filepath.Join(modelDir, "acestep-5Hz-lm-0.6B-Q8_0.gguf")
112-
112+
113113
resp, err := client.LoadModel(context.Background(), &pb.ModelOptions{
114114
ModelFile: mainModelPath,
115115
ModelPath: modelDir,
@@ -134,7 +134,7 @@ func TestSoundGeneration(t *testing.T) {
134134
if err != nil {
135135
t.Fatal(err)
136136
}
137-
defer os.RemoveAll(tmpDir)
137+
t.Cleanup(func() { os.RemoveAll(tmpDir) })
138138

139139
outputFile := filepath.Join(tmpDir, "output.wav")
140140

backend/go/acestep-cpp/goacestepcpp.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
var (
14-
CppLoadModel func(lmModelPath, textEncoderPath, ditModelPath, vaeModelPath string) int
14+
CppLoadModel func(lmModelPath, textEncoderPath, ditModelPath, vaeModelPath string) int
1515
CppGenerateMusic func(caption, lyrics string, bpm int, keyscale, timesignature string, duration, temperature float32, instrumental bool, seed int, dst string, threads int) int
1616
)
1717

@@ -29,18 +29,18 @@ func (a *AceStepCpp) Load(opts *pb.ModelOptions) error {
2929
var textEncoderModel, ditModel, vaeModel string
3030

3131
for _, oo := range opts.Options {
32-
parts := strings.SplitN(oo, ":", 2)
33-
if len(parts) != 2 {
32+
key, value, found := strings.Cut(oo, ":")
33+
if !found {
3434
fmt.Fprintf(os.Stderr, "Unrecognized option: %v\n", oo)
3535
continue
3636
}
37-
switch parts[0] {
37+
switch key {
3838
case "text_encoder_model":
39-
textEncoderModel = parts[1]
39+
textEncoderModel = value
4040
case "dit_model":
41-
ditModel = parts[1]
41+
ditModel = value
4242
case "vae_model":
43-
vaeModel = parts[1]
43+
vaeModel = value
4444
default:
4545
fmt.Fprintf(os.Stderr, "Unrecognized option: %v\n", oo)
4646
}

backend/go/llm/llama/llama.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type LLM struct {
1818
draftModel *llama.LLama
1919
}
2020

21-
2221
// Free releases GPU resources and frees the llama model
2322
// This should be called when the model is being unloaded to properly release VRAM
2423
func (llm *LLM) Free() error {

backend/go/local-store/debug.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build debug
2-
// +build debug
32

43
package main
54

backend/go/local-store/production.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !debug
2-
// +build !debug
32

43
package main
54

backend/go/local-store/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func normalizedCosineSimilarity(k1, k2 []float32) float32 {
332332
assert(len(k1) == len(k2), fmt.Sprintf("normalizedCosineSimilarity: len(k1) = %d, len(k2) = %d", len(k1), len(k2)))
333333

334334
var dot float32
335-
for i := 0; i < len(k1); i++ {
335+
for i := range len(k1) {
336336
dot += k1[i] * k2[i]
337337
}
338338

@@ -419,7 +419,7 @@ func cosineSimilarity(k1, k2 []float32, mag1 float64) float32 {
419419
assert(len(k1) == len(k2), fmt.Sprintf("cosineSimilarity: len(k1) = %d, len(k2) = %d", len(k1), len(k2)))
420420

421421
var dot, mag2 float64
422-
for i := 0; i < len(k1); i++ {
422+
for i := range len(k1) {
423423
dot += float64(k1[i] * k2[i])
424424
mag2 += float64(k2[i] * k2[i])
425425
}

0 commit comments

Comments
 (0)