@@ -98,8 +98,10 @@ func decodeString(body io.Reader, output *string) error {
9898 return nil
9999}
100100
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}
103105 if c .config .APIType == APITypeAzure || c .config .APIType == APITypeAzureAD {
104106 baseURL := c .config .BaseURL
105107 baseURL = strings .TrimRight (baseURL , "/" )
@@ -108,8 +110,17 @@ func (c *Client) fullURL(suffix string) string {
108110 if strings .Contains (suffix , "/models" ) {
109111 return fmt .Sprintf ("%s/%s%s?api-version=%s" , baseURL , azureAPIPrefix , suffix , c .config .APIVersion )
110112 }
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+ }
111120 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+ )
113124 }
114125
115126 // c.config.APIType == APITypeOpenAI || c.config.APIType == ""
@@ -120,8 +131,9 @@ func (c *Client) newStreamRequest(
120131 ctx context.Context ,
121132 method string ,
122133 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 )
125137 if err != nil {
126138 return nil , err
127139 }
0 commit comments