@@ -9,9 +9,11 @@ import (
99 "fmt"
1010 "io"
1111 "net/http"
12+ "slices"
1213 "strings"
1314
1415 "github.com/cli/go-gh/v2/pkg/api"
16+ "github.com/github/gh-models/internal/modelkey"
1517 "github.com/github/gh-models/internal/sse"
1618 "golang.org/x/text/language"
1719 "golang.org/x/text/language/display"
@@ -185,19 +187,7 @@ func lowercaseStrings(input []string) []string {
185187
186188// ListModels returns a list of available models.
187189func (c * AzureClient ) ListModels (ctx context.Context ) ([]* ModelSummary , error ) {
188- body := bytes .NewReader ([]byte (`
189- {
190- "filters": [
191- { "field": "freePlayground", "values": ["true"], "operator": "eq"},
192- { "field": "labels", "values": ["latest"], "operator": "eq"}
193- ],
194- "order": [
195- { "field": "displayName", "direction": "asc" }
196- ]
197- }
198- ` ))
199-
200- httpReq , err := http .NewRequestWithContext (ctx , http .MethodPost , c .cfg .ModelsURL , body )
190+ httpReq , err := http .NewRequestWithContext (ctx , http .MethodGet , c .cfg .ModelsURL , nil )
201191 if err != nil {
202192 return nil , err
203193 }
@@ -218,28 +208,34 @@ func (c *AzureClient) ListModels(ctx context.Context) ([]*ModelSummary, error) {
218208 decoder := json .NewDecoder (resp .Body )
219209 decoder .UseNumber ()
220210
221- var searchResponse modelCatalogSearchResponse
222- err = decoder .Decode (& searchResponse )
211+ var catalog githubModelCatalogResponse
212+ err = decoder .Decode (& catalog )
223213 if err != nil {
224214 return nil , err
225215 }
226216
227- models := make ([]* ModelSummary , 0 , len (searchResponse .Summaries ))
228- for _ , summary := range searchResponse .Summaries {
217+ models := make ([]* ModelSummary , 0 , len (catalog ))
218+ for _ , catalogModel := range catalog {
219+ // Determine task from supported modalities - if it supports text input/output, it's likely a chat model
229220 inferenceTask := ""
230- if len (summary .InferenceTasks ) > 0 {
231- inferenceTask = summary .InferenceTasks [0 ]
221+ if slices .Contains (catalogModel .SupportedInputModalities , "text" ) && slices .Contains (catalogModel .SupportedOutputModalities , "text" ) {
222+ inferenceTask = "chat-completion"
223+ }
224+
225+ modelKey , err := modelkey .ParseModelKey (catalogModel .ID )
226+ if err != nil {
227+ return nil , fmt .Errorf ("parsing model key %q: %w" , catalogModel .ID , err )
232228 }
233229
234230 models = append (models , & ModelSummary {
235- ID : summary .AssetID ,
236- Name : summary .Name ,
237- FriendlyName : summary .DisplayName ,
231+ ID : catalogModel .ID ,
232+ Name : modelKey .ModelName ,
233+ Registry : catalogModel .Registry ,
234+ FriendlyName : catalogModel .Name ,
238235 Task : inferenceTask ,
239- Publisher : summary .Publisher ,
240- Summary : summary .Summary ,
241- Version : summary .Version ,
242- RegistryName : summary .RegistryName ,
236+ Publisher : catalogModel .Publisher ,
237+ Summary : catalogModel .Summary ,
238+ Version : catalogModel .Version ,
243239 })
244240 }
245241
0 commit comments