Skip to content

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

Open
wants to merge 10 commits into
base: CON-1716-Project_layout
Choose a base branch
from

Conversation

az-smartling
Copy link

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 under api/ to house related API functionalities.
  • Core Client Base: Added api/mt/base.go to define a common base struct that holds a sm_client.Client instance, intended for reuse across various API services.
  • File Downloader Interface: Defined the Downloader interface in api/mt/downloader.go with methods for downloading single files (File) and batches of files (Batch), along with a stub httpDownloader implementation.
  • File Translator Interface: Created the FileTranslator interface in api/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 in api/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 in api/mt/uploader.go with an UploadFile method, accompanied by a stub httpUploader 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

}

func NewDownloader(client *smclient.Client) Downloader {
return httpDownloader{}

Choose a reason for hiding this comment

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

critical

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}}


func (d httpDownloader) File(url, dest string) error {
//TODO implement me
panic("implement me")

Choose a reason for hiding this comment

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

medium

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


func (d httpDownloader) Batch(urls []string, destDir string) error {
//TODO implement me
panic("implement me")

Choose a reason for hiding this comment

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

medium

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

package mt

import (
smclient "github.com/Smartling/api-sdk-go/helpers/sm_client"

Choose a reason for hiding this comment

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

medium

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.

Suggested change
smclient "github.com/Smartling/api-sdk-go/helpers/sm_client"
"github.com/Smartling/api-sdk-go/helpers/sm_client"

Comment on lines 15 to 17
type httpUploader struct {
client *smclient.Client
}

Choose a reason for hiding this comment

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

medium

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}}.

Suggested change
type httpUploader struct {
client *smclient.Client
}
type httpUploader struct {
base base
}


func (h httpUploader) UploadFile() error {
//TODO implement me
panic("implement me")

Choose a reason for hiding this comment

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

medium

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

@az-smartling az-smartling changed the title CON-1716 API endpoints CON-1716 MT API endpoints Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant