-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
210 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package model_entities | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/langgenius/dify-plugin-daemon/internal/utils/parser" | ||
) | ||
|
||
func TestRerankFullFunction(t *testing.T) { | ||
const ( | ||
rerank = ` | ||
{ | ||
"model": "rerank", | ||
"docs": [ | ||
{ | ||
"index": 1, | ||
"text": "text", | ||
"score": 0.1 | ||
} | ||
] | ||
}` | ||
) | ||
|
||
_, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank)) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestRerankWrongDocs(t *testing.T) { | ||
const ( | ||
rerank = ` | ||
{ | ||
"model": "rerank", | ||
"docs": [ | ||
{ | ||
"index": 1, | ||
"text": "text" | ||
} | ||
] | ||
}` | ||
) | ||
|
||
_, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank)) | ||
if err == nil { | ||
t.Error("should have error") | ||
} | ||
} | ||
|
||
func TestRerankWrongDocIndex(t *testing.T) { | ||
const ( | ||
rerank = ` | ||
{ | ||
"model": "rerank", | ||
"docs": [ | ||
{ | ||
"text": "text", | ||
"score": 0.1 | ||
} | ||
] | ||
}` | ||
) | ||
|
||
_, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank)) | ||
if err == nil { | ||
t.Error("should have error") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
package model_entities | ||
|
||
import "github.com/shopspring/decimal" | ||
|
||
type EmbeddingUsage struct { | ||
Tokens *int `json:"tokens" validate:"required"` | ||
TotalTokens *int `json:"total_tokens" validate:"required"` | ||
UnitPrice decimal.Decimal `json:"unit_price" validate:"required"` | ||
PriceUnit decimal.Decimal `json:"price_unit" validate:"required"` | ||
TotalPrice decimal.Decimal `json:"total_price" validate:"required"` | ||
Currency *string `json:"currency" validate:"required"` | ||
Latency *float64 `json:"latency" validate:"required"` | ||
} | ||
|
||
type TextEmbeddingResult struct { | ||
Model string `json:"model" validate:"required"` | ||
Embeddings [][]float64 `json:"embeddings" validate:"required,dive"` | ||
Usage EmbeddingUsage `json:"usage" validate:"required"` | ||
} |
84 changes: 84 additions & 0 deletions
84
internal/types/entities/model_entities/text_embedding_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters