This commit is contained in:
Hong Ooi 2019-09-23 15:18:30 +10:00
Родитель a2360040a2
Коммит 1eda73047a
7 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@ -4,4 +4,5 @@ S3method(print,cognitive_endpoint)
export(az_cognitive_service)
export(call_cognitive_endpoint)
export(cognitive_endpoint)
export(get_cognitive_token)
import(AzureRMR)

Просмотреть файл

@ -44,6 +44,7 @@ globalVariables(c("self", "private"))
#' - `CustomVision.Prediction`: Prediction endpoint for a custom vision service
#' - `ContentModerator`: Content moderation (text and images)
#' - `Text`: text analytics
#' - `TextTranslate`: text translation
#'
#' The possible tiers depend on the type of service created. Consult the Azure Cognitive Service documentation for more information. Usually there will be at least one free tier available.
#'

Просмотреть файл

@ -14,6 +14,7 @@
#' - `CustomVision.Prediction`: Prediction endpoint for a custom vision service
#' - `ContentModerator`: Content moderation (text and images)
#' - `Text`: text analytics
#' - `TextTranslate`: text translation
#'
#' @return
#' An object inheriting from class `cognitive_endpoint`, that can be used to communicate with the REST endpoint. The object will have a subclass based on the type of the service.
@ -158,6 +159,7 @@ get_api_path <- function(type)
customvision=, customvision_training=, customvision_prediction="customvision/v3.0",
contentmoderator="contentmoderator/moderate/v1.0",
text="text/analytics/v2.0",
texttranslate="translate",
stop("Unknown cognitive service", call.=FALSE)
)
}

21
R/get_cognitive_token.R Normal file
Просмотреть файл

@ -0,0 +1,21 @@
#' Obtain authentication token for a cognitive service
#'
#' @param key The subscription key for the service.
#' @param region The Azure region where the service is located.
#' @param token_host Optionally, the URL for the token endpoint.
#' @export
get_cognitive_token <- function(key, region, token_host=NULL)
{
if(is.null(token_host))
token_host <- sprintf("https://%s.api.cognitive.microsoft.com/sts/v1.0/issueToken", normalize_region(region))
hdrs <- httr::add_headers(`Ocp-Apim-Subscription-Key`=unname(key))
res <- httr::POST(token_host, encode="form", hdrs)
rawToChar(process_cognitive_response(res, "stop"))
}
normalize_region <- function(region)
{
tolower(gsub(" ", "", region))
}

Просмотреть файл

@ -34,6 +34,7 @@ Currently, \code{cognitive_endpoint} recognises the following service types:
\item \code{CustomVision.Prediction}: Prediction endpoint for a custom vision service
\item \code{ContentModerator}: Content moderation (text and images)
\item \code{Text}: text analytics
\item \code{TextTranslate}: text translation
}
}
\seealso{

Просмотреть файл

@ -43,6 +43,7 @@ For \code{create_cognitive_service}, the type of service created can be one of t
\item \code{CustomVision.Prediction}: Prediction endpoint for a custom vision service
\item \code{ContentModerator}: Content moderation (text and images)
\item \code{Text}: text analytics
\item \code{TextTranslate}: text translation
}
The possible tiers depend on the type of service created. Consult the Azure Cognitive Service documentation for more information. Usually there will be at least one free tier available.

Просмотреть файл

@ -0,0 +1,18 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_cognitive_token.R
\name{get_cognitive_token}
\alias{get_cognitive_token}
\title{Obtain authentication token for a cognitive service}
\usage{
get_cognitive_token(key, region, token_host = NULL)
}
\arguments{
\item{key}{The subscription key for the service.}
\item{region}{The Azure region where the service is located.}
\item{token_host}{Optionally, the URL for the token endpoint.}
}
\description{
Obtain authentication token for a cognitive service
}