Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 15,857 Bytes
422262e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
[](#chat-completion)Chat Completion
-----------------------------------
Generate a response given a list of messages in a conversational context, supporting both conversational Language Models (LLMs) and conversational Vision-Language Models (VLMs). This is a subtask of [`text-generation`](https://huggingface.co/docs/inference-providers/tasks/text-generation) and [`image-text-to-text`](https://huggingface.co/docs/inference-providers/tasks/image-text-to-text).
### [](#recommended-models)Recommended models
#### [](#conversational-large-language-models-llms)Conversational Large Language Models (LLMs)
* [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it): A text-generation model trained to follow instructions.
* [deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B): Smaller variant of one of the most powerful models.
* [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct): Very powerful text generation model trained to follow instructions.
* [microsoft/phi-4](https://huggingface.co/microsoft/phi-4): Powerful text generation model by Microsoft.
* [Qwen/Qwen2.5-7B-Instruct-1M](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct-1M): Strong conversational model that supports very long instructions.
* [Qwen/Qwen2.5-Coder-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct): Text generation model used to write code.
* [deepseek-ai/DeepSeek-R1](https://huggingface.co/deepseek-ai/DeepSeek-R1): Powerful reasoning based open large language model.
#### [](#conversational-vision-language-models-vlms)Conversational Vision-Language Models (VLMs)
* [Qwen/Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct): Strong image-text-to-text model.
Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=image-text-to-text&sort=trending).
### [](#api-playground)API Playground
For Chat Completion models, we provide an interactive UI Playground for easier testing:
* Quickly iterate on your prompts from the UI.
* Set and override system, assistant and user messages.
* Browse and select models currently available on the Inference API.
* Compare the output of two models side-by-side.
* Adjust requests parameters from the UI.
* Easily switch between UI view and code snippets.
[](https://huggingface.co/playground)
Access the Inference UI Playground and start exploring: [https://huggingface.co/playground](https://huggingface.co/playground)
### [](#using-the-api)Using the API
The API supports:
* Using the chat completion API compatible with the OpenAI SDK.
* Using grammars, constraints, and tools.
* Streaming the output
#### [](#code-snippet-example-for-conversational-llms)Code snippet example for conversational LLMs
Language
Python JavaScript cURL
Client
huggingface\_hub requests openai
Provider
Featherless Nscale
+9
Settings
Settings
Settings
Copied
import os
from huggingface\_hub import InferenceClient
client = InferenceClient(
provider="featherless-ai",
api\_key=os.environ\["HF\_TOKEN"\],
)
completion = client.chat.completions.create(
model="meta-llama/Llama-3.3-70B-Instruct",
messages=\[
{
"role": "user",
"content": "What is the capital of France?"
}
\],
)
print(completion.choices\[0\].message)
#### [](#code-snippet-example-for-conversational-vlms)Code snippet example for conversational VLMs
Language
Python JavaScript cURL
Client
huggingface\_hub requests openai
Provider
Fireworks Featherless
+10
Settings
Settings
Settings
Copied
import os
from huggingface\_hub import InferenceClient
client = InferenceClient(
provider="fireworks-ai",
api\_key=os.environ\["HF\_TOKEN"\],
)
completion = client.chat.completions.create(
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
messages=\[
{
"role": "user",
"content": \[
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image\_url",
"image\_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
\]
}
\],
)
print(completion.choices\[0\].message)
### [](#api-specification)API specification
#### [](#request)Request
Headers
**authorization**
_string_
Authentication header in the form `'Bearer: hf_****'` when `hf_****` is a personal user access token with “Inference Providers” permission. You can generate one from [your settings page](https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained).
Payload
**frequency\_penalty**
_number_
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.
**logprobs**
_boolean_
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.
**max\_tokens**
_integer_
The maximum number of tokens that can be generated in the chat completion.
**messages\***
_object\[\]_
A list of messages comprising the conversation so far.
**(#1)**
_unknown_
One of the following:
**(#1)**
_object_
**content\***
_unknown_
One of the following:
**(#1)**
_string_
**(#2)**
_object\[\]_
**(#1)**
_object_
**text\***
_string_
**type\***
_enum_
Possible values: text.
**(#2)**
_object_
**image\_url\***
_object_
**url\***
_string_
**type\***
_enum_
Possible values: image\_url.
**(#2)**
_object_
**tool\_calls\***
_object\[\]_
**function\***
_object_
**parameters\***
_unknown_
**description**
_string_
**name\***
_string_
**id\***
_string_
**type\***
_string_
**(#2)**
_object_
**name**
_string_
**role\***
_string_
**presence\_penalty**
_number_
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics
**response\_format**
_unknown_
One of the following:
**(#1)**
_object_
**type\***
_enum_
Possible values: text.
**(#2)**
_object_
**type\***
_enum_
Possible values: json\_schema.
**json\_schema\***
_object_
**name\***
_string_
The name of the response format.
**description**
_string_
A description of what the response format is for, used by the model to determine how to respond in the format.
**schema**
_object_
The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas [here](https://json-schema.org/).
**strict**
_boolean_
Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field.
**(#3)**
_object_
**type\***
_enum_
Possible values: json\_object.
**seed**
_integer_
**stop**
_string\[\]_
Up to 4 sequences where the API will stop generating further tokens.
**stream**
_boolean_
**stream\_options**
_object_
**include\_usage**
_boolean_
If set, an additional chunk will be streamed before the data: \[DONE\] message. The usage field on this chunk shows the token usage statistics for the entire request, and the choices field will always be an empty array. All other chunks will also include a usage field, but with a null value.
**temperature**
_number_
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
**tool\_choice**
_unknown_
One of the following:
**(#1)**
_enum_
Possible values: auto.
**(#2)**
_enum_
Possible values: none.
**(#3)**
_enum_
Possible values: required.
**(#4)**
_object_
**function\***
_object_
**name\***
_string_
**tool\_prompt**
_string_
A prompt to be appended before the tools
**tools**
_object\[\]_
A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
**function\***
_object_
**parameters\***
_unknown_
**description**
_string_
**name\***
_string_
**type\***
_string_
**top\_logprobs**
_integer_
An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.
**top\_p**
_number_
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top\_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
#### [](#response)Response
Output type depends on the `stream` input parameter. If `stream` is `false` (default), the response will be a JSON object with the following fields:
Body
**choices**
_object\[\]_
**finish\_reason**
_string_
**index**
_integer_
**logprobs**
_object_
**content**
_object\[\]_
**logprob**
_number_
**token**
_string_
**top\_logprobs**
_object\[\]_
**logprob**
_number_
**token**
_string_
**message**
_unknown_
One of the following:
**(#1)**
_object_
**content**
_string_
**role**
_string_
**tool\_call\_id**
_string_
**(#2)**
_object_
**role**
_string_
**tool\_calls**
_object\[\]_
**function**
_object_
**arguments**
_string_
**description**
_string_
**name**
_string_
**id**
_string_
**type**
_string_
**created**
_integer_
**id**
_string_
**model**
_string_
**system\_fingerprint**
_string_
**usage**
_object_
**completion\_tokens**
_integer_
**prompt\_tokens**
_integer_
**total\_tokens**
_integer_
If `stream` is `true`, generated tokens are returned as a stream, using Server-Sent Events (SSE). For more information about streaming, check out [this guide](https://huggingface.co/docs/text-generation-inference/conceptual/streaming).
Body
**choices**
_object\[\]_
**delta**
_unknown_
One of the following:
**(#1)**
_object_
**content**
_string_
**role**
_string_
**tool\_call\_id**
_string_
**(#2)**
_object_
**role**
_string_
**tool\_calls**
_object\[\]_
**function**
_object_
**arguments**
_string_
**name**
_string_
**id**
_string_
**index**
_integer_
**type**
_string_
**finish\_reason**
_string_
**index**
_integer_
**logprobs**
_object_
**content**
_object\[\]_
**logprob**
_number_
**token**
_string_
**top\_logprobs**
_object\[\]_
**logprob**
_number_
**token**
_string_
**created**
_integer_
**id**
_string_
**model**
_string_
**system\_fingerprint**
_string_
**usage**
_object_
**completion\_tokens**
_integer_
**prompt\_tokens**
_integer_
**total\_tokens**
_integer_
[< \> Update on GitHub](https://github.com/huggingface/hub-docs/blob/main/docs/inference-providers/tasks/chat-completion.md) |