GithubHelp home page GithubHelp logo

translator-service's Introduction

Install Dependencies

You need to install flask and pytest to run this application.

pip3 install flask
pip3 install pytest

Deploy this service to Google cloud

Please follow this tutorial to deploy translator service to Google cloud.

Test your deployment

Once you have deployed this service, you can access the following link https://PATH_TO_YOUR_DEPLOYED_SERVICE/?q=这是一条中文消息 and you will see a JSON response

{
    "is_english":false,
    "translated_content":"This is a Chinese message"
}

Implement LLM based translator

Please replace translate method in src/translator.py with your LLM based implementation. The translate method takes a string content as input and returns a tuple (bool, str). Indicating if content is in English and the translated content if content is not in English.

Warning

Do not push your API key to your repository. You should use environment variables to store your API key.

Handle responses from LLM

You need to design your prompt so that you can parse the result from a LLM model. However, your system needs to be robust if LLM does not respond as you expect. It is up to you how your system reacts to unexpected responses. You can try a different prompt, return an error message, or simply assume the input is in English.

Test your implementation

Now you need to test your implementation.

To do this, please complete the unit test in test/unit/test_translator.py. In test_llm_normal_response(), please implement a unit test that verifies that your program can return correct value if LLM provides an expected result. In test_llm_gibberish_response(), please implement a unit test that verifies that your program can handle a gibberish response.

Integrate Translator Service With NodeBB

Please merge the changes in https://github.com/CMU-313/NodeBB-S24/tree/leo/draft-pr to your NodeBB repository.

git remote add upstream https://github.com/CMU-313/NodeBB-S24.git
git fetch upstream
git cherry-pick f385a392cfe26812a86b2c87729d561e5c3c9cd4

The changes will call translator API when a new post is received. If the API response indicates that the post is not in English, it will show the translated content in the post.

Since you need to use your own translator service, you need to provide your API endpoint through environment variable TRANSLATOR_API.

export TRANSLATOR_API=https://PATH_TO_YOUR_DEPLOYED_SERVICE
./nodebb start

To add environment variables to your GCP deployment, you can follow this tutorial.

Once you have deployed the changes, you can test the translator service by creating a new post in NodeBB with non-English content 这是一条中文消息.

image

translator-service's People

Contributors

jocelyn-morningstar avatar aoli-al avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.