* Improve (#356) to support registration of wildcard URLs * Add TestAzureChatCompletions & TestAzureChatCompletionsWithCustomDeploymentName * Remove TestAzureChatCompletionsWithCustomDeploymentName --------- Co-authored-by: coggsflod <richard.coggins@officedepot.com>
This commit is contained in:
18
chat_test.go
18
chat_test.go
@@ -67,6 +67,24 @@ func TestChatCompletions(t *testing.T) {
|
|||||||
checks.NoError(t, err, "CreateChatCompletion error")
|
checks.NoError(t, err, "CreateChatCompletion error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAzureChatCompletions(t *testing.T) {
|
||||||
|
client, server, teardown := setupAzureTestServer()
|
||||||
|
defer teardown()
|
||||||
|
server.RegisterHandler("/openai/deployments/*", handleChatCompletionEndpoint)
|
||||||
|
|
||||||
|
_, err := client.CreateChatCompletion(context.Background(), ChatCompletionRequest{
|
||||||
|
MaxTokens: 5,
|
||||||
|
Model: GPT3Dot5Turbo,
|
||||||
|
Messages: []ChatCompletionMessage{
|
||||||
|
{
|
||||||
|
Role: ChatMessageRoleUser,
|
||||||
|
Content: "Hello!",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
checks.NoError(t, err, "CreateAzureChatCompletion error")
|
||||||
|
}
|
||||||
|
|
||||||
// handleChatCompletionEndpoint Handles the ChatGPT completion endpoint by the test server.
|
// handleChatCompletionEndpoint Handles the ChatGPT completion endpoint by the test server.
|
||||||
func handleChatCompletionEndpoint(w http.ResponseWriter, r *http.Request) {
|
func handleChatCompletionEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testAPI = "this-is-my-secure-token-do-not-steal!!"
|
const testAPI = "this-is-my-secure-token-do-not-steal!!"
|
||||||
@@ -36,11 +37,14 @@ func (ts *ServerTest) OpenAITestServer() *httptest.Server {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerCall, ok := ts.handlers[r.URL.Path]
|
// Handle /path/* routes.
|
||||||
if !ok {
|
for route, handler := range ts.handlers {
|
||||||
http.Error(w, "the resource path doesn't exist", http.StatusNotFound)
|
pattern, _ := regexp.Compile(route)
|
||||||
return
|
if pattern.MatchString(r.URL.Path) {
|
||||||
|
handler(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handlerCall(w, r)
|
http.Error(w, "the resource path doesn't exist", http.StatusNotFound)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user