mirror of
https://github.com/hanzo-go/openai.git
synced 2026-09-24 00:31:39 +00:00
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]>
38 lines
1.1 KiB
Go
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)
|
|
}
|