weaviate

Форк
0
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

12
package clients
13

14
import (
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

24
func TestGetMeta(t *testing.T) {
25
	t.Run("when the server is providing meta", func(t *testing.T) {
26
		server := httptest.NewServer(&testMetaHandler{t: t})
27
		defer server.Close()
28
		c := New(server.URL, 0, nullLogger())
29
		meta, err := c.MetaInfo()
30

31
		assert.Nil(t, err)
32
		assert.NotNil(t, meta)
33
		metaModel := meta["name"]
34
		require.NotNil(t, metaModel)
35
		assert.Equal(t, "Bert", metaModel)
36
	})
37
}
38

39
type testMetaHandler struct {
40
	t *testing.T
41
	// the test handler will report as not ready before the time has passed
42
	readyTime time.Time
43
}
44

45
func (f *testMetaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
46
	assert.Equal(f.t, "/meta", r.URL.String())
47
	assert.Equal(f.t, http.MethodGet, r.Method)
48

49
	if time.Since(f.readyTime) < 0 {
50
		w.WriteHeader(http.StatusServiceUnavailable)
51
	}
52

53
	w.Write([]byte(f.metaInfo()))
54
}
55

56
func (f *testMetaHandler) metaInfo() string {
57
	return `{
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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.