-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: support nova-3 and keyterms #277
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |||||||||||||||||
"net/http" | ||||||||||||||||||
"net/url" | ||||||||||||||||||
"os" | ||||||||||||||||||
"strings" | ||||||||||||||||||
|
||||||||||||||||||
klog "k8s.io/klog/v2" | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -75,6 +76,11 @@ Output parameters: | |||||||||||||||||
func (c *Client) DoFile(ctx context.Context, filePath string, req *interfaces.PreRecordedTranscriptionOptions, resBody interface{}) error { | ||||||||||||||||||
klog.V(6).Infof("prerecorded.DoFile() ENTER\n") | ||||||||||||||||||
|
||||||||||||||||||
if len(req.Keyterms) > 0 && !strings.HasPrefix(req.Model, "nova-3") { | ||||||||||||||||||
klog.V(1).Info("Keyterms are only supported with nova-3 models.") | ||||||||||||||||||
return nil | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return a descriptive error in DoFile. Return a descriptive error to better communicate why the operation failed. Apply this diff to improve error handling: if len(req.Keyterms) > 0 && !strings.HasPrefix(req.Model, "nova-3") {
klog.V(1).Info("Keyterms are only supported with nova-3 models.")
- return nil
+ return fmt.Errorf("keyterms are only supported with nova-3 models, got model: %s", req.Model)
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
// file? | ||||||||||||||||||
fileInfo, err := os.Stat(filePath) | ||||||||||||||||||
if err != nil || errors.Is(err, os.ErrNotExist) { | ||||||||||||||||||
|
@@ -116,6 +122,11 @@ Output parameters: | |||||||||||||||||
func (c *Client) DoStream(ctx context.Context, src io.Reader, options *interfaces.PreRecordedTranscriptionOptions, resBody interface{}) error { | ||||||||||||||||||
klog.V(6).Infof("prerecorded.DoStream() ENTER\n") | ||||||||||||||||||
|
||||||||||||||||||
if len(options.Keyterms) > 0 && !strings.HasPrefix(options.Model, "nova-3") { | ||||||||||||||||||
klog.V(1).Info("Keyterms are only supported with nova-3 models.") | ||||||||||||||||||
return nil | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+125
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return a descriptive error in DoStream. Return a descriptive error to better communicate why the operation failed. Apply this diff to improve error handling: if len(options.Keyterms) > 0 && !strings.HasPrefix(options.Model, "nova-3") {
klog.V(1).Info("Keyterms are only supported with nova-3 models.")
- return nil
+ return fmt.Errorf("keyterms are only supported with nova-3 models, got model: %s", options.Model)
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
uri, err := version.GetPrerecordedAPI(ctx, c.Options.Host, c.Options.APIVersion, c.Options.Path, options) | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
klog.V(1).Infof("GetPrerecordedAPI failed. Err: %v\n", err) | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ package websocketv1 | |||||||||||||||||
|
||||||||||||||||||
import ( | ||||||||||||||||||
"context" | ||||||||||||||||||
"strings" | ||||||||||||||||||
|
||||||||||||||||||
klog "k8s.io/klog/v2" | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -69,6 +70,10 @@ func NewUsingCallbackWithCancel(ctx context.Context, ctxCancel context.CancelFun | |||||||||||||||||
if apiKey != "" { | ||||||||||||||||||
cOptions.APIKey = apiKey | ||||||||||||||||||
} | ||||||||||||||||||
if len(tOptions.Keyterms) > 0 && !strings.HasPrefix(tOptions.Model, "nova-3") { | ||||||||||||||||||
klog.V(1).Info("Keyterms are only supported with nova-3 models.") | ||||||||||||||||||
return nil, nil | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return a descriptive error instead of nil. While the validation logic is correct, returning Apply this diff to improve error handling: if len(tOptions.Keyterms) > 0 && !strings.HasPrefix(tOptions.Model, "nova-3") {
klog.V(1).Info("Keyterms are only supported with nova-3 models.")
- return nil, nil
+ return nil, fmt.Errorf("keyterms are only supported with nova-3 models, got model: %s", tOptions.Model)
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
err := cOptions.Parse() | ||||||||||||||||||
if err != nil { | ||||||||||||||||||
klog.V(1).Infof("ClientOptions.Parse() failed. Err: %v\n", err) | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ package websocketv1 | |
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
klog "k8s.io/klog/v2" | ||
|
||
|
@@ -69,6 +70,10 @@ func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, a | |
if apiKey != "" { | ||
cOptions.APIKey = apiKey | ||
} | ||
if len(tOptions.Keyterms) > 0 && !strings.HasPrefix(tOptions.Model, "nova-3") { | ||
klog.V(1).Info("Keyterms are only supported with nova-3 models.") | ||
return nil, nil | ||
} | ||
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling for keyterms validation. The current implementation returns if len(tOptions.Keyterms) > 0 && !strings.HasPrefix(tOptions.Model, "nova-3") {
klog.V(1).Info("Keyterms are only supported with nova-3 models.")
- return nil, nil
+ return nil, fmt.Errorf("keyterms are only supported with nova-3 models, got model: %s", tOptions.Model)
} |
||
err := cOptions.Parse() | ||
if err != nil { | ||
klog.V(1).Infof("ClientOptions.Parse() failed. Err: %v\n", err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling for keyterms validation.
The current implementation returns
nil, nil
when keyterms validation fails, which makes it unclear whether the operation succeeded or failed. Consider returning a proper error to indicate the validation failure.