nlpcloud

package module
v1.1.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 9 Imported by: 0

README

Go Client For NLP Cloud

reference go report

This is a Go client for the NLP Cloud API. See the documentation for more details.

NLP Cloud serves high performance pre-trained or custom models for NER, sentiment-analysis, classification, summarization, dialogue summarization, paraphrasing, intent classification, product description and ad generation, chatbot, grammar and spelling correction, keywords and keyphrases extraction, text generation, image generation, question answering, automatic speech recognition, machine translation, language detection, semantic search, semantic similarity, tokenization, POS tagging, embeddings, and dependency parsing. It is ready for production, served through a REST API.

You can either use the NLP Cloud pre-trained models, fine-tune your own models, or deploy your own models.

If you face an issue, don't hesitate to raise it as a Github issue. Thanks!

Installation

Install using go install.

go install github.com/nlpcloud/nlpcloud-go

Examples

Here is a full example that summarizes a text using Facebook's Bart Large CNN model, with a fake token:

package main

import (
    "net/http"
    
    "github.com/nlpcloud/nlpcloud-go"
)

func main() {
    client := nlpcloud.NewClient(&http.Client{}, nlpcloud.ClientParams{
        Model:"bart-large-cnn", Token:"4eC39HqLyjWDarjtT1zdp7dc", GPU:false, Lang:"", Async:false})
    summarization, err := client.Summarization(nlpcloud.SummarizationParams{Text: `One month after
    the United States began what has become a troubled rollout of a national COVID vaccination
    campaign, the effort is finally gathering real steam. Close to a million doses -- over 951,000, to be more exact -- 
    made their way into the arms of Americans in the past 24 hours, the U.S. Centers 
    for Disease Control and Prevention reported Wednesday. That s the largest number 
    of shots given in one day since the rollout began and a big jump from the 
    previous day, when just under 340,000 doses were given, CBS News reported. 
    That number is likely to jump quickly after the federal government on Tuesday 
    gave states the OK to vaccinate anyone over 65 and said it would release all 
    the doses of vaccine it has available for distribution. Meanwhile, a number 
    of states have now opened mass vaccination sites in an effort to get larger 
    numbers of people inoculated, CBS News reported.`})
    ...
}

Here is a full example that does the same thing, but on a GPU:

package main

import (
    "net/http"
    
    "github.com/nlpcloud/nlpcloud-go"
)

func main() {
    client := nlpcloud.NewClient(&http.Client{}, nlpcloud.ClientParams{
        Model:"bart-large-cnn", Token:"4eC39HqLyjWDarjtT1zdp7dc", GPU:true, Lang:"", Async:false})
    summarization, err := client.Summarization(nlpcloud.SummarizationParams{Text: `One month after
    the United States began what has become a troubled rollout of a national COVID vaccination
    campaign, the effort is finally gathering real steam. Close to a million doses -- over 951,000, to be more exact -- 
    made their way into the arms of Americans in the past 24 hours, the U.S. Centers 
    for Disease Control and Prevention reported Wednesday. That s the largest number 
    of shots given in one day since the rollout began and a big jump from the 
    previous day, when just under 340,000 doses were given, CBS News reported. 
    That number is likely to jump quickly after the federal government on Tuesday 
    gave states the OK to vaccinate anyone over 65 and said it would release all 
    the doses of vaccine it has available for distribution. Meanwhile, a number 
    of states have now opened mass vaccination sites in an effort to get larger 
    numbers of people inoculated, CBS News reported.`})
    ...
}

Here is a full example that does the same thing, but on a French text:

package main

import (
    "net/http"
    
    "github.com/nlpcloud/nlpcloud-go"
)

func main() {
    client := nlpcloud.NewClient(&http.Client{}, nlpcloud.ClientParams{
        Model:"bart-large-cnn", Token:"4eC39HqLyjWDarjtT1zdp7dc", GPU:true, Lang:"fra_Latn", Async:false})
    summarization, err := client.Summarization(nlpcloud.SummarizationParams{Text: `Sur des images aériennes, 
    prises la veille par un vol de surveillance de la Nouvelle-Zélande, la côte d’une île est bordée 
    d’arbres passés du vert au gris sous l’effet des retombées volcaniques. On y voit aussi des immeubles
    endommagés côtoyer des bâtiments intacts. « D’après le peu d’informations
    dont nous disposons, l’échelle de la dévastation pourrait être immense, 
    spécialement pour les îles les plus isolées », avait déclaré plus tôt 
    Katie Greenwood, de la Fédération internationale des sociétés de la Croix-Rouge.
    Selon l’Organisation mondiale de la santé (OMS), une centaine de maisons ont
    été endommagées, dont cinquante ont été détruites sur l’île principale de
    Tonga, Tongatapu. La police locale, citée par les autorités néo-zélandaises,
    a également fait état de deux morts, dont une Britannique âgée de 50 ans,
    Angela Glover, emportée par le tsunami après avoir essayé de sauver les chiens
    de son refuge, selon sa famille.`})
    ...
}

Usage

Client Initialization

While it uses a HTTP REST API, you'll have to pass an instance that implements interface HTTPClient. It works with a *http.Client.

Pass the model you want to use and the NLP Cloud token to the client during initialization.

The model can either be a pre-trained model like en_core_web_lg, bart-large-mnli, ... but also one of your custom models using custom_model/<model id> (e.g. custom_model/2568).

Your token can be retrieved from your NLP Cloud dashboard.

package main

import (
    "net/http"
    
    "github.com/nlpcloud/nlpcloud-go"
)

func main() {
    client := nlpcloud.NewClient(&http.Client{}, nlpcloud.`ClientParams{
        Model:"<model>", Token:"<token>", GPU:false, Lang:"<language>", Async:false})
    ...
}

If you want to use a GPU, set the 4th parameter as true.

If you want to use the multilingual add-on in order to process non-English texts, set your language code in the 5th parameter. For example, if you want to process French text, you should set the 5th parameter as "fra_Latn".

If you want to make asynchronous requests, pass the 5th parameter as true. You will always receive a quick response containing a URL. You should then poll this URL with nlpcloud.AsyncResult() on a regular basis (every 10 seconds for example) in order to check if the result is available.

API endpoint

Depending on the API endpoint, it may have parameters (only LibVersions does not follow this rule). In case it has parameters, you can call an endpoint using the following:

res, err := client.TheAPIEndpoint(params TheAPIEndpointParams)
Streaming

Some API endpoints support token streaming through Server Sent Events (SSE). Here is an example showing how to implement token streaming with the generation API endpoint:

client := nlpcloud.NewClient(&http.Client{}, nlpcloud.ClientParams{Model: <model_name>, Token: <token>, GPU: true})

streamBody, err := client.StreamingGeneration(nlpcloud.GenerationParams{
  Text: "LLaMA is a powerful NLP model",
  MaxLength: 50,
})

defer streamBody.Close()

stream := bufio.NewReader(streamBody)

for {
  chunk, err := stream.ReadBytes('\x00')
  if err != nil {
    if errors.Is(err, io.EOF) {
      break
    }
    log.Fatalln()
  }

  fmt.Println(string(chunk))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASR added in v1.1.25

type ASR struct {
	Text     string    `json:"text"`
	Duration int       `json:"duration"`
	Language string    `json:"language"`
	Segments []Segment `json:"segments"`
	Words    []ASRWord `json:"words"`
}

ASR holds the extracted text returned by the API.

type ASRParams added in v1.1.25

type ASRParams struct {
	URL           *string `json:"url"`
	EncodedFile   *string `json:"encoded_file"`
	InputLanguage *string `json:"input_language"`
}

ASRParams wraps all the parameters for the "asr" endpoint.

type ASRWord added in v1.1.51

type ASRWord struct {
	ID      int     `json:"id"`
	Starter float64 `json:"start"`
	End     float64 `json:"end"`
	Text    string  `json:"text"`
	Prob    float64 `json:"prob"`
}

Word holds an ASR word.

type AdGeneration added in v1.1.11

type AdGeneration struct {
	GeneratedText string `json:"generated_text"`
}

AdGeneration holds the generated product description or ad returned by the API.

type AdGenerationParams added in v1.1.11

type AdGenerationParams struct {
	Keywords []string `json:"keywords"`
}

AdGenerationParams wraps all the parameters for the "ad-generation" endpoint.

type Arc

type Arc struct {
	Start int    `json:"start"`
	End   int    `json:"end"`
	Label string `json:"label"`
	Text  string `json:"text"`
	Dir   string `json:"dir"`
}

Arc holds information related to POS direction.

type Async added in v1.1.32

type Async struct {
	URL string `json:"url"`
}

Async holds the information returned when making an async request.

type AsyncResult added in v1.1.33

type AsyncResult struct {
	CreatedOn   time.Time `json:"created_on"`
	FinishedOn  time.Time `json:"finished_on"`
	RequestBody string    `json:"request_body"`
	HTTPCode    int       `json:"http_code"`
	ErrorDetail string    `json:"error_detail"`
	Content     string    `json:"content"`
}

type AsyncResultParams added in v1.1.33

type AsyncResultParams struct {
	URL string `json:"url"`
}

AsyncResultParams wraps all the parameters for the "async-result" endpoint.

type BatchClassification added in v1.1.18

type BatchClassification struct {
	Scores []float64 `json:"scores"`
}

BatchClassification holds a batch of scores returned by the API.

type BatchClassificationParams added in v1.1.18

type BatchClassificationParams struct {
	Texts  []string `json:"texts"`
	Labels []string `json:"labels"`
}

BatchClassificationParams wraps all the parameters for the "batch-classification" endpoint.

type BatchGeneration added in v1.1.39

type BatchGeneration struct {
	Generations []Generation `json:"generations"`
}

BatchGeneration holds a batch of generations returned by the API.

type BatchGenerationParams added in v1.1.39

type BatchGenerationParams struct {
	Texts []string `json:"texts"`
}

BatchGenerationParams wraps all the parameters for the "batch-generation" endpoint.

type BatchSummarization added in v1.1.7

type BatchSummarization struct {
	SummaryTexts []string `json:"summary_texts"`
}

BatchSummarization holds a batch of summarized texts returned by the API.

type BatchSummarizationParams added in v1.1.7

type BatchSummarizationParams struct {
	Texts []string `json:"texts"`
	Size  string   `json:"size"`
}

BatchSummarizationParams wraps all the parameters for the "batch-summarization" endpoint.

type BatchTranslation added in v1.1.15

type BatchTranslation struct {
	TranslationTexts []string `json:"translation_texts"`
}

BatchTranslation holds a batch of translated texts returned by the API.

type BatchTranslationParams added in v1.1.15

type BatchTranslationParams struct {
	Texts   []string  `json:"texts"`
	Sources *[]string `json:"sources,omitempty"`
	Targets *[]string `json:"targets,omitempty"`
}

BatchTranslationParams wraps all the parameters for the "batch-translation" endpoint.

type Chatbot added in v1.1.11

type Chatbot struct {
	Response string     `json:"response"`
	History  []Exchange `json:"history"`
}

Chatbot holds the chatbot response returned by the API.

type ChatbotParams added in v1.1.11

type ChatbotParams struct {
	Input   string      `json:"input"`
	History *[]Exchange `json:"history,omitempty"`
	Context *string     `json:"context,omitempty"`
}

ChatbotParams wraps all the parameters for the "chatbot" endpoint.

type Classification

type Classification struct {
	Labels []string  `json:"labels"`
	Scores []float64 `json:"scores"`
}

Classification holds the text classification returned by the API.

type ClassificationParams added in v1.1.0

type ClassificationParams struct {
	Text       string    `json:"text"`
	Labels     *[]string `json:"labels,omitempty"`
	MultiClass *bool     `json:"multi_class,omitempty"`
}

ClassificationParams wraps all the parameters for the "classification" endpoint.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client holds the necessary information to connect to API.

func NewClient

func NewClient(client HTTPClient, clientParams ClientParams) *Client

NewClient initializes a new Client.

func (*Client) ASR added in v1.1.25

func (c *Client) ASR(params ASRParams, opts ...Option) (*ASR, error)

ASR extracts text from an audio file by contacting the API.

func (*Client) AdGeneration added in v1.1.11

func (c *Client) AdGeneration(params AdGenerationParams, opts ...Option) (*AdGeneration, error)

AdGeneration generates a product description or an ad by contacting the API.

func (*Client) AsyncResult added in v1.1.33

func (c *Client) AsyncResult(params AsyncResultParams, opts ...Option) (*AsyncResult, error)

AsyncResult extracts gets an async result by contacting the API.

func (*Client) BatchClassification added in v1.1.18

func (c *Client) BatchClassification(params BatchClassificationParams, opts ...Option) (*BatchClassification, error)

BatchClassification classifies a batch of blocks of text by contacting the API.

func (*Client) BatchGeneration added in v1.1.39

func (c *Client) BatchGeneration(params BatchGenerationParams) (*BatchGeneration, error)

BatchGeneration generates a batch of blocks of text by contacting the API.

func (*Client) BatchSummarization added in v1.1.7

func (c *Client) BatchSummarization(params BatchSummarizationParams, opts ...Option) (*BatchSummarization, error)

BatchSummarization summarizes a batch of blocks of text by contacting the API.

func (*Client) BatchTranslation added in v1.1.15

func (c *Client) BatchTranslation(params BatchTranslationParams, opts ...Option) (*BatchTranslation, error)

BatchTranslation translates a batch of blocks of text by contacting the API.

func (*Client) Chatbot added in v1.1.11

func (c *Client) Chatbot(params ChatbotParams, opts ...Option) (*Chatbot, error)

Chatbot responds as a human by contacting the API.

func (*Client) Classification

func (c *Client) Classification(params ClassificationParams, opts ...Option) (*Classification, error)

Classification applies scored labels to a block of text by contacting the API.

func (*Client) CodeGeneration added in v1.1.20

func (c *Client) CodeGeneration(params CodeGenerationParams, opts ...Option) (*CodeGeneration, error)

CodeGeneration generates source code by contacting the API.

func (*Client) Dependencies

func (c *Client) Dependencies(params DependenciesParams, opts ...Option) (*Dependencies, error)

Dependencies gets POS dependencies from a block of text by contacting the API.

func (*Client) Embeddings added in v1.1.14

func (c *Client) Embeddings(params EmbeddingsParams, opts ...Option) (*Embeddings, error)

Embeddings extracts embeddings from a list of sentences by contacting the API.

func (*Client) Entities

func (c *Client) Entities(params EntitiesParams, opts ...Option) (*Entities, error)

Entities extracts entities from a block of text by contacting the API.

func (*Client) GSCorrection added in v1.1.11

func (c *Client) GSCorrection(params GSCorrectionParams, opts ...Option) (*GSCorrection, error)

GSCorrection corrects the grammar and spelling by contacting the API.

func (*Client) Generation added in v1.1.0

func (c *Client) Generation(params GenerationParams, opts ...Option) (*Generation, error)

Generation generates a block of text by contacting the API.

func (*Client) ImageGeneration added in v1.1.24

func (c *Client) ImageGeneration(params ImageGenerationParams, opts ...Option) (*ImageGeneration, error)

ImageGeneration generates an image out of a text instruction by contacting the API.

func (*Client) IntentClassification added in v1.1.11

func (c *Client) IntentClassification(params IntentClassificationParams, opts ...Option) (*IntentClassification, error)

IntentClassification classifies intent from a block of text by contacting the API.

func (*Client) KwKpExtraction added in v1.1.11

func (c *Client) KwKpExtraction(params KwKpExtractionParams, opts ...Option) (*KwKpExtraction, error)

AdGeneration generates a product description or an ad by contacting the API.

func (*Client) LangDetection added in v1.1.0

func (c *Client) LangDetection(params LangDetectionParams, opts ...Option) (*LangDetection, error)

LangDetection returns an estimation of the text language by contacting the API.

func (*Client) Paraphrasing added in v1.1.10

func (c *Client) Paraphrasing(params ParaphrasingParams, opts ...Option) (*Paraphrasing, error)

Paraphrasing paraphrases a block of text by contacting the API.

func (*Client) Question

func (c *Client) Question(params QuestionParams, opts ...Option) (*Question, error)

Question answers a question with a context by contacting the API.

func (*Client) SemanticSearch added in v1.1.27

func (c *Client) SemanticSearch(params SemanticSearchParams, opts ...Option) (*SemanticSearch, error)

SemanticSearch performs semantic search on custom data contacting the API.

func (*Client) SemanticSimilarity added in v1.1.14

func (c *Client) SemanticSimilarity(params SemanticSimilarityParams, opts ...Option) (*SemanticSimilarity, error)

SemanticSimilarity calculates a semantic similarity score out of 2 sentences by contacting the API.

func (*Client) SentenceDependencies

func (c *Client) SentenceDependencies(params SentenceDependenciesParams, opts ...Option) (*SentenceDependencies, error)

SentenceDependencies gets POS dependencies with arcs from a block of text by contacting the API.

func (*Client) Sentiment

func (c *Client) Sentiment(params SentimentParams, opts ...Option) (*Sentiment, error)

Sentiment defines the sentime of a block of text by contacting the API.

func (*Client) SpeechSynthesis added in v1.1.40

func (c *Client) SpeechSynthesis(params SpeechSynthesisParams, opts ...Option) (*SpeechSynthesis, error)

SpeechSynthesis generates audio out of a text by contacting the API.

func (*Client) StreamingChatbot added in v1.1.48

func (c *Client) StreamingChatbot(params ChatbotParams, opts ...Option) (io.ReadCloser, error)

StreamingChatbot responds as a human by contacting the API, and returns a stream.

func (*Client) StreamingGeneration added in v1.1.48

func (c *Client) StreamingGeneration(params GenerationParams, opts ...Option) (io.ReadCloser, error)

StreamingGeneration generates a block of text by contacting the API, and returns a stream.

func (*Client) Summarization

func (c *Client) Summarization(params SummarizationParams, opts ...Option) (*Summarization, error)

Summarization summarizes a block of text by contacting the API.

func (*Client) Tokens added in v1.1.0

func (c *Client) Tokens(params TokensParams, opts ...Option) (*Tokens, error)

Tokens tokenize and lemmatize text by calling the API.

func (*Client) Translation added in v1.0.9

func (c *Client) Translation(params TranslationParams, opts ...Option) (*Translation, error)

Translation translates a block of text by contacting the API.

type ClientParams added in v1.1.46

type ClientParams struct {
	Model string
	Token string
	GPU   bool
	Lang  string
	Async bool
}

ClientParams wraps all the parameters for the client initialization.

type CodeGeneration added in v1.1.20

type CodeGeneration struct {
	GeneratedCode string `json:"generated_code"`
}

CodeGeneration holds the generated code returned by the API.

type CodeGenerationParams added in v1.1.20

type CodeGenerationParams struct {
	Intruction string `json:"instruction"`
}

CodeGenerationParams wraps all the parameters for the "code-generation" endpoint.

type Dependencies

type Dependencies struct {
	Words []Word `json:"words"`
	Arcs  []Arc  `json:"arcs"`
}

Dependencies holds a list of POS dependencies returned by the API.

type DependenciesParams added in v1.1.0

type DependenciesParams struct {
	Text string `json:"text"`
}

DependenciesParams wraps all the parameters for the "dependencies" endpoint.

type Embeddings added in v1.1.14

type Embeddings struct {
	Embeddings [][]float64 `json:"embeddings"`
}

type EmbeddingsParams added in v1.1.14

type EmbeddingsParams struct {
	Sentences []string `json:"sentences"`
}

EmbeddingsParams wraps all the parameters for the "embeddings" endpoint.

type Entities

type Entities struct {
	Entities []Entity `json:"entities"`
}

Entities holds a list of NER entities returned by the API.

type EntitiesParams added in v1.1.0

type EntitiesParams struct {
	Text           string  `json:"text"`
	SearchedEntity *string `json:"searched_entity,omitempty"`
}

EntitiesParams wraps all the parameters for the "entities" endpoint.

type Entity

type Entity struct {
	Start int    `json:"start"`
	End   int    `json:"end"`
	Type  string `json:"type"`
	Text  string `json:"text"`
}

Entity holds an NER entity returned by the API.

type Exchange added in v1.1.11

type Exchange struct {
	Input    string `json:"input"`
	Response string `json:"response"`
}

type GSCorrection added in v1.1.11

type GSCorrection struct {
	Correction string `json:"correction"`
}

GSCorrection holds the corrected text returned by the API.

type GSCorrectionParams added in v1.1.11

type GSCorrectionParams struct {
	Text string `json:"text"`
}

GSCorrectionParams wraps all the parameters for the "gs-correction" endpoint.

type Generation added in v1.1.0

type Generation struct {
	GeneratedText     string `json:"generated_text"`
	NbGeneratedTokens int    `json:"nb_generated_tokens"`
	NbInputTokens     int    `json:"nb_input_tokens"`
}

Generation holds a generated text returned by the API.

type GenerationParams added in v1.1.0

type GenerationParams struct {
	Text               string    `json:"text"`
	MaxLength          *int      `json:"max_length,omitempty"`
	LengthNoInput      *bool     `json:"length_no_input,omitempty"`
	EndSequence        *string   `json:"end_sequence,omitempty"`
	RemoveInput        *bool     `json:"remove_input,omitempty"`
	NumBeams           *int      `json:"num_beams,omitempty"`
	NumReturnSequences *int      `json:"num_return_sequences,omitempty"`
	TopK               *int      `json:"top_k,omitempty"`
	TopP               *float64  `json:"top_p,omitempty"`
	Temperature        *float64  `json:"temperature,omitempty"`
	RepetitionPenalty  *float64  `json:"repetition_penalty,omitempty"`
	BadWords           *[]string `json:"bad_words,omitempty"`
	RemoveEndSequence  *bool     `json:"remove_end_sequence,omitempty"`
	// NoChatPrompt is experimental. It is not suited for production.
	NoChatPrompt *bool `json:"no_chat_prompt,omitempty"`
}

GenerationParams wraps all the parameters for the "generation" endpoint.

type HTTPClient added in v1.1.0

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient defines what a HTTP client have to implement in order to get used by the Client.

type HTTPError added in v1.1.5

type HTTPError struct {
	Detail string
	Status int
}

HTTPError is an error type returned when the HTTP request is failing.

func (HTTPError) Error added in v1.1.5

func (h HTTPError) Error() string

func (HTTPError) GetDetail added in v1.1.5

func (h HTTPError) GetDetail() string

func (HTTPError) GetStatusCode added in v1.1.5

func (h HTTPError) GetStatusCode() int

type ImageGeneration added in v1.1.24

type ImageGeneration struct {
	URL string `json:"url"`
}

ImageGeneration holds the generated image url returned by the API.

type ImageGenerationParams added in v1.1.24

type ImageGenerationParams struct {
	Text string `json:"text"`
}

ImageGenerationParams wraps all the parameters for the "image-generation" endpoint.

type IntentClassification added in v1.1.11

type IntentClassification struct {
	Intent string `json:"intent"`
}

IntentClassification holds the classified intent returned by the API.

type IntentClassificationParams added in v1.1.11

type IntentClassificationParams struct {
	Text string `json:"text"`
}

IntentClassificationParams wraps all the parameters for the "intent-classification" endpoint.

type KwKpExtraction added in v1.1.11

type KwKpExtraction struct {
	KeywordsAndKeyphrases []string `json:"keywords_and_keyphrases"`
}

KwKpExtraction holds the extracted keywords and keyphrases returned by the API.

type KwKpExtractionParams added in v1.1.11

type KwKpExtractionParams struct {
	Text string `json:"text"`
}

KwKpExtractionParams wraps all the parameters for the "kw-kp-extraction" endpoint.

type LangDetection added in v1.1.0

type LangDetection struct {
	Languages []map[string]float64 `json:"languages"`
}

LangDetection holds the languages of a text returned by the API.

type LangDetectionParams added in v1.1.0

type LangDetectionParams struct {
	// Text should not exceed 100.000 characters.
	Text string `json:"text"`
}

LangDetectionParams wraps all the parameters for the "langdetection" endpoint.

type Option added in v1.1.23

type Option interface {
	// contains filtered or unexported methods
}

func WithContext added in v1.1.23

func WithContext(ctx context.Context) Option

WithContext returns an Option that defines the context.Context to use with issuing a request. Default is context.Background.

type Paraphrasing added in v1.1.10

type Paraphrasing struct {
	ParaphrasedText string `json:"paraphrased_text"`
}

Paraphrasing holds a paraphrased text returned by the API.

type ParaphrasingParams added in v1.1.10

type ParaphrasingParams struct {
	Text string `json:"text"`
}

ParaphrasingParams wraps all the parameters for the "paraphrasing" endpoint.

type Question

type Question struct {
	Answer string  `json:"answer"`
	Score  float64 `json:"score"`
	Start  int     `json:"start"`
	End    int     `json:"end"`
}

Question holds the answer to a question by the API.

type QuestionParams added in v1.1.0

type QuestionParams struct {
	Question string  `json:"question"`
	Context  *string `json:"context,omitempty"`
}

QuestionParams wraps all the parameters for the "question" endpoint.

type ScoredLabel

type ScoredLabel struct {
	Label string  `json:"label"`
	Score float64 `json:"score"`
}

ScoredLabel holds a label and its score for sentiment analysis.

type SearchResult added in v1.1.27

type SearchResult struct {
	Score float64 `json:"score"`
	Text  string  `json:"text"`
}

SearchResult holds a search result from semantic search.

type Segment added in v1.1.31

type Segment struct {
	ID      int     `json:"id"`
	Starter float64 `json:"start"`
	End     float64 `json:"end"`
	Text    string  `json:"text"`
}

Segment holds an ASR segment.

type SemanticSearch added in v1.1.27

type SemanticSearch struct {
	SearchResults []SearchResult `json:"search_results"`
}

SemanticSearch holds semantic search results returned by the API.

type SemanticSearchParams added in v1.1.27

type SemanticSearchParams struct {
	Text       string `json:"text"`
	NumResults int    `json:"num_results"`
}

SemanticSearchParams wraps all the parameters for the "semantic-search" endpoint.

type SemanticSimilarity added in v1.1.14

type SemanticSimilarity struct {
	Score float64 `json:"score"`
}

SemanticSimilarity holds semantic similarity score returned by the API.

type SemanticSimilarityParams added in v1.1.14

type SemanticSimilarityParams struct {
	Sentences [2]string `json:"sentences"`
}

SemanticSimilarityParams wraps all the parameters for the "semantic-similarity" endpoint.

type SentenceDependencies

type SentenceDependencies struct {
	SentenceDependencies []SentenceDependency `json:"sentence_dependencies"`
}

SentenceDependencies holds a list of POS dependencies for several sentences returned by the API.

type SentenceDependenciesParams added in v1.1.0

type SentenceDependenciesParams struct {
	Text string `json:"text"`
}

SentenceDependenciesParams wraps all the parameters for the "sentence-dependencies" endpoint.

type SentenceDependency

type SentenceDependency struct {
	Sentence     string       `json:"sentence"`
	Dependencies Dependencies `json:"dependencies"`
}

SentenceDependency holds a POS dependency for one sentence returned by the API.

type Sentiment

type Sentiment struct {
	ScoredLabels []ScoredLabel `json:"scored_labels"`
}

Sentiment holds the sentiment of a text returned by the API.

type SentimentParams added in v1.1.0

type SentimentParams struct {
	Text   string  `json:"text"`
	Target *string `json:"target,omitempty"`
}

SentimentParams wraps all the parameters for the "sentiment" endpoint.

type SpeechSynthesis added in v1.1.40

type SpeechSynthesis struct {
	URL string `json:"url"`
}

SpeechSynthesis holds the generated audio file url returned by the API.

type SpeechSynthesisParams added in v1.1.40

type SpeechSynthesisParams struct {
	Text  string  `json:"text"`
	Voice *string `json:"voice"`
}

SpeechSynthesisParams wraps all the parameters for the "speech-synthesis" endpoint.

type Summarization

type Summarization struct {
	SummaryText string `json:"summary_text"`
}

Summarization holds a summarized text returned by the API.

type SummarizationParams added in v1.1.0

type SummarizationParams struct {
	Text string  `json:"text"`
	Size *string `json:"size"`
}

SummarizationParams wraps all the parameters for the "summarization" endpoint.

type Token added in v1.1.0

type Token struct {
	Text    string `json:"text"`
	Lemma   string `json:"lemma"`
	Start   int    `json:"start"`
	End     int    `json:"end"`
	Index   int    `json:"index"`
	WSAfter bool   `json:"ws_after"`
}

Token holds a token value from Tokens.

type Tokens added in v1.1.0

type Tokens struct {
	Tokens []Token `json:"tokens"`
}

Tokens holds a list of Token returned by the API.

type TokensParams added in v1.1.0

type TokensParams struct {
	Text string `json:"text"`
}

TokensParams wraps all the parameters for the "tokens" endpoint.

type Translation added in v1.0.9

type Translation struct {
	TranslationText string `json:"translation_text"`
}

Translation holds a translated text returned by the API.

type TranslationParams added in v1.1.0

type TranslationParams struct {
	Text   string  `json:"text"`
	Source *string `json:"source,omitempty"`
	Target *string `json:"target,omitempty"`
}

TranslationParams wraps all the parameters for the "translation" endpoint.

type Word

type Word struct {
	Text string `json:"text"`
	Tag  string `json:"tag"`
}

Word holds POS tag for a word.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL