Files
openai/openai_test.go
T
zeekayandHanzo Dev 88762272c3 refactor(module): declare own import path github.com/hanzoai/go-openai
The fork kept the upstream module path (module github.com/sashabaranov/
go-openai), so every consumer could only reach it through a
"replace github.com/sashabaranov/go-openai => github.com/hanzoai/go-openai"
directive — and Go replace directives do NOT propagate to consumers, so each
downstream repo had to copy the same replace or fail to compile against
fork-only fields (e.g. ReasoningContent). That is the opposite of one-and-
only-one-way.

Declare the fork's OWN module path so it can be required directly and inherited
transitively. Package name stays 'openai' (import identifier unchanged); only
the module path + internal self-imports (/internal, /jsonschema) are renamed.
Upstream issue-URL comments are left intact as attribution. Builds + vets clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-17 21:55:51 -07:00

38 lines
1.1 KiB
Go

package openai_test
import (
"github.com/hanzoai/go-openai"
"github.com/hanzoai/go-openai/internal/test"
)
func setupOpenAITestServer() (client *openai.Client, server *test.ServerTest, teardown func()) {
server = test.NewTestServer()
ts := server.OpenAITestServer()
ts.Start()
teardown = ts.Close
config := openai.DefaultConfig(test.GetTestToken())
config.BaseURL = ts.URL + "/v1"
client = openai.NewClientWithConfig(config)
return
}
func setupAzureTestServer() (client *openai.Client, server *test.ServerTest, teardown func()) {
server = test.NewTestServer()
ts := server.OpenAITestServer()
ts.Start()
teardown = ts.Close
config := openai.DefaultAzureConfig(test.GetTestToken(), "https://dummylab.openai.azure.com/")
config.BaseURL = ts.URL
client = openai.NewClientWithConfig(config)
return
}
// numTokens Returns the number of GPT-3 encoded tokens in the given text.
// This function approximates based on the rule of thumb stated by OpenAI:
// https://beta.openai.com/tokenizer/
//
// TODO: implement an actual tokenizer for GPT-3 and Codex (once available).
func numTokens(s string) int {
return int(float32(len(s)) / 4)
}