generated from maragudk/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.go
36 lines (30 loc) · 850 Bytes
/
embed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gai
import (
"context"
"io"
)
// EmbedRequest for [Embedder].
type EmbedRequest struct {
Input io.Reader
}
// VectorComponent is a single component of a vector.
type VectorComponent interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}
// EmbedResponse for [Embedder].
type EmbedResponse[T VectorComponent] struct {
Embedding []T
}
// Embedder is satisfied by models supporting embedding.
type Embedder[T VectorComponent] interface {
Embed(ctx context.Context, p EmbedRequest) (EmbedResponse[T], error)
}
// ReadAllString is like [io.ReadAll], but returns a string, and panics on errors.
// Useful for situations where the read cannot error.
func ReadAllString(r io.Reader) string {
d, err := io.ReadAll(r)
if err != nil {
panic(err)
}
return string(d)
}