Skip to content

Getting started

Ramtin Yazdanian edited this page Apr 29, 2024 · 6 revisions

Guide to getting started with GraphAI

This is a step-by-step guide intended for anyone aiming to use the GraphAI API.

Open SSH tunnel

Here is the ssh config that you should add to your ssh config file (typically ~/.ssh/config in unix):

# Jump Host
Host 86.119.30.24 jumphost-ls
  User vpn
  Hostname 86.119.30.24
  IdentityFile /path/to/your/private/key

Host 192.168.142.120 graphai
  Hostname 192.168.142.120
  User tunnel
  LocalForward 127.0.0.1:28800 127.0.0.1:28800
  IdentityFile /path/to/your/private/key
  ProxyJump jumphost-ls

After pasting this to your config file, you should be able to connect running the following command in a terminal:

ssh -f -N graphai

Check documentation

Once the tunnel is open, you should be able to see the API documentation by browsing to localhost:28800 on any browser.

Using the API endpoints

Direct use

Authenticate in the API

To use the API, you should authenticate first by calling the /token endpoint:

curl -X 'POST' 'http://localhost:28800/token' -H 'accept: application/json' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=&username=YOURUSERNAME&password=YOURPASSWORD&scope=&client_id=&client_secret='

If you do not have a username and password, contact Ramtin.

This will return an access token valid for the current session, that you’ll have to include as a header in subsequent requests to other endpoints as follows:

-H 'Authorization: Bearer ACCESSTOKEN'

Example direct use: Translate text

With this you can access the API. To translate texts using the Helsinki models, make a POST request to /translation/translate with the text to translate (more details in the API docs). For instance:

{
  "text": "hey there",
  "source": "en",
  "target": "fr"
}

For now we only support English to French, French to English, German to English, and Italian to English. Because the translation of long texts is sometimes a bit slow, the endpoint is anynchronous, meaning that you will get a response immediately with a task id, like

{
  "task_id": "38c0385b-472e-48fb-9be6-5cc5bc19f2ef"
}

Once you have the task id you’ll have to poll the endpoint /translation/translate/status/{task_id}. When the text is translated, you’ll get a response like

{
  "task_id": "38c0385b-472e-48fb-9be6-5cc5bc19f2ef",
  "task_name": "text_6.translate_text_callback",
  "task_status": "SUCCESS",
  "task_result": {
    "result": " Bonjour.",
    "text_too_large": false,
    "successful": true,
    "fresh": true,
    "device": "cpu"
  }
}

Using graphai-client

Thanks to Yves' graphai-client, you can use the API directly through Python with ease, and you won't have to manually deal with the aforementioned authentication and POST and GET requests.

Clone this wiki locally