-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Flair conversion work with more models
found on HuggingFace hub
- Loading branch information
1 parent
64b4552
commit 4da856d
Showing
12 changed files
with
150 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package builtins | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nlpodyssey/cybertron/pkg/converter/flair/conversion" | ||
) | ||
|
||
type Getattr struct{} | ||
|
||
func (Getattr) Call(args ...any) (any, error) { | ||
if len(args) != 2 && len(args) != 3 { | ||
return nil, fmt.Errorf("builtins.getattr: want 2 or 3 args, got %d: %#v", len(args), args) | ||
} | ||
|
||
object, ok := args[0].(conversion.PyAttributeGettable) | ||
if !ok { | ||
return nil, fmt.Errorf("builtins.getattr: 1st arg (object) does not satisfy PyAttributeGettable interface: %T", args[0]) | ||
} | ||
|
||
name, ok := args[1].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("builtins.getattr: want 2nd arg (name) to be string, got %T: %#v", args[1], args[1]) | ||
} | ||
|
||
value, exists, err := object.PyGetAttribute(name) | ||
if err != nil { | ||
return nil, fmt.Errorf("builtins.getattr(%#v): PyGetAttribute failed: %w", args, err) | ||
} | ||
|
||
if len(args) == 3 && !exists { | ||
return args[2], nil | ||
} | ||
return value, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package builtins | ||
|
||
type Int struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package collections | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nlpodyssey/gopickle/types" | ||
) | ||
|
||
type DefaultDictClass struct{} | ||
|
||
type DefaultDict struct { | ||
*types.Dict | ||
DefaultFactory any | ||
} | ||
|
||
func (DefaultDictClass) Call(args ...any) (any, error) { | ||
if len(args) != 1 { | ||
return nil, fmt.Errorf("DefaultDictClass: want 1 argument, got %d: %#v", len(args), args) | ||
} | ||
|
||
return &DefaultDict{ | ||
Dict: types.NewDict(), | ||
DefaultFactory: args[0], | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters