Skip to content

Instantly share code, notes, and snippets.

@yodiz
Created January 23, 2024 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yodiz/43637281ac9fccaf56dc8b4e896a2e64 to your computer and use it in GitHub Desktop.
Save yodiz/43637281ac9fccaf56dc8b4e896a2e64 to your computer and use it in GitHub Desktop.
#r "nuget:Fenix.Dry"
module Translate =
open Fenix.Dry.Http
open Fenix.Dry.Http.HttpResponse
let translate q =
let body =
System.Text.Json.JsonSerializer.Serialize({| text = [|q|]; target_lang = "EN-US"; source_lang = "NB" |})
let resp =
HttpRequest.postStrUtf8 "https://api-free.deepl.com/v2/translate" body
|> HttpRequest.Header.contentType "application/json"
|> HttpRequest.Header.set "Authorization" "DeepL-Auth-Key ededee63-628c-3371-3532-b3f283b8d74e:fx"
|> Client.send 30000
let body = Body.asStrUtf8 resp
if resp.Status <> 200 then failwithf "Expected 200 resp, got %i - %s" resp.Status body
let json = System.Text.Json.JsonSerializer.Deserialize<{|translations : {|text : string; detected_source_language : string |} array |}>(body)
json.translations[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment