initial commit
This commit is contained in:
79
backend/internal/client/client_test.go
Normal file
79
backend/internal/client/client_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"reichard.io/aethera/internal/store"
|
||||
)
|
||||
|
||||
const model = "devstral-small-2-instruct"
|
||||
|
||||
func TestSendMessage(t *testing.T) {
|
||||
// Initialize Client
|
||||
baseURL, err := url.Parse("https://llm-api.va.reichard.io/v1")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse base URL: %v", err)
|
||||
}
|
||||
client := NewClient(baseURL)
|
||||
|
||||
// Create Context
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Generate Text Stream
|
||||
var buf bytes.Buffer
|
||||
_, err = client.SendMessage(ctx, []*store.Message{{
|
||||
Role: "user",
|
||||
Content: "Hello, how are you?",
|
||||
}}, model, func(mc *MessageChunk) error {
|
||||
if mc.Message != nil {
|
||||
_, err := buf.Write([]byte(*mc.Message))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate text stream: %v", err)
|
||||
}
|
||||
|
||||
// Verify Results
|
||||
output := buf.String()
|
||||
if output == "" {
|
||||
t.Error("No content was written to the buffer")
|
||||
} else {
|
||||
t.Logf("Successfully received %d bytes from the stream", len(output))
|
||||
t.Logf("Output: %s", output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummarizeChat(t *testing.T) {
|
||||
// Initialize Client
|
||||
baseURL, err := url.Parse("https://llm-api.va.reichard.io/v1")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse base URL: %v", err)
|
||||
}
|
||||
client := NewClient(baseURL)
|
||||
|
||||
// Create Context
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Generate Text Stream
|
||||
userMessage := "Write me a go program that reads in a zip file and prints the contents along with their sizes and mimetype."
|
||||
output, err := client.CreateTitle(ctx, userMessage, model)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to generate text stream: %v", err)
|
||||
}
|
||||
|
||||
// Verify Results
|
||||
if output == "" {
|
||||
t.Error("No content was written to the buffer")
|
||||
} else {
|
||||
t.Logf("Successfully received %d bytes from the stream", len(output))
|
||||
t.Logf("Output: %s", output)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user