added tiny test files to use in examples for creating models from file.
This commit is contained in:
parent
f98f113b75
commit
2d2b212e3d
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -262,18 +261,6 @@ func ExampleClient_Chat() {
|
|||||||
// Get the first model in the list
|
// Get the first model in the list
|
||||||
model := tags.Models[0].Model
|
model := tags.Models[0].Model
|
||||||
|
|
||||||
request := api.ShowRequest{
|
|
||||||
Model: model,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show the model
|
|
||||||
show, err := client.Show(ctx, &request)
|
|
||||||
|
|
||||||
// if we get an empty show, something is wrong
|
|
||||||
if show == nil {
|
|
||||||
log.Fatal("show is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we're getting ready for the big show. CHATTING WITH THE TINIEST MODEL ON THE SERVER!
|
// now we're getting ready for the big show. CHATTING WITH THE TINIEST MODEL ON THE SERVER!
|
||||||
|
|
||||||
// Create a new chat message to send to the server. Role must be defined and can be "user", system", or a third one that I forget.
|
// Create a new chat message to send to the server. Role must be defined and can be "user", system", or a third one that I forget.
|
||||||
@ -315,29 +302,6 @@ func ExampleClient_Chat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleClient_Create() {
|
func ExampleClient_Create() {
|
||||||
createTestFile := func(name string) string {
|
|
||||||
f, err := os.CreateTemp("", name)
|
|
||||||
defer f.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = f.Write([]byte("GGUF"))
|
|
||||||
_, err = f.Write([]byte{0x2, 0})
|
|
||||||
|
|
||||||
return f.Name()
|
|
||||||
}
|
|
||||||
|
|
||||||
testFileName := createTestFile("ollama-model")
|
|
||||||
|
|
||||||
modelFileReader := strings.NewReader(fmt.Sprintf("FROM %s\nPARAMETER seed 42\nPARAMETER top_p 0.9\nPARAMETER stop foo\nPARAMETER stop bar", testFileName))
|
|
||||||
modelFile := io.Reader(modelFileReader)
|
|
||||||
|
|
||||||
modelFileBytes, err := io.ReadAll(modelFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
modelFileString := string(modelFileBytes)
|
|
||||||
|
|
||||||
// Create a new context
|
// Create a new context
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -348,11 +312,23 @@ func ExampleClient_Create() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ggufFilePath := "test.gguf"
|
||||||
|
modelFilePath := "testModel"
|
||||||
|
modelName := "tiny-spoof"
|
||||||
|
|
||||||
|
// get the model file bytes from the testModel file
|
||||||
|
modelBytes, err := os.ReadFile(modelFilePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
modelString := string(modelBytes) // convert the model bytes to a string
|
||||||
|
|
||||||
// Create a new create request
|
// Create a new create request
|
||||||
req := &api.CreateRequest{
|
req := &api.CreateRequest{
|
||||||
Path: testFileName,
|
Path: ggufFilePath,
|
||||||
Model: "tiny-spoof",
|
Model: modelName,
|
||||||
Modelfile: modelFileString,
|
Modelfile: modelString,
|
||||||
}
|
}
|
||||||
|
|
||||||
var progressMessages []string // we will store the response from the server in this variable
|
var progressMessages []string // we will store the response from the server in this variable
|
||||||
@ -380,14 +356,14 @@ func ExampleClient_Create() {
|
|||||||
// Iterate through the tags and check if the model was created
|
// Iterate through the tags and check if the model was created
|
||||||
modelCreatedFlag := false
|
modelCreatedFlag := false
|
||||||
for _, tag := range tags.Models {
|
for _, tag := range tags.Models {
|
||||||
if strings.Contains(tag.Model, "tiny-spoof") {
|
if strings.Contains(tag.Model, modelName) {
|
||||||
modelCreatedFlag = true
|
modelCreatedFlag = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the model
|
// delete the model
|
||||||
deleteRequest := &api.DeleteRequest{
|
deleteRequest := &api.DeleteRequest{
|
||||||
Model: "tiny-spoof",
|
Model: modelName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.Delete(ctx, deleteRequest); err != nil { // send the request to the server and if there is an error, log it
|
if err := client.Delete(ctx, deleteRequest); err != nil { // send the request to the server and if there is an error, log it
|
||||||
@ -405,7 +381,7 @@ func ExampleClient_Create() {
|
|||||||
|
|
||||||
// iterate through the tags and check if the model was deleted
|
// iterate through the tags and check if the model was deleted
|
||||||
for _, tag := range tags.Models {
|
for _, tag := range tags.Models {
|
||||||
if strings.Contains(tag.Model, "tiny-spoof") {
|
if strings.Contains(tag.Model, modelName) {
|
||||||
log.Fatal("model was not deleted")
|
log.Fatal("model was not deleted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
api/test.gguf
Normal file
BIN
api/test.gguf
Normal file
Binary file not shown.
5
api/testModel
Normal file
5
api/testModel
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
FROM test.gguf
|
||||||
|
PARAMETER seed 42
|
||||||
|
PARAMETER top_p 0.9
|
||||||
|
PARAMETER stop foo
|
||||||
|
PARAMETER stop bar
|
Loading…
x
Reference in New Issue
Block a user