File tree 2 files changed +27
-5
lines changed
2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,24 @@ func TestChatCompletions(t *testing.T) {
67
67
checks .NoError (t , err , "CreateChatCompletion error" )
68
68
}
69
69
70
+ func TestAzureChatCompletions (t * testing.T ) {
71
+ client , server , teardown := setupAzureTestServer ()
72
+ defer teardown ()
73
+ server .RegisterHandler ("/openai/deployments/*" , handleChatCompletionEndpoint )
74
+
75
+ _ , err := client .CreateChatCompletion (context .Background (), ChatCompletionRequest {
76
+ MaxTokens : 5 ,
77
+ Model : GPT3Dot5Turbo ,
78
+ Messages : []ChatCompletionMessage {
79
+ {
80
+ Role : ChatMessageRoleUser ,
81
+ Content : "Hello!" ,
82
+ },
83
+ },
84
+ })
85
+ checks .NoError (t , err , "CreateAzureChatCompletion error" )
86
+ }
87
+
70
88
// handleChatCompletionEndpoint Handles the ChatGPT completion endpoint by the test server.
71
89
func handleChatCompletionEndpoint (w http.ResponseWriter , r * http.Request ) {
72
90
var err error
Original file line number Diff line number Diff line change 4
4
"log"
5
5
"net/http"
6
6
"net/http/httptest"
7
+ "regexp"
7
8
)
8
9
9
10
const testAPI = "this-is-my-secure-token-do-not-steal!!"
@@ -36,11 +37,14 @@ func (ts *ServerTest) OpenAITestServer() *httptest.Server {
36
37
return
37
38
}
38
39
39
- handlerCall , ok := ts .handlers [r .URL .Path ]
40
- if ! ok {
41
- http .Error (w , "the resource path doesn't exist" , http .StatusNotFound )
42
- return
40
+ // Handle /path/* routes.
41
+ for route , handler := range ts .handlers {
42
+ pattern , _ := regexp .Compile (route )
43
+ if pattern .MatchString (r .URL .Path ) {
44
+ handler (w , r )
45
+ return
46
+ }
43
47
}
44
- handlerCall (w , r )
48
+ http . Error (w , "the resource path doesn't exist" , http . StatusNotFound )
45
49
}))
46
50
}
You can’t perform that action at this time.
0 commit comments