weaviate
74 строки · 1.9 Кб
1// _ _
2// __ _____ __ ___ ___ __ _| |_ ___
3// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
4// \ V V / __/ (_| |\ V /| | (_| | || __/
5// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
6//
7// Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
8//
9// CONTACT: hello@weaviate.io
10//
11
12package clients
13
14import (
15"net/http"
16"net/http/httptest"
17"testing"
18"time"
19
20"github.com/stretchr/testify/assert"
21"github.com/stretchr/testify/require"
22)
23
24func TestGetMeta(t *testing.T) {
25t.Run("when the server is providing meta", func(t *testing.T) {
26server := httptest.NewServer(&testMetaHandler{t: t})
27defer server.Close()
28c := New(server.URL, 0, nullLogger())
29meta, err := c.MetaInfo()
30
31assert.Nil(t, err)
32assert.NotNil(t, meta)
33metaModel := meta["name"]
34require.NotNil(t, metaModel)
35assert.Equal(t, "Bert", metaModel)
36})
37}
38
39type testMetaHandler struct {
40t *testing.T
41// the test handler will report as not ready before the time has passed
42readyTime time.Time
43}
44
45func (f *testMetaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
46assert.Equal(f.t, "/meta", r.URL.String())
47assert.Equal(f.t, http.MethodGet, r.Method)
48
49if time.Since(f.readyTime) < 0 {
50w.WriteHeader(http.StatusServiceUnavailable)
51}
52
53w.Write([]byte(f.metaInfo()))
54}
55
56func (f *testMetaHandler) metaInfo() string {
57return `{
58"description": "<strong>Sbert</strong><br><ul><li>For embeddings",
59"disableGUI": "true",
60"filename": "ggml-all-MiniLM-L6-v2-f16.bin",
61"filesize": "45521167",
62"md5sum": "031bb5d5722c08d13e3e8eaf55c37391",
63"name": "Bert",
64"order": "t",
65"parameters": "1 million",
66"path": "/Users/marcin/.cache/gpt4all/ggml-all-MiniLM-L6-v2-f16.bin",
67"promptTemplate": "### Human: \n{0}\n### Assistant:\n",
68"quant": "f16",
69"ramrequired": "1",
70"requires": "2.4.14",
71"systemPrompt": "",
72"type": "Bert"
73}`
74}
75