A page for anyone in a project, built for the one who knows least: an Excel, CSV or JSONL file of questions and answers, previewed; a model; a name; who may use it; and a button. The weights to train on are found from where the model's came (a GGUF repository's base model), the card's memory from their size, the node as the one with the most free. When it is done the adapter is published by itself (a llama.cpp model's replicas replaced to load it) and is a model of its own in the chat and the API. The project's by default; its members share it wider (confirmed, and never wider than the knowledge bases its pairs came from) or delete it. One trains at a time per project. ctl train start needs only --model and --data now, and --publish publishes when done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package train
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestPairsFromATableByItsHeaderOrItsFirstColumns(t *testing.T) {
|
||
for _, c := range []struct {
|
||
name, file string
|
||
want []Pair
|
||
skipped int
|
||
cols [2]string
|
||
}{
|
||
{"headed.csv", "No;Cevap;Soru\n1;Yirmi gün.;İzin kaç gün?\n2;;Boş cevap\n3;Evet;Uzaktan çalışabilir miyim?\n",
|
||
[]Pair{{"İzin kaç gün?", "Yirmi gün."}, {"Uzaktan çalışabilir miyim?", "Evet"}}, 1, [2]string{"Soru", "Cevap"}},
|
||
{"plain.csv", "\ufeffİzin kaç gün?,\"Yirmi gün, yılda.\"\n\nMasraf?,Formla.\n",
|
||
[]Pair{{"İzin kaç gün?", "Yirmi gün, yılda."}, {"Masraf?", "Formla."}}, 0, [2]string{}},
|
||
{"tabs.tsv", "Question\tAnswer\nA?\tB.\n", []Pair{{"A?", "B."}}, 0, [2]string{"Question", "Answer"}},
|
||
{"d.jsonl", `{"q":"A?","a":"B."}` + "\n" + `{"question":"C?","answer":"D."}` + "\n" + `{"q":"E?"}` + "\n",
|
||
[]Pair{{"A?", "B."}, {"C?", "D."}}, 1, [2]string{}},
|
||
} {
|
||
got, err := ReadPairs(c.name, []byte(c.file))
|
||
if err != nil {
|
||
t.Errorf("%s: %v", c.name, err)
|
||
continue
|
||
}
|
||
if len(got.Pairs) != len(c.want) || got.Skipped != c.skipped || got.Columns != c.cols {
|
||
t.Errorf("%s: %+v", c.name, got)
|
||
continue
|
||
}
|
||
for i := range c.want {
|
||
if got.Pairs[i] != c.want[i] {
|
||
t.Errorf("%s: pair %d = %+v, want %+v", c.name, i, got.Pairs[i], c.want[i])
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestPairsRefusedWithAReason(t *testing.T) {
|
||
for name, file := range map[string]string{
|
||
"a.csv": "only one column\n",
|
||
"a.xls": "x",
|
||
"a.pdf": "x",
|
||
"a.json": "not json\n",
|
||
} {
|
||
if _, err := ReadPairs(name, []byte(file)); err == nil {
|
||
t.Errorf("%s read", name)
|
||
}
|
||
}
|
||
var b strings.Builder
|
||
for range MaxPairs + 1 {
|
||
b.WriteString("x,y\n")
|
||
}
|
||
if _, err := ReadPairs("big.csv", []byte(b.String())); err == nil || !strings.Contains(err.Error(), "more than") {
|
||
t.Errorf("too many: %v", err)
|
||
}
|
||
}
|
||
|
||
func TestNDJSONIsWhatAJobReads(t *testing.T) {
|
||
got := NDJSON([]Pair{{"<b>?", "a & b"}})
|
||
if got != `{"q":"<b>?","a":"a & b"}`+"\n" {
|
||
t.Errorf("%q", got)
|
||
}
|
||
}
|