@@ -24,6 +24,7 @@ import (
2424 "encoding/json"
2525 errpkg "errors"
2626 "fmt"
27+ "net/url"
2728 "strings"
2829
2930 "github.com/apache/answer/internal/base/constant"
@@ -728,11 +729,16 @@ func (s *SiteInfoService) GetAIModels(ctx context.Context, req *schema.GetAIMode
728729
729730 var respBody * resty.Response
730731 apiHost := strings .TrimRight (req .APIHost , "/" )
731- if req .Provider == "azure_openai " {
732- // Azure OpenAI uses api-key header and lists deployments
732+ if req .Provider == "azure_ai " {
733+ // Azure AI: parse resource name from apiHost and list deployments via *.openai.azure.com
733734 r .SetHeader ("api-key" , req .APIKey )
734- url := fmt .Sprintf ("%s/openai/deployments?api-version=2022-12-01" , apiHost )
735- respBody , err = r .R ().Get (url )
735+ parsedURL , parseErr := url .Parse (apiHost )
736+ if parseErr != nil || parsedURL .Host == "" {
737+ return resp , errors .BadRequest ("invalid api_host URL" )
738+ }
739+ resourceName := strings .Split (parsedURL .Hostname (), "." )[0 ]
740+ deploymentsURL := fmt .Sprintf ("https://%s.openai.azure.com/openai/deployments?api-version=2022-12-01" , resourceName )
741+ respBody , err = r .R ().Get (deploymentsURL )
736742 } else {
737743 // Standard OpenAI-compatible providers
738744 r .SetHeader ("Authorization" , fmt .Sprintf ("Bearer %s" , req .APIKey ))
@@ -747,7 +753,7 @@ func (s *SiteInfoService) GetAIModels(ctx context.Context, req *schema.GetAIMode
747753 return resp , errors .BadRequest (fmt .Sprintf ("failed to get AI models, response: %s" , respBody .String ()))
748754 }
749755
750- if req .Provider == "azure_openai " {
756+ if req .Provider == "azure_ai " {
751757 data := schema.GetAzureDeploymentsResp {}
752758 _ = json .Unmarshal (respBody .Body (), & data )
753759 for _ , d := range data .Data {
0 commit comments