Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s
- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名) - 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块) - docreader proto 描述符采用等长替换,保持序列化字节布局有效 - Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像 - 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
70 lines
2.3 KiB
Go
70 lines
2.3 KiB
Go
package rerank
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"sort"
|
|
"testing"
|
|
|
|
"academy/internal/types"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCohereBatchesAtRecommendedDocumentCount(t *testing.T) {
|
|
u := newUpstream(t)
|
|
docs := documents(1001)
|
|
r, err := NewReranker(&RerankerConfig{
|
|
Source: types.ModelSourceRemote, Provider: "cohere", ModelName: "rerank-v4.0-pro",
|
|
BaseURL: u.url + "/v2", APIKey: "k",
|
|
})
|
|
require.NoError(t, err)
|
|
got, err := r.Rerank(context.Background(), "q", docs)
|
|
require.NoError(t, err)
|
|
require.Len(t, got, len(docs))
|
|
require.Len(t, u.requests, 2)
|
|
var counts []int
|
|
for _, req := range u.requests {
|
|
counts = append(counts, len(req.body["documents"].([]any)))
|
|
assert.Equal(t, "/v2/rerank", req.path)
|
|
assert.Equal(t, "Bearer k", req.header.Get("Authorization"))
|
|
assert.NotContains(t, req.body, "top_n")
|
|
assert.NotContains(t, req.body, "return_documents")
|
|
}
|
|
sort.Ints(counts)
|
|
assert.Equal(t, []int{1, 1000}, counts)
|
|
seen := make(map[int]bool, len(got))
|
|
for _, result := range got {
|
|
require.GreaterOrEqual(t, result.Index, 0)
|
|
require.Less(t, result.Index, len(docs))
|
|
assert.False(t, seen[result.Index], "duplicate index %d", result.Index)
|
|
seen[result.Index] = true
|
|
assert.Equal(t, docs[result.Index], result.Document.Text)
|
|
assert.Equal(t, probability(docs[result.Index]), result.RelevanceScore)
|
|
}
|
|
}
|
|
|
|
func TestCohereRestoresDuplicateTextByIndexAndPreservesZero(t *testing.T) {
|
|
withRerankSSRFWhitelist(t, "127.0.0.1")
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{"results":[{"index":1,"relevance_score":0.8},{"index":0,"relevance_score":0}]}`))
|
|
}))
|
|
defer server.Close()
|
|
r, err := NewReranker(&RerankerConfig{
|
|
Source: types.ModelSourceRemote, Provider: "cohere", ModelName: "rerank-v4.0-pro",
|
|
BaseURL: server.URL + "/v2", APIKey: "k",
|
|
})
|
|
require.NoError(t, err)
|
|
got, err := r.Rerank(context.Background(), "q", []string{"same", "same"})
|
|
require.NoError(t, err)
|
|
require.Len(t, got, 2)
|
|
assert.Equal(t, 1, got[0].Index)
|
|
assert.Equal(t, 0.8, got[0].RelevanceScore)
|
|
assert.Equal(t, 0, got[1].Index)
|
|
assert.Zero(t, got[1].RelevanceScore)
|
|
assert.Equal(t, "same", got[0].Document.Text)
|
|
assert.Equal(t, "same", got[1].Document.Text)
|
|
}
|