Skip to content

Commit 8257391

Browse files
Proposal: Conversation API (#59)
* Proposal: Conversation API Signed-off-by: Loong <[email protected]> * add endpoint Signed-off-by: Loong <[email protected]> * add load balancing Signed-off-by: Loong <[email protected]> * update inputs Signed-off-by: Loong <[email protected]> * use Any Signed-off-by: Loong <[email protected]> * add json request&response Signed-off-by: Loong <[email protected]> * update name Signed-off-by: Loong <[email protected]> * update json Signed-off-by: Loong <[email protected]> * add metadata Signed-off-by: Loong <[email protected]> * Use component metadata. Adds conversationContext Signed-off-by: Artur Souza <[email protected]> --------- Signed-off-by: Loong <[email protected]> Signed-off-by: Artur Souza <[email protected]> Co-authored-by: Artur Souza <[email protected]>
1 parent 252b7c3 commit 8257391

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Conversation building block
2+
3+
* Author(s): Loong Dai (@daixiang0)
4+
* Updated: 2024-06-18
5+
6+
## Overview
7+
8+
This is a proposal for a new building block for Dapr to allow developers to leverage LLM services in a consistent way. Goal is to expose an API that allows developers to ask Dapr to do request.
9+
10+
## Background
11+
12+
Now there are many large language model servers or toolkits, which provides own APIs, like [OpenAI](https://openai.com/), [Hugging Face](https://huggingface.co/), [Kserve](https://kserve.github.io/website/latest/), [OpenVINO](https://docs.openvino.ai/) and so on.
13+
14+
For developers, it is hard to migrate from one to the other due to hardcode and API differences.
15+
16+
For startups and communities, they need to implement the popular APIs as soon as possible, or users maybe give up tring or adopting because of the cost of migration.
17+
18+
This is an area where Dapr can help. We can offer an abstraction layer on those APIs.
19+
20+
## Component YAML
21+
22+
A component can have it's own set of attributes, like in Dapr. For example:
23+
24+
```yaml
25+
apiVersion: dapr.io/v1alpha1
26+
kind: Component
27+
metadata:
28+
name: chatgpt4o
29+
spec:
30+
type: conversation.chatgpt
31+
version: v1
32+
metadata:
33+
- name: key
34+
value: "bfnskdlgdhklhk53adfgsfnsgmtyqdghbid34891"
35+
- name: model
36+
value: "gpt-4o"
37+
- name: endpoints
38+
value: "us.api.openai.com,eu.api.openai.com"
39+
- name: loadBalancingPolicy
40+
value: "ROUNDROBIN"
41+
```
42+
43+
## gRPC APIs
44+
45+
In the Dapr gRPC APIs, we are extending the `runtime.v1.Dapr` service to add new methods:
46+
47+
> Note: APIs will have "Alpha1" added while in preview
48+
49+
> Note: The API token is stored in the component
50+
51+
```proto
52+
// (Existing Dapr service)
53+
service Dapr {
54+
// Conversate.
55+
rpc Converse(stream ConversationRequest) returns (stream ConversationResponse);
56+
}
57+
58+
// ConversationRequest is the request object for Conversation.
59+
message ConversationRequest {
60+
// The name of Conversation component
61+
string name = 1;
62+
// Conversation context - the Id of an existing chat room (like in ChatGPT)
63+
optional string conversationContext = 2;
64+
// Inputs for the conversation, support multiple input in one time.
65+
repeated string inputs = 3;
66+
// Parameters for all custom fields.
67+
repeated google.protobuf.Any parameters = 4;
68+
}
69+
70+
// ConversationResult is the result for one input.
71+
message ConversationResult {
72+
// Result for the one conversation input.
73+
string result = 1;
74+
// Parameters for all custom fields.
75+
repeated google.protobuf.Any parameters = 2;
76+
}
77+
78+
// ConversationResponse is the response for Conversation.
79+
message ConversationResponse {
80+
// Conversation context - the Id of an existing or newly created chat room (like in ChatGPT)
81+
optional string conversationContext = 1;
82+
83+
// An array of results.
84+
repeated ConversationResult outputs = 2;
85+
}
86+
```
87+
88+
## HTTP APIs
89+
90+
The HTTP APIs are same with the gRPC APIs:
91+
92+
`POST /v1.0/conversation/[component]/converse` -> Conversate
93+
94+
```json
95+
REQUEST = {
96+
"conversationContext": "fb512b84-7a1a-4fb4-8bd2-ac7d2ec45984",
97+
"inputs": ["what is Dapr", "Why use Dapr"],
98+
"parameters": {},
99+
}
100+
101+
RESPONSE = {
102+
"conversationContext": "fb512b84-7a1a-4fb4-8bd2-ac7d2ec45984",
103+
"outputs": {
104+
{
105+
"result": "Dapr is distribution application runtime ...",
106+
"parameters": {},
107+
},
108+
{
109+
"result": "Dapr can help developers ...",
110+
"parameters": {},
111+
}
112+
113+
},
114+
}
115+
```
116+
117+
> Note: URL will begin with `/v1.0-alpha1` while in preview

0 commit comments

Comments
 (0)