12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package model_entities
- import (
- "testing"
- "github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
- )
- func TestTextEmbeddingFullFunction(t *testing.T) {
- const (
- text_embedding = `
- {
- "model": "text_embedding",
- "embeddings": [[
- 0.1, 0.2, 0.3
- ]],
- "usage" : {
- "tokens": 3,
- "total_tokens": 100,
- "unit_price": 0.1,
- "price_unit": 1,
- "total_price": 10,
- "currency": "usd",
- "latency": 0.1
- }
- }`
- )
- _, err := parser.UnmarshalJsonBytes[TextEmbeddingResult]([]byte(text_embedding))
- if err != nil {
- t.Error(err)
- }
- }
- func TestTextEmbeddingWrongUsage(t *testing.T) {
- const (
- text_embedding = `
- {
- "model": "text_embedding",
- "embeddings": [[
- 0.1, 0.2, 0.3
- ]],
- "usage" : {
- "tokens": 3,
- "total_tokens": 100,
- "unit_price": 0.1,
- "price_unit": 1,
- "total_price": 10,
- "currency": "usd"
- }
- }`
- )
- _, err := parser.UnmarshalJsonBytes[TextEmbeddingResult]([]byte(text_embedding))
- if err == nil {
- t.Error("should have error")
- }
- }
- func TestTextEmbeddingWrongEmbeddings(t *testing.T) {
- const (
- text_embedding = `
- {
- "model": "text_embedding",
- "embeddings": [
- 0.1, 0.2, 0.3
- ],
- "usage" : {
- "tokens": 3,
- "total_tokens": 100,
- "unit_price": 0.1,
- "price_unit": 1,
- "total_price": 10,
- "currency": "usd",
- "latency": 0.1
- }
- }`
- )
- _, err := parser.UnmarshalJsonBytes[TextEmbeddingResult]([]byte(text_embedding))
- if err == nil {
- t.Error("should have error")
- }
- }
|