0
# Chat Completions
1
2
Conversational AI interface supporting chat templates, tool calling, and multi-turn conversations with proper message formatting and context management. Provides OpenAI-compatible chat completion functionality.
3
4
## Capabilities
5
6
### Chat Interface
7
8
Generate responses in conversational format with support for system messages, user messages, assistant messages, and advanced features like tool calling.
9
10
```python { .api }
11
def chat(
12
self,
13
messages: List[ChatCompletionMessageParam],
14
chat_template: Optional[str] = None,
15
chat_template_content_format: ChatTemplateContentFormatOption = "auto",
16
add_generation_prompt: bool = True,
17
continue_final_message: bool = False,
18
tools: Optional[List[ChatCompletionToolParam]] = None,
19
documents: Optional[List[ChatCompletionDocumentParam]] = None,
20
mm_processor_kwargs: Optional[Dict[str, Any]] = None,
21
**kwargs: Any,
22
) -> List[ChatCompletionOutput]:
23
"""
24
Generate chat completions from conversation messages.
25
26
Parameters:
27
- messages: List of conversation messages with roles and content
28
- chat_template: Custom chat template for message formatting
29
- chat_template_content_format: Content format handling ("auto", "string", "openai")
30
- add_generation_prompt: Whether to add generation prompt
31
- continue_final_message: Continue from the last assistant message
32
- tools: Available tools for function calling
33
- documents: Context documents for retrieval
34
- mm_processor_kwargs: Multimodal processing arguments
35
36
Returns:
37
List of ChatCompletionOutput objects with generated responses
38
"""
39
```
40
41
## Usage Examples
42
43
### Basic Chat Conversation
44
45
```python
46
from vllm import LLM
47
48
llm = LLM(model="microsoft/DialoGPT-medium")
49
50
messages = [
51
{"role": "system", "content": "You are a helpful assistant."},
52
{"role": "user", "content": "What is the capital of France?"},
53
]
54
55
response = llm.chat(messages)
56
print(response[0].message.content)
57
```
58
59
## Types
60
61
```python { .api }
62
class ChatCompletionMessageParam:
63
role: str # "system", "user", "assistant"
64
content: str # Message content
65
66
class ChatCompletionOutput:
67
message: ChatMessage # Generated response
68
finish_reason: Optional[str] # Completion reason
69
```