github.com/instill-ai/component@v0.16.0-beta/pkg/connector/huggingface/v0/structs.go (about) 1 package huggingface 2 3 // Request structure for text-to-image model 4 type TextToImageRequest struct { 5 // The prompt or prompts to guide the image generation. 6 Inputs string `json:"inputs"` 7 Options Options `json:"options,omitempty"` 8 Parameters TextToImageRequestParameters `json:"parameters,omitempty"` 9 } 10 11 type Options struct { 12 // (Default: false). Boolean to use GPU instead of CPU for inference. 13 // Requires Startup plan at least. 14 UseGPU *bool `json:"use_gpu,omitempty"` 15 // (Default: true). There is a cache layer on the inference API to speedup 16 // requests we have already seen. Most models can use those results as is 17 // as models are deterministic (meaning the results will be the same anyway). 18 // However if you use a non deterministic model, you can set this parameter 19 // to prevent the caching mechanism from being used resulting in a real new query. 20 UseCache *bool `json:"use_cache,omitempty"` 21 // (Default: false) If the model is not ready, wait for it instead of receiving 503. 22 // It limits the number of requests required to get your inference done. It is advised 23 // to only set this flag to true after receiving a 503 error as it will limit hanging 24 // in your application to known places. 25 WaitForModel *bool `json:"wait_for_model,omitempty"` 26 } 27 28 type TextToImageRequestParameters struct { 29 // The prompt or prompts not to guide the image generation. 30 // Ignored when not using guidance (i.e., ignored if guidance_scale is less than 1). 31 NegativePrompt string `json:"negative_prompt,omitempty"` 32 // The height in pixels of the generated image. 33 Height int64 `json:"height,omitempty"` 34 // The width in pixels of the generated image. 35 Width int64 `json:"width,omitempty"` 36 // The number of denoising steps. More denoising steps usually lead to a higher quality 37 // image at the expense of slower inference. Defaults to 50. 38 NumInferenceSteps int64 `json:"num_inference_steps,omitempty"` 39 // Higher guidance scale encourages to generate images that are closely linked to the text 40 // input, usually at the expense of lower image quality. Defaults to 7.5. 41 GuidanceScale float64 `json:"guidance_scale,omitempty"` 42 } 43 44 // Request structure for the Fill Mask endpoint 45 type FillMaskRequest struct { 46 // (Required) a string to be filled from, must contain the [MASK] token (check model card for exact name of the mask) 47 Inputs string `json:"inputs,omitempty"` 48 Options Options `json:"options,omitempty"` 49 } 50 51 // Request structure for the summarization endpoint 52 type SummarizationRequest struct { 53 // String to be summarized 54 Inputs string `json:"inputs"` 55 Parameters SummarizationParameters `json:"parameters,omitempty"` 56 Options Options `json:"options,omitempty"` 57 } 58 59 // Used with SummarizationRequest 60 type SummarizationParameters struct { 61 // (Default: None). Integer to define the minimum length in tokens of the output summary. 62 MinLength *int `json:"min_length,omitempty"` 63 64 // (Default: None). Integer to define the maximum length in tokens of the output summary. 65 MaxLength *int `json:"max_length,omitempty"` 66 67 // (Default: None). Integer to define the top tokens considered within the sample operation to create 68 // new text. 69 TopK *int `json:"top_k,omitempty"` 70 71 // (Default: None). Float to define the tokens that are within the sample` operation of text generation. 72 // Add tokens in the sample for more probable to least probable until the sum of the probabilities is 73 // greater than top_p. 74 TopP *float64 `json:"top_p,omitempty"` 75 76 // (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 77 // 0 mens top_k=1, 100.0 is getting closer to uniform probability. 78 Temperature *float64 `json:"temperature,omitempty"` 79 80 // (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized 81 // to not be picked in successive generation passes. 82 RepetitionPenalty *float64 `json:"repetitionpenalty,omitempty"` 83 84 // (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. 85 // Network can cause some overhead so it will be a soft limit. 86 MaxTime *float64 `json:"maxtime,omitempty"` 87 } 88 89 // Response structure for the summarization endpoint 90 type SummarizationResponse struct { 91 // The summarized input string 92 SummaryText string `json:"summary_text,omitempty"` 93 } 94 95 // Request structure for the Text classification endpoint 96 type TextClassificationRequest struct { 97 //String to be classified 98 Inputs string `json:"inputs"` 99 Options Options `json:"options,omitempty"` 100 } 101 102 type TextGenerationRequest struct { 103 // (Required) a string to be generated from 104 Inputs string `json:"inputs"` 105 Parameters TextGenerationParameters `json:"parameters,omitempty"` 106 Options Options `json:"options,omitempty"` 107 } 108 109 type TextGenerationResponse struct { 110 GeneratedText string `json:"generated_text,omitempty"` 111 } 112 113 type TextGenerationParameters struct { 114 // (Default: None). Integer to define the top tokens considered within the sample operation to create new text. 115 TopK *int `json:"top_k,omitempty"` 116 117 // (Default: None). Float to define the tokens that are within the sample` operation of text generation. Add 118 // tokens in the sample for more probable to least probable until the sum of the probabilities is greater 119 // than top_p. 120 TopP *float64 `json:"top_p,omitempty"` 121 122 // (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 123 // 0 means top_k=1, 100.0 is getting closer to uniform probability. 124 Temperature *float64 `json:"temperature,omitempty"` 125 126 // (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized 127 // to not be picked in successive generation passes. 128 RepetitionPenalty *float64 `json:"repetition_penalty,omitempty"` 129 130 // (Default: None). Int (0-250). The amount of new tokens to be generated, this does not include the input 131 // length it is a estimate of the size of generated text you want. Each new tokens slows down the request, 132 // so look for balance between response times and length of text generated. 133 MaxNewTokens *int `json:"max_new_tokens,omitempty"` 134 135 // (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. 136 // Network can cause some overhead so it will be a soft limit. Use that in combination with max_new_tokens 137 // for best results. 138 MaxTime *float64 `json:"max_time,omitempty"` 139 140 // (Default: True). Bool. If set to False, the return results will not contain the original query making it 141 // easier for prompting. 142 ReturnFullText *bool `json:"return_full_text,omitempty"` 143 144 // (Default: 1). Integer. The number of proposition you want to be returned. 145 NumReturnSequences *int `json:"num_return_sequences,omitempty"` 146 } 147 148 // Request structure for the token classification endpoint 149 type TokenClassificationRequest struct { 150 // (Required) strings to be classified 151 Inputs string `json:"inputs"` 152 Parameters TokenClassificationParameters `json:"parameters,omitempty"` 153 Options Options `json:"options,omitempty"` 154 } 155 156 type TokenClassificationParameters struct { 157 // (Default: simple) 158 AggregationStrategy string `json:"aggregation_strategy,omitempty"` 159 } 160 161 // Request structure for the Translation endpoint 162 type TranslationRequest struct { 163 // (Required) a string to be translated in the original languages 164 Inputs string `json:"inputs"` 165 166 Options Options `json:"options,omitempty"` 167 } 168 169 // Response structure from the Translation endpoint 170 type TranslationResponse struct { 171 // The translated Input string 172 TranslationText string `json:"translation_text,omitempty"` 173 } 174 175 type ZeroShotRequest struct { 176 // (Required) 177 Inputs string `json:"inputs"` 178 179 // (Required) 180 Parameters ZeroShotParameters `json:"parameters"` 181 182 Options Options `json:"options,omitempty"` 183 } 184 185 // Used with ZeroShotRequest 186 type ZeroShotParameters struct { 187 // (Required) A list of strings that are potential classes for inputs. Max 10 candidate_labels, 188 // for more, simply run multiple requests, results are going to be misleading if using 189 // too many candidate_labels anyway. If you want to keep the exact same, you can 190 // simply run multi_label=True and do the scaling on your end. 191 CandidateLabels []string `json:"candidate_labels"` 192 193 // (Default: false) Boolean that is set to True if classes can overlap 194 MultiLabel *bool `json:"multi_label,omitempty"` 195 } 196 197 // Response structure from the Zero-shot classification endpoint. 198 type ZeroShotResponse struct { 199 // The string sent as an input 200 Sequence string `json:"sequence,omitempty"` 201 202 // The list of labels sent in the request, sorted in descending order 203 // by probability that the input corresponds to the to the label. 204 Labels []string `json:"labels,omitempty"` 205 206 // a list of floats that correspond the the probability of label, in the same order as labels. 207 Scores []float64 `json:"scores,omitempty"` 208 } 209 210 type FeatureExtractionRequest struct { 211 // (Required) 212 Inputs string `json:"inputs"` 213 214 Options Options `json:"options,omitempty"` 215 } 216 217 // Request structure for question answering model 218 type QuestionAnsweringRequest struct { 219 // (Required) 220 Inputs QuestionAnsweringInputs `json:"inputs"` 221 Options Options `json:"options,omitempty"` 222 } 223 224 type QuestionAnsweringInputs struct { 225 // (Required) The question as a string that has an answer within Context. 226 Question string `json:"question"` 227 228 // (Required) A string that contains the answer to the question 229 Context string `json:"context"` 230 } 231 232 // Response structure for question answering model 233 type QuestionAnsweringResponse struct { 234 // A string that’s the answer within the Context text. 235 Answer string `json:"answer,omitempty"` 236 237 // A float that represents how likely that the answer is correct. 238 Score float64 `json:"score,omitempty"` 239 240 // The string index of the start of the answer within Context. 241 Start int `json:"start,omitempty"` 242 243 // The string index of the stop of the answer within Context. 244 Stop int `json:"stop,omitempty"` 245 } 246 247 // Request structure for table question answering model 248 type TableQuestionAnsweringRequest struct { 249 Inputs TableQuestionAnsweringInputs `json:"inputs"` 250 Options Options `json:"options,omitempty"` 251 } 252 253 type TableQuestionAnsweringInputs struct { 254 // (Required) The query in plain text that you want to ask the table 255 Query string `json:"query"` 256 257 // (Required) A table of data represented as a dict of list where entries 258 // are headers and the lists are all the values, all lists must 259 // have the same size. 260 Table map[string][]string `json:"table"` 261 } 262 263 // Response structure for table question answering model 264 type TableQuestionAnsweringResponse struct { 265 // The plaintext answer 266 Answer string `json:"answer,omitempty"` 267 268 // A list of coordinates of the cells references in the answer 269 Coordinates [][]int `json:"coordinates,omitempty"` 270 271 // A list of coordinates of the cells contents 272 Cells []string `json:"cells,omitempty"` 273 274 // The aggregator used to get the answer 275 Aggregator string `json:"aggregator,omitempty"` 276 } 277 278 // Request structure for the Sentence Similarity endpoint. 279 type SentenceSimilarityRequest struct { 280 // (Required) Inputs for the request. 281 Inputs SentenceSimilarityInputs `json:"inputs"` 282 Options Options `json:"options,omitempty"` 283 } 284 285 type SentenceSimilarityInputs struct { 286 // (Required) The string that you wish to compare the other strings with. 287 // This can be a phrase, sentence, or longer passage, depending on the 288 // model being used. 289 SourceSentence string `json:"source_sentence"` 290 291 // A list of strings which will be compared against the source_sentence. 292 Sentences []string `json:"sentences"` 293 } 294 295 // Request structure for the conversational endpoint 296 type ConversationalRequest struct { 297 // (Required) 298 Inputs ConversationalInputs `json:"inputs"` 299 300 Parameters ConversationalParameters `json:"parameters,omitempty"` 301 Options Options `json:"options,omitempty"` 302 } 303 304 // Used with ConversationalRequest 305 type ConversationalInputs struct { 306 // (Required) The last input from the user in the conversation. 307 Text string `json:"text"` 308 309 // A list of strings corresponding to the earlier replies from the model. 310 GeneratedResponses []string `json:"generated_responses,omitempty"` 311 312 // A list of strings corresponding to the earlier replies from the user. 313 // Should be of the same length of GeneratedResponses. 314 PastUserInputs []string `json:"past_user_inputs,omitempty"` 315 } 316 317 // Used with ConversationalRequest 318 type ConversationalParameters struct { 319 // (Default: None). Integer to define the minimum length in tokens of the output summary. 320 MinLength *int `json:"min_length,omitempty"` 321 322 // (Default: None). Integer to define the maximum length in tokens of the output summary. 323 MaxLength *int `json:"max_length,omitempty"` 324 325 // (Default: None). Integer to define the top tokens considered within the sample operation to create 326 // new text. 327 TopK *int `json:"top_k,omitempty"` 328 329 // (Default: None). Float to define the tokens that are within the sample` operation of text generation. 330 // Add tokens in the sample for more probable to least probable until the sum of the probabilities is 331 // greater than top_p. 332 TopP *float64 `json:"top_p,omitempty"` 333 334 // (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 335 // 0 mens top_k=1, 100.0 is getting closer to uniform probability. 336 Temperature *float64 `json:"temperature,omitempty"` 337 338 // (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized 339 // to not be picked in successive generation passes. 340 RepetitionPenalty *float64 `json:"repetition_penalty,omitempty"` 341 342 // (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. 343 // Network can cause some overhead so it will be a soft limit. 344 MaxTime *float64 `json:"maxtime,omitempty"` 345 } 346 347 type ImageRequest struct { 348 Image string `json:"image"` 349 } 350 351 type ImageSegmentationResponse struct { 352 // The label for the class (model specific) of a segment. 353 Label string `json:"label,omitempty"` 354 355 // A float that represents how likely it is that the segment belongs to the given class. 356 Score float64 `json:"score,omitempty"` 357 358 // A str (base64 str of a single channel black-and-white img) representing the mask of a segment. 359 Mask string `json:"mask,omitempty"` 360 } 361 362 type ObjectBox struct { 363 XMin int `json:"xmin,omitempty"` 364 YMin int `json:"ymin,omitempty"` 365 XMax int `json:"xmax,omitempty"` 366 YMax int `json:"ymax,omitempty"` 367 } 368 369 type ImageToTextResponse struct { 370 // The generated caption 371 GeneratedText string `json:"generated_text"` 372 } 373 374 type AudioRequest struct { 375 Audio string `json:"audio"` 376 } 377 378 type SpeechRecognitionResponse struct { 379 // The string that was recognized within the audio file. 380 Text string `json:"text,omitempty"` 381 }