Skip to content

Commit 4a83a61

Browse files
bibryamMyMirelHub
authored andcommitted
Updated conversation api docs to latest alpha v2, refresh sample request, add metadata, remove redundant fields like name, fixes #4687
Signed-off-by: Bilgin Ibryam <[email protected]>
1 parent 66084d5 commit 4a83a61

File tree

2 files changed

+167
-111
lines changed

2 files changed

+167
-111
lines changed

daprdocs/content/en/developing-applications/building-blocks/conversation/conversation-overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ In addition to enabling critical performance and security functionality (like [p
2020
- **OpenAI-compatible interface** for seamless integration with existing AI workflows and tools
2121

2222
You can also pair the conversation API with Dapr functionalities, like:
23-
- Resiliency circuit breakers and retries to circumvent limit and token errors, or
24-
- Middleware to authenticate requests coming to and from the LLM
2523

26-
Dapr provides observability by issuing metrics for your LLM interactions.
24+
- Resiliency policies including circuit breakers to handle repeated errors, timeouts to safeguards from slow responses, and retries for temporary network failures
25+
- Observability with metrics and distributed tracing using OpenTelemetry and Zipkin
26+
- Middleware to authenticate requests to and from the LLM
2727

2828
## Features
2929

@@ -67,7 +67,7 @@ Watch the demo presented during [Diagrid's Dapr v1.15 celebration](https://www.d
6767

6868
{{< youtube id=NTnwoDhHIcQ start=5444 >}}
6969

70-
## Try out conversation
70+
## Try out conversation API
7171

7272
### Quickstarts and tutorials
7373

daprdocs/content/en/reference/api/conversation_api.md

Lines changed: 163 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The conversation API is currently in [alpha]({{% ref "certification-lifecycle.md
1212

1313
Dapr provides an API to interact with Large Language Models (LLMs) and enables critical performance and security functionality with features like prompt caching, PII data obfuscation, and tool calling capabilities.
1414

15-
Tool calling follow's OpenAI's function calling format, making it easy to integrate with existing AI development workflows and tools.
15+
Tool calling follows OpenAI's function calling format, making it easy to integrate with existing AI development workflows and tools.
1616

1717
## Converse
1818

@@ -32,32 +32,34 @@ POST http://localhost:<daprPort>/v1.0-alpha2/conversation/<llm-name>/converse
3232

3333
| Field | Description |
3434
| --------- | ----------- |
35-
| `name` | The name of the conversation component. Required |
36-
| `contextId` | The ID of an existing chat (like in ChatGPT). Optional |
35+
| `context_id` | The ID of an existing chat (like in ChatGPT). Optional |
3736
| `inputs` | Inputs for the conversation. Multiple inputs at one time are supported. Required |
3837
| `parameters` | Parameters for all custom fields. Optional |
39-
| `metadata` | [Metadata](#metadata) passed to conversation components. Optional |
40-
| `scrubPii` | A boolean value to enable obfuscation of sensitive information returning from the LLM. Optional |
38+
| `metadata` | Metadata passed to conversation components. Optional |
39+
| `scrub_pii` | A boolean value to enable obfuscation of sensitive information returning from the LLM. Optional |
4140
| `temperature` | A float value to control the temperature of the model. Used to optimize for consistency (0) or creativity (1). Optional |
4241
| `tools` | Tools register the tools available to be used by the LLM during the conversation. Optional |
43-
| `toolChoice` | Controls which (if any) tool is called by the model. Values: `auto`, `required`, or specific tool name. Defaults to `auto` if tools are present. Optional |
42+
| `tool_choice` | Controls which (if any) tool is called by the model. Values: `auto`, `required`, or specific tool name. Defaults to `auto` if tools are present. Optional |
4443

4544
#### Input body
4645

4746
| Field | Description |
4847
| --------- | ----------- |
4948
| `messages` | Array of conversation messages. Required |
50-
| `scrubPii` | A boolean value to enable obfuscation of sensitive information present in the content field. Optional |
49+
| `scrub_pii` | A boolean value to enable obfuscation of sensitive information present in the content field. Optional |
5150

5251
#### Message types
5352

5453
The API supports different message types:
5554

56-
- **`ofDeveloper`**: Developer role messages with optional name and content
57-
- **`ofSystem`**: System role messages with optional name and content
58-
- **`ofUser`**: User role messages with optional name and content
59-
- **`ofAssistant`**: Assistant role messages with optional name, content, and tool calls
60-
- **`ofTool`**: Tool role messages with tool ID, name, and content
55+
| Type | Description |
56+
| ---- | ----------- |
57+
| `of_developer` | Developer role messages with optional name and content |
58+
| `of_system` | System role messages with optional name and content |
59+
| `of_user` | User role messages with optional name and content |
60+
| `of_assistant` | Assistant role messages with optional name, content, and tool calls |
61+
| `of_tool` | Tool role messages with tool ID, name, and content |
62+
6163

6264
#### Tool calling
6365

@@ -69,81 +71,136 @@ Tools can be defined using the `tools` field with function definitions:
6971
| `function.description` | A description of what the function does. Optional |
7072
| `function.parameters` | JSON Schema object describing the function parameters. Optional |
7173

74+
75+
#### Tool choice options
76+
77+
The `tool_choice` is an optional parameter that controls how the model can use available tools:
78+
79+
- **`auto`**: The model can pick between generating a message or calling one or more tools (default when tools are present)
80+
- **`required`**: Requires one or more functions to be called
81+
- **`{tool_name}`**: Forces the model to call a specific tool by name
82+
83+
84+
#### Metadata
85+
The `metadata` field serves as a dynamic configuration mechanism that allows you to pass additional configuration and authentication information to conversation components on a per-request basis. This metadata overrides any corresponding fields configured in the component's YAML configuration file, enabling dynamic configuration without modifying static component definitions.
86+
87+
**Common metadata fields:**
88+
89+
| Field | Description | Example |
90+
| ----- | ----------- | ------- |
91+
| `api_key` | API key for authenticating with the LLM service | `"sk-1234567890abcdef"` |
92+
| `model` | Specific model identifier | `"gpt-4-turbo"`, `"claude-3-sonnet"` |
93+
| `version` | API version or service version | `"1.0"`, `"2023-12-01"` |
94+
| `endpoint` | Custom endpoint URL for the service | `"https://api.custom-llm.com/v1"` |
95+
96+
{{% alert title="Note" color="primary" %}}
97+
The exact metadata fields supported depend on the specific conversation component implementation. Refer to the component's documentation for the complete list of supported metadata fields.
98+
{{% /alert %}}
99+
100+
In addition to passing metadata in the request body, you can also pass metadata as URL query parameters without modifying the request payload. Here is the format:
101+
102+
- **Prefix**: All metadata parameters must be prefixed with `metadata.`
103+
- **Format**: `?metadata.<field_name>=<value>`
104+
- **Multiple parameters**: Separate with `&` (e.g., `?metadata.api_key=sk-123&metadata.model=gpt-4`)
105+
106+
Example of model override:
107+
```bash
108+
POST http://localhost:3500/v1.0-alpha2/conversation/openai/converse?metadata.model=sk-gpt-4-turbo
109+
```
110+
111+
URL metadata parameters are merged with request body metadata, URL parameters take precedence if conflicts exist, and both override component configuration in the YAML file.
112+
72113
### Request content examples
73114

74115
#### Basic conversation
75116

76117
```json
77-
REQUEST = {
78-
"name": "openai",
79-
"inputs": [{
80-
"messages": [{
81-
"of_user": {
82-
"content": [{
83-
"text": "What is Dapr?"
84-
}]
85-
}
86-
}]
87-
}],
88-
"parameters": {},
89-
"metadata": {}
90-
}
118+
curl -X POST http://localhost:3500/v1.0-alpha2/conversation/openai/converse \
119+
-H "Content-Type: application/json" \
120+
-d '{
121+
"inputs": [
122+
{
123+
"messages": [
124+
{
125+
"of_user": {
126+
"content": [
127+
{
128+
"text": "What is Dapr?"
129+
}
130+
]
131+
}
132+
}
133+
]
134+
}
135+
],
136+
"parameters": {},
137+
"metadata": {}
138+
}'
91139
```
92140

93141
#### Conversation with tool calling
94142

95143
```json
96-
{
97-
"name": "openai",
98-
"inputs": [{
99-
"messages": [{
100-
"of_user": {
101-
"content": [{
102-
"text": "What is the weather like in San Francisco in celsius?"
103-
}]
104-
}
105-
}],
106-
"scrub_pii": false
107-
}],
108-
"parameters": {
109-
"max_tokens": {
110-
"@type": "type.googleapis.com/google.protobuf.Int64Value",
111-
"value": "100"
112-
},
113-
"model": {
114-
"@type": "type.googleapis.com/google.protobuf.StringValue",
115-
"value": "claude-3-5-sonnet-20240620"
116-
}
117-
},
118-
"metadata": {
119-
"api_key": "test-key",
120-
"version": "1.0"
121-
},
122-
"scrub_pii": false,
123-
"temperature": 0.7,
124-
"tools": [{
125-
"function": {
126-
"name": "get_weather",
127-
"description": "Get the current weather for a location",
128-
"parameters": {
129-
"type": "object",
130-
"properties": {
131-
"location": {
132-
"type": "string",
133-
"description": "The city and state, e.g. San Francisco, CA"
144+
curl -X POST http://localhost:3500/v1.0-alpha2/conversation/openai/converse \
145+
-H "Content-Type: application/json" \
146+
-d '{
147+
"inputs": [
148+
{
149+
"messages": [
150+
{
151+
"of_user": {
152+
"content": [
153+
{
154+
"text": "What is the weather like in San Francisco in celsius?"
155+
}
156+
]
157+
}
158+
}
159+
],
160+
"scrub_pii": false
161+
}
162+
],
163+
"parameters": {
164+
"max_tokens": {
165+
"@type": "type.googleapis.com/google.protobuf.Int64Value",
166+
"value": "100"
134167
},
135-
"unit": {
136-
"type": "string",
137-
"enum": ["celsius", "fahrenheit"],
138-
"description": "The temperature unit to use"
168+
"model": {
169+
"@type": "type.googleapis.com/google.protobuf.StringValue",
170+
"value": "claude-3-5-sonnet-20240620"
139171
}
140172
},
141-
"required": ["location"]
142-
}
143-
}
144-
}],
145-
"tool_choice": "auto"
146-
}
173+
"metadata": {
174+
"api_key": "test-key",
175+
"version": "1.0"
176+
},
177+
"scrub_pii": false,
178+
"temperature": 0.7,
179+
"tools": [
180+
{
181+
"function": {
182+
"name": "get_weather",
183+
"description": "Get the current weather for a location",
184+
"parameters": {
185+
"type": "object",
186+
"properties": {
187+
"location": {
188+
"type": "string",
189+
"description": "The city and state, e.g. San Francisco, CA"
190+
},
191+
"unit": {
192+
"type": "string",
193+
"enum": ["celsius", "fahrenheit"],
194+
"description": "The temperature unit to use"
195+
}
196+
},
197+
"required": ["location"]
198+
}
199+
}
200+
}
201+
],
202+
"tool_choice": "auto"
203+
}'
147204
```
148205

149206
### HTTP response codes
@@ -159,50 +216,49 @@ Code | Description
159216
#### Basic conversation response
160217

161218
```json
162-
RESPONSE = {
163-
"outputs": [{
164-
"choices": [{
165-
"finish_reason": "stop",
166-
"index": 0,
167-
"message": {
168-
"content": "Dapr is a distributed application runtime that makes it easy for developers to build resilient, stateless and stateful applications that run on the cloud and edge.",
169-
"tool_calls": []
170-
}
171-
}]
172-
}]
219+
{
220+
"outputs": [
221+
{
222+
"choices": [
223+
{
224+
"finishReason": "stop",
225+
"message": {
226+
"content": "Distributed application runtime, open-source."
227+
}
228+
}
229+
]
230+
}
231+
]
173232
}
174233
```
175234

176235
#### Tool calling response
177236

178237
```json
179238
{
180-
"outputs": [{
181-
"choices": [{
182-
"finish_reason": "tool_calls",
183-
"index": 0,
184-
"message": {
185-
"content": null,
186-
"tool_calls": [{
187-
"id": "call_123",
188-
"function": {
189-
"name": "get_weather",
190-
"arguments": "{\"location\": \"San Francisco, CA\", \"unit\": \"celsius\"}"
239+
"outputs": [
240+
{
241+
"choices": [
242+
{
243+
"finishReason": "tool_calls",
244+
"message": {
245+
"toolCalls": [
246+
{
247+
"id": "call_Uwa41pG0UqGA2zp0Fec0KwOq",
248+
"function": {
249+
"name": "get_weather",
250+
"arguments": "{\"location\":\"San Francisco, CA\",\"unit\":\"celsius\"}"
251+
}
252+
}
253+
]
191254
}
192-
}]
193-
}
194-
}]
195-
}]
255+
}
256+
]
257+
}
258+
]
196259
}
197260
```
198261

199-
### Tool choice options
200-
201-
The `tool_choice` is an optional parameter that controls how the model can use available tools:
202-
203-
- **`auto`**: The model can pick between generating a message or calling one or more tools (default when tools are present)
204-
- **`required`**: Requires one or more functions to be called
205-
- **`{tool_name}`**: Forces the model to call a specific tool by name
206262

207263
## Legacy Alpha1 API
208264

0 commit comments

Comments
 (0)