-
Notifications
You must be signed in to change notification settings - Fork 4
CON-1716 MT API endpoints #13
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
base: CON-1716-Project_layout
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @az-smartling, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request establishes the foundational structure for new machine translation (MT) related API endpoints within the api-sdk-go
project. It primarily involves creating new Go files that define interfaces for various functionalities such as file uploading, downloading, translation control, and file translation, along with basic stub implementations for some of these interfaces. This sets the stage for future development and integration of these API features.
Highlights
- New API Module Structure: Introduced a new
mt
(machine translation) package underapi/
to house related API functionalities. - Core Client Base: Added
api/mt/base.go
to define a commonbase
struct that holds asm_client.Client
instance, intended for reuse across various API services. - File Downloader Interface: Defined the
Downloader
interface inapi/mt/downloader.go
with methods for downloading single files (File
) and batches of files (Batch
), along with a stubhttpDownloader
implementation. - File Translator Interface: Created the
FileTranslator
interface inapi/mt/file_translator.go
to outline methods for starting (Start
) and checking the progress (Progress
) of file translations. - Translation Control Interface: Added the
TranslationControl
interface inapi/mt/translation_control.go
for managing translation processes, including canceling translations (CancelTranslation
) and detecting file languages (DetectFileLanguage
,DetectionProgress
). - File Uploader Interface: Introduced the
Uploader
interface inapi/mt/uploader.go
with anUploadFile
method, accompanied by a stubhttpUploader
implementation.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces foundational structures for new API endpoints within the mt
(Machine Translation) package. My review focuses on ensuring correct client initialization, improving the robustness of stubbed methods by suggesting error returns instead of panics, and promoting consistency in struct design and import patterns across the new files. Since no explicit style guide was provided, feedback is based on common Go idioms and best practices.
api/mt/downloader.go
Outdated
} | ||
|
||
func NewDownloader(client *smclient.Client) Downloader { | ||
return httpDownloader{} |
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.
The smclient.Client
within the embedded base
struct is not being initialized in NewDownloader
. This will lead to a nil pointer dereference when methods on httpDownloader
attempt to use the client.
The base
struct should be initialized with the provided client.
return httpDownloader{base: base{client: client}}
api/mt/downloader.go
Outdated
|
||
func (d httpDownloader) File(url, dest string) error { | ||
//TODO implement me | ||
panic("implement me") |
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.
While panic
clearly indicates an unimplemented part, it can crash the application using this SDK. For library code, it's generally better to return an error for unimplemented methods. This allows the calling code to handle the situation more gracefully.
Consider returning an error like errors.New("mt.httpDownloader.File not implemented")
.
return errors.New("mt.httpDownloader.File: not implemented") // Or a more specific error
api/mt/downloader.go
Outdated
|
||
func (d httpDownloader) Batch(urls []string, destDir string) error { | ||
//TODO implement me | ||
panic("implement me") |
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.
Similar to the File
method, panicking here can abruptly terminate the consuming application. Returning an error is a more robust approach for unimplemented methods in a library.
Consider returning an error like errors.New("mt.httpDownloader.Batch not implemented")
.
return errors.New("mt.httpDownloader.Batch: not implemented") // Or a more specific error
api/mt/uploader.go
Outdated
package mt | ||
|
||
import ( | ||
smclient "github.com/Smartling/api-sdk-go/helpers/sm_client" |
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.
The import alias smclient
for github.com/Smartling/api-sdk-go/helpers/sm_client
is redundant because the package name itself is smclient
(as declared in helpers/sm_client/client.go
).
For consistency with other files in this PR (e.g., base.go
, downloader.go
which import it directly as "github.com/Smartling/api-sdk-go/helpers/sm_client"
and use smclient.Client
), you can remove this explicit alias. The code will continue to work as smclient.Client
will resolve correctly due to the package's actual name.
smclient "github.com/Smartling/api-sdk-go/helpers/sm_client" | |
"github.com/Smartling/api-sdk-go/helpers/sm_client" |
api/mt/uploader.go
Outdated
type httpUploader struct { | ||
client *smclient.Client | ||
} |
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.
The httpUploader
struct defines its own client
field, whereas httpDownloader
embeds the base
struct (which contains the client). For consistency and to potentially leverage shared functionality that might be added to base
in the future, consider having httpUploader
also embed the base
struct.
If you make this change, NewUploader
(on line 12) would also need to be updated to initialize the embedded base
struct, similar to how NewDownloader
should be: return httpUploader{base: base{client: client}}
.
type httpUploader struct { | |
client *smclient.Client | |
} | |
type httpUploader struct { | |
base base | |
} |
api/mt/uploader.go
Outdated
|
||
func (h httpUploader) UploadFile() error { | ||
//TODO implement me | ||
panic("implement me") |
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.
As with the methods in downloader.go
, using panic
for an unimplemented method can cause the consuming application to crash. It's generally safer for library code to return an error.
Consider returning an error like errors.New("mt.httpUploader.UploadFile not implemented")
.
return errors.New("mt.httpUploader.UploadFile: not implemented") // Or a more specific error
# Conflicts: # client_authenticate.go # helpers/sm_client/client_upload_file.go
No description provided.