feat(ai): enable Terra for ranking (#58)

This commit is contained in:
2026-11-26 09:29:22 +01:00
parent 8a91aabeea
commit 2747e857b1
4 changed files with 137 additions and 6 deletions

View File

@ -13,7 +13,7 @@ import (
)
func TestTicket50CompatibleAdaptersSendNativeSchema(t *testing.T) {
for _, name := range []string{"openai", "ollama"} {
for _, name := range []string{"openai", "openai-terra", "ollama"} {
t.Run(name, func(t *testing.T) {
called := 0
client := &http.Client{Transport: ticket31Transport(func(r *http.Request) (*http.Response, error) {
@ -22,8 +22,11 @@ func TestTicket50CompatibleAdaptersSendNativeSchema(t *testing.T) {
if json.NewDecoder(r.Body).Decode(&body) != nil {
t.Fatal("invalid request")
}
if name == "openai-terra" && (string(body["model"]) != `"gpt-6.1-terra"` || r.URL.Path != "/v1/chat/completions") {
t.Fatalf("unexpected model or route: %s %s", body["model"], r.URL.Path)
}
var schema json.RawMessage
if name == "openai" {
if name == "openai" || name == "openai-terra" {
var format struct {
Type string
JSONSchema struct {
@ -50,16 +53,20 @@ func TestTicket50CompatibleAdaptersSendNativeSchema(t *testing.T) {
t.Fatalf("missing schema: %s", schema)
}
response := `{"done":true,"done_reason":"stop","response":"{\"scores\":[{\"index\":0}]}"}`
if name == "openai" {
if name == "openai" || name == "openai-terra" {
response = `{"choices":[{"finish_reason":"stop","message":{"content":"{\"scores\":[{\"index\":0}]}"}}]}`
}
return &http.Response{StatusCode: 200, Header: http.Header{"Content-Type": []string{"application/json"}}, Body: io.NopCloser(strings.NewReader(response))}, nil
})}
var p Provider
if name == "openai" {
if name == "openai" || name == "openai-terra" {
cfg := openai.DefaultConfig("fixture")
cfg.HTTPClient = client
p = &openAIProvider{model: "gpt-4o-mini", client: openai.NewClientWithConfig(cfg)}
model := "gpt-4o-mini"
if name == "openai-terra" {
model = "gpt-6.1-terra"
}
p = &openAIProvider{model: model, client: openai.NewClientWithConfig(cfg)}
} else {
ollama := newOllama("http://fixture.invalid", "llama3")
ollama.client = client