rerank_test.go 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package model_entities
  2. import (
  3. "testing"
  4. "github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
  5. )
  6. func TestRerankFullFunction(t *testing.T) {
  7. const (
  8. rerank = `
  9. {
  10. "model": "rerank",
  11. "docs": [
  12. {
  13. "index": 1,
  14. "text": "text",
  15. "score": 0.1
  16. }
  17. ]
  18. }`
  19. )
  20. _, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank))
  21. if err != nil {
  22. t.Error(err)
  23. }
  24. }
  25. func TestRerankWrongDocs(t *testing.T) {
  26. const (
  27. rerank = `
  28. {
  29. "model": "rerank",
  30. "docs": [
  31. {
  32. "index": 1,
  33. "text": "text"
  34. }
  35. ]
  36. }`
  37. )
  38. _, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank))
  39. if err == nil {
  40. t.Error("should have error")
  41. }
  42. }
  43. func TestRerankWrongDocIndex(t *testing.T) {
  44. const (
  45. rerank = `
  46. {
  47. "model": "rerank",
  48. "docs": [
  49. {
  50. "text": "text",
  51. "score": 0.1
  52. }
  53. ]
  54. }`
  55. )
  56. _, err := parser.UnmarshalJsonBytes[RerankResult]([]byte(rerank))
  57. if err == nil {
  58. t.Error("should have error")
  59. }
  60. }