From edd08f62ab6c3a8f6dda4205839df0f76511df89 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Wed, 24 Jan 2024 20:29:59 -0800 Subject: [PATCH] removed example_basic as it was a duplicate of ExampleClient_Chat --- api/example_test.go | 68 --------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/api/example_test.go b/api/example_test.go index 85fd29ff..7d854725 100644 --- a/api/example_test.go +++ b/api/example_test.go @@ -40,74 +40,6 @@ func TestMain(m *testing.M) { os.Exit(result) } -func Example_basic() { - // Create a new context - ctx := context.Background() - - // Create a new client - client, err := api.ClientFromEnvironment() - if err != nil { - log.Fatal(err) - } - - // List all the models on the server as tags - tags, err := client.List(ctx) - if err != nil { - log.Fatal(err) - } - - // if we get an empty list it means that there are no models on the server - if len(tags.Models) == 0 { - log.Fatal("no tags returned") - } - - // sort the tags.models by Size least to greatest - sort.Slice(tags.Models, func(i, j int) bool { - return tags.Models[i].Size < tags.Models[j].Size - }) - - // Get the first model in the list - model := tags.Models[0].Model - - // 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. - // These should be defined in the api package as an enum constant or something. - chatMessage := api.Message{ - Content: "Hello! Tell me about yourself in exactly one sentence.", - Role: "user", - } - - // Create a new chat request to send to the server. This specifies the model and the messages to send. - req := &api.ChatRequest{ - Model: model, - Messages: []api.Message{chatMessage}, - } - - // Create a function to handle the response from the server. This is a callback function that will be called for each response from the server. - var modelResponseText string // we will store the response from the server in this variable - fn := func(response api.ChatResponse) error { // this callback function fires for each token returned from the server - - modelResponseText += response.Message.Content // append the response to the modelResponseText variable to retrieve the whole message - return nil - } - - if err := client.Chat(ctx, req, fn); err != nil { // send the request to the server and if there is an error, log it - if errors.Is(err, context.Canceled) { - log.Fatal("context was canceled") - } - log.Fatal(err) - } - - if modelResponseText == "" { - log.Fatal("modelResponseText is empty") - } else { - fmt.Println("model responded") - } - // Output: - // model responded -} - func ExampleClient_Heartbeat() { // Create a new context ctx := context.Background()