@@ -98,8 +98,10 @@ func decodeString(body io.Reader, output *string) error {
98
98
return nil
99
99
}
100
100
101
- func (c * Client ) fullURL (suffix string ) string {
102
- // /openai/deployments/{engine}/chat/completions?api-version={api_version}
101
+ // fullURL returns full URL for request.
102
+ // args[0] is model name, if API type is Azure, model name is required to get deployment name.
103
+ func (c * Client ) fullURL (suffix string , args ... any ) string {
104
+ // /openai/deployments/{model}/chat/completions?api-version={api_version}
103
105
if c .config .APIType == APITypeAzure || c .config .APIType == APITypeAzureAD {
104
106
baseURL := c .config .BaseURL
105
107
baseURL = strings .TrimRight (baseURL , "/" )
@@ -108,8 +110,17 @@ func (c *Client) fullURL(suffix string) string {
108
110
if strings .Contains (suffix , "/models" ) {
109
111
return fmt .Sprintf ("%s/%s%s?api-version=%s" , baseURL , azureAPIPrefix , suffix , c .config .APIVersion )
110
112
}
113
+ azureDeploymentName := "UNKNOWN"
114
+ if len (args ) > 0 {
115
+ model , ok := args [0 ].(string )
116
+ if ok {
117
+ azureDeploymentName = c .config .GetAzureDeploymentByModel (model )
118
+ }
119
+ }
111
120
return fmt .Sprintf ("%s/%s/%s/%s%s?api-version=%s" ,
112
- baseURL , azureAPIPrefix , azureDeploymentsPrefix , c .config .Engine , suffix , c .config .APIVersion )
121
+ baseURL , azureAPIPrefix , azureDeploymentsPrefix ,
122
+ azureDeploymentName , suffix , c .config .APIVersion ,
123
+ )
113
124
}
114
125
115
126
// c.config.APIType == APITypeOpenAI || c.config.APIType == ""
@@ -120,8 +131,9 @@ func (c *Client) newStreamRequest(
120
131
ctx context.Context ,
121
132
method string ,
122
133
urlSuffix string ,
123
- body any ) (* http.Request , error ) {
124
- req , err := c .requestBuilder .build (ctx , method , c .fullURL (urlSuffix ), body )
134
+ body any ,
135
+ model string ) (* http.Request , error ) {
136
+ req , err := c .requestBuilder .build (ctx , method , c .fullURL (urlSuffix , model ), body )
125
137
if err != nil {
126
138
return nil , err
127
139
}
0 commit comments