Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Make Chat Completions Requests](#make-chat-completions-requests)
- [Without Streaming](#without-streaming)
- [With Streaming](#with-streaming)
- [DIAL-specific and Extended Parameters](#dial-specific-and-extended-parameters)
- [Working with Files](#working-with-files)
- [Working with URLs](#working-with-urls)
- [Uploading Files](#uploading-files)
Expand Down Expand Up @@ -464,6 +465,115 @@ ChatCompletionChunk(
)
```

#### DIAL-specific and Extended Parameters

Along with the standard OpenAI parameters, `chat.completions.create` accepts
the DIAL extensions and the newer OpenAI parameters:

```python
completion = client.chat.completions.create(
deployment_name="gpt-4o",
stream=False,
messages=[
# Messages support multi-modal content parts,
# the "developer" role and per-message cache breakpoints
{
"role": "developer",
"content": "Be brief",
"custom_fields": {"cache_breakpoint": {"expire_at": "1h"}},
},
{
"role": "user",
"content": [
{"type": "text", "text": "What is on the picture?"},
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.png"},
},
],
# DIAL attachments, stages and forms
"custom_content": {
"attachments": [
{"type": "image/png", "url": "files/bucket/image.png"}
]
},
},
],
tools=[
{
"type": "function",
"function": {"name": "get_weather", "parameters": {}, "strict": True},
"custom_fields": {"cache_breakpoint": {}},
},
# DIAL static tools, resolved by DIAL Core itself
{
"type": "static_function",
"static_function": {"name": "search", "configuration": {}},
},
],
tool_choice="required",
parallel_tool_calls=False,
reasoning_effort="high",
max_completion_tokens=1000,
response_format={
"type": "json_schema",
"json_schema": {"name": "answer", "schema": {"type": "object"}},
},
stream_options={"include_usage": True},
# DIAL-specific parameters
max_prompt_tokens=8000,
custom_fields={
"configuration": {},
"cache_breakpoint": {"expire_at": "5m"},
},
)
```

The response models cover the DIAL extensions as well:

```pycon
>>> completion.choices[0].message.custom_content
CustomContent(
stages=[
Stage(
index=None,
name='Thinking',
status='completed',
content='...',
attachments=None
)
],
attachments=None,
state=None,
form_value=None,
form_schema=None
)
>>> completion.usage
CompletionUsage(
prompt_tokens=11,
completion_tokens=1,
total_tokens=12,
prompt_tokens_details=PromptTokensDetails(
cached_tokens=8,
cache_write_tokens=3
),
completion_tokens_details=CompletionTokensDetails(reasoning_tokens=1)
)
>>> completion.statistics
Statistics(
usage_per_model=[
UsagePerModel(
index=0,
model='gpt-4o',
prompt_tokens=11,
completion_tokens=1,
total_tokens=12
)
],
discarded_messages=[0, 1]
)
```

### Working with Files

#### Working with URLs
Expand Down
110 changes: 92 additions & 18 deletions aidial_client/resources/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
FunctionCallSpecParam,
FunctionParam,
Message,
ReasoningEffort,
ResponseFormat,
StaticToolParam,
StreamOptions,
ToolCallSpecParam,
ToolParam,
)
Expand All @@ -51,19 +55,26 @@ def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
Expand All @@ -86,19 +97,26 @@ def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
Expand All @@ -120,19 +138,26 @@ def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
Expand Down Expand Up @@ -165,11 +190,24 @@ def create(
"tools": tools,
"top_p": top_p,
"user": user,
"max_prompt_tokens": max_prompt_tokens,
"custom_fields": custom_fields,
"logprobs": logprobs,
"top_logprobs": top_logprobs,
"extra_body": extra_body,
# DIAL-specific parameters and the ones which aren't supported
# by every openai version are sent in the request body directly
"extra_body": {
**remove_none(
{
"max_prompt_tokens": max_prompt_tokens,
"custom_fields": custom_fields,
"max_completion_tokens": max_completion_tokens,
"parallel_tool_calls": parallel_tool_calls,
"reasoning_effort": reasoning_effort,
"response_format": response_format,
"stream_options": stream_options,
}
),
**extra_body,
},
"extra_query": {
"api-version": (
api_version or self.default_api_version or Omit()
Expand Down Expand Up @@ -217,20 +255,29 @@ async def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
# Extra params
extra_body: dict[str, Any] | None = None,
extra_headers: Mapping[StrictStr, StrictStr] | None = None,
Expand All @@ -250,19 +297,26 @@ async def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
Expand All @@ -284,19 +338,26 @@ async def create(
function_call: Literal["none", "auto"]
| FunctionCallSpecParam
| None = None,
tools: list[ToolParam] | None = None,
tool_choice: Literal["none", "auto"] | ToolCallSpecParam | None = None,
tools: list[ToolParam | StaticToolParam] | None = None,
tool_choice: Literal["none", "auto", "required"]
| ToolCallSpecParam
| None = None,
parallel_tool_calls: bool | None = None,
temperature: float | None = None,
top_p: float | None = None,
n: int | None = None,
stop: str | list[str] | None = None,
max_tokens: int | None = None,
max_completion_tokens: int | None = None,
max_prompt_tokens: Literal["infinity"] | int | None = None,
presence_penalty: float | None = None,
frequency_penalty: float | None = None,
logit_bias: dict | None = None,
seed: int | None = None,
user: str | None = None,
reasoning_effort: ReasoningEffort | None = None,
response_format: ResponseFormat | None = None,
stream_options: StreamOptions | None = None,
custom_fields: ChatCompletionRequestCustomFields | None = None,
logprobs: bool | None = None,
top_logprobs: int | None = None,
Expand Down Expand Up @@ -329,11 +390,24 @@ async def create(
"tools": tools,
"top_p": top_p,
"user": user,
"max_prompt_tokens": max_prompt_tokens,
"custom_fields": custom_fields,
"logprobs": logprobs,
"top_logprobs": top_logprobs,
"extra_body": extra_body,
# DIAL-specific parameters and the ones which aren't supported
# by every openai version are sent in the request body directly
"extra_body": {
**remove_none(
{
"max_prompt_tokens": max_prompt_tokens,
"custom_fields": custom_fields,
"max_completion_tokens": max_completion_tokens,
"parallel_tool_calls": parallel_tool_calls,
"reasoning_effort": reasoning_effort,
"response_format": response_format,
"stream_options": stream_options,
}
),
**extra_body,
},
"extra_query": {
"api-version": (
api_version or self.default_api_version or Omit()
Expand Down
Loading
Loading