Skip to content

enhance: get more information about models #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gptscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ type ListModelsOptions struct {
}

// ListModels will list all the available models.
func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) ([]string, error) {
func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) ([]Model, error) {
var o ListModelsOptions
for _, opt := range opts {
o.Providers = append(o.Providers, opt.Providers...)
Expand All @@ -314,7 +314,11 @@ func (g *GPTScript) ListModels(ctx context.Context, opts ...ListModelsOptions) (
return nil, err
}

return strings.Split(strings.TrimSpace(out), "\n"), nil
var models []Model
if err = json.Unmarshal([]byte(out), &models); err != nil {
return nil, err
}
return models, nil
}

func (g *GPTScript) Confirm(ctx context.Context, resp AuthResponse) error {
Expand Down
8 changes: 4 additions & 4 deletions gptscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func TestListModelsWithProvider(t *testing.T) {
}

for _, model := range models {
if !strings.HasPrefix(model, "claude-3-") || !strings.HasSuffix(model, "from github.com/gptscript-ai/claude3-anthropic-provider") {
t.Errorf("Unexpected model name: %s", model)
if !strings.HasPrefix(model.ID, "claude-3-") || !strings.HasSuffix(model.ID, "from github.com/gptscript-ai/claude3-anthropic-provider") {
t.Errorf("Unexpected model name: %s", model.ID)
}
}
}
Expand Down Expand Up @@ -128,8 +128,8 @@ func TestListModelsWithDefaultProvider(t *testing.T) {
}

for _, model := range models {
if !strings.HasPrefix(model, "claude-3-") || !strings.HasSuffix(model, "from github.com/gptscript-ai/claude3-anthropic-provider") {
t.Errorf("Unexpected model name: %s", model)
if !strings.HasPrefix(model.ID, "claude-3-") || !strings.HasSuffix(model.ID, "from github.com/gptscript-ai/claude3-anthropic-provider") {
t.Errorf("Unexpected model name: %s", model.ID)
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions openai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gptscript

type Permission struct {
CreatedAt int64 `json:"created"`
ID string `json:"id"`
Object string `json:"object"`
AllowCreateEngine bool `json:"allow_create_engine"`
AllowSampling bool `json:"allow_sampling"`
AllowLogprobs bool `json:"allow_logprobs"`
AllowSearchIndices bool `json:"allow_search_indices"`
AllowView bool `json:"allow_view"`
AllowFineTuning bool `json:"allow_fine_tuning"`
Organization string `json:"organization"`
Group interface{} `json:"group"`
IsBlocking bool `json:"is_blocking"`
}

type Model struct {
CreatedAt int64 `json:"created"`
ID string `json:"id"`
Object string `json:"object"`
OwnedBy string `json:"owned_by"`
Permission []Permission `json:"permission"`
Root string `json:"root"`
Parent string `json:"parent"`
Metadata map[string]string `json:"metadata"`
}
Comment on lines +3 to +27
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just copied from the chat-completion-client repo. I figured it wasn't worth adding that as a dependency just for this.

Loading