Skip to content

Commit

Permalink
#149: Streaming Chat Workflow (#150)
Browse files Browse the repository at this point in the history
- Initing a new type of workflow, a streaming (async) routing workflow using the Streaming Chat API as an example
- Updated the Bruno collection
- Updated the LanguageModel API to include `ChatStream()` and `SupportChatStream()` methods
- Get the streaming router working
- Implemented SSE event parsing to be able to work with OpenAI streaming chat API
- Integrated OpenAI chat streaming into the Glide's streaming chat API
- Covered the happy workflow by tests
  • Loading branch information
roma-glushko authored Mar 2, 2024
1 parent e9e7246 commit 4edb644
Show file tree
Hide file tree
Showing 46 changed files with 1,279 additions and 250 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ jobs:
- name: login into Github Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: login into Github Container Registry
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin

- name: login into Docker
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u einstack --password-stdin

Expand Down
11 changes: 11 additions & 0 deletions docs/api/Language API/💬 Chat Stream.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: 💬 Chat Stream
type: http
seq: 2
}

get {
url: {{base_url}}/language/default/chatStream
body: none
auth: none
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
meta {
name: [Lang] Chat
name: 💬 Chat
type: http
seq: 2
seq: 1
}

post {
url: {{base_url}}/v1/language/myrouter/chat/
url: {{base_url}}/language/default/chat/
body: json
auth: none
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
meta {
name: [Lang] Router List
name: 🔧 Router List
type: http
seq: 3
}

get {
url: {{base_url}}/v1/language/
url: {{base_url}}/language/
body: json
auth: none
}
Expand Down
2 changes: 1 addition & 1 deletion docs/api/environments/Development.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vars {
base_url: http://127.0.0.1:9099
base_url: http://127.0.0.1:9099/v1
}
4 changes: 2 additions & 2 deletions docs/api/Health.bru → docs/api/🔧 Health.bru
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
meta {
name: Health
name: 🔧 Health
type: http
seq: 1
}

get {
url: {{base_url}}/health
url: {{base_url}}/health/
body: none
auth: none
}
103 changes: 89 additions & 14 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const docTemplate = `{
},
"/v1/language/{router}/chat": {
"post": {
"description": "Talk to different LLMs Chat API via unified endpoint",
"description": "Talk to different LLM Chat APIs via unified endpoint",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -123,6 +123,70 @@ const docTemplate = `{
}
}
}
},
"/v1/language/{router}/chatStream": {
"get": {
"description": "Talk to different LLM Stream Chat APIs via a unified websocket endpoint",
"consumes": [
"application/json"
],
"tags": [
"Language"
],
"summary": "Language Chat",
"operationId": "glide-language-chat-stream",
"parameters": [
{
"type": "string",
"description": "Router ID",
"name": "router",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Websocket Connection Type",
"name": "Connection",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Upgrade header",
"name": "Upgrade",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Websocket Security Token",
"name": "Sec-WebSocket-Key",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Websocket Security Token",
"name": "Sec-WebSocket-Version",
"in": "header",
"required": true
}
],
"responses": {
"101": {
"description": "Switching Protocols"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/http.ErrorSchema"
}
},
"426": {
"description": "Upgrade Required"
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -742,6 +806,10 @@ const docTemplate = `{
},
"schemas.ChatMessage": {
"type": "object",
"required": [
"content",
"role"
],
"properties": {
"content": {
"description": "The content of the message.",
Expand All @@ -759,6 +827,9 @@ const docTemplate = `{
},
"schemas.ChatRequest": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
Expand Down Expand Up @@ -790,7 +861,7 @@ const docTemplate = `{
"type": "string"
},
"modelResponse": {
"$ref": "#/definitions/schemas.ProviderResponse"
"$ref": "#/definitions/schemas.ModelResponse"
},
"model_id": {
"type": "string"
Expand All @@ -803,18 +874,7 @@ const docTemplate = `{
}
}
},
"schemas.OverrideChatRequest": {
"type": "object",
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
},
"model_id": {
"type": "string"
}
}
},
"schemas.ProviderResponse": {
"schemas.ModelResponse": {
"type": "object",
"properties": {
"message": {
Expand All @@ -831,6 +891,21 @@ const docTemplate = `{
}
}
},
"schemas.OverrideChatRequest": {
"type": "object",
"required": [
"message",
"model_id"
],
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
},
"model_id": {
"type": "string"
}
}
},
"schemas.TokenUsage": {
"type": "object",
"properties": {
Expand Down
103 changes: 89 additions & 14 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"/v1/language/{router}/chat": {
"post": {
"description": "Talk to different LLMs Chat API via unified endpoint",
"description": "Talk to different LLM Chat APIs via unified endpoint",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -120,6 +120,70 @@
}
}
}
},
"/v1/language/{router}/chatStream": {
"get": {
"description": "Talk to different LLM Stream Chat APIs via a unified websocket endpoint",
"consumes": [
"application/json"
],
"tags": [
"Language"
],
"summary": "Language Chat",
"operationId": "glide-language-chat-stream",
"parameters": [
{
"type": "string",
"description": "Router ID",
"name": "router",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Websocket Connection Type",
"name": "Connection",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Upgrade header",
"name": "Upgrade",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Websocket Security Token",
"name": "Sec-WebSocket-Key",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Websocket Security Token",
"name": "Sec-WebSocket-Version",
"in": "header",
"required": true
}
],
"responses": {
"101": {
"description": "Switching Protocols"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/http.ErrorSchema"
}
},
"426": {
"description": "Upgrade Required"
}
}
}
}
},
"definitions": {
Expand Down Expand Up @@ -739,6 +803,10 @@
},
"schemas.ChatMessage": {
"type": "object",
"required": [
"content",
"role"
],
"properties": {
"content": {
"description": "The content of the message.",
Expand All @@ -756,6 +824,9 @@
},
"schemas.ChatRequest": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
Expand Down Expand Up @@ -787,7 +858,7 @@
"type": "string"
},
"modelResponse": {
"$ref": "#/definitions/schemas.ProviderResponse"
"$ref": "#/definitions/schemas.ModelResponse"
},
"model_id": {
"type": "string"
Expand All @@ -800,18 +871,7 @@
}
}
},
"schemas.OverrideChatRequest": {
"type": "object",
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
},
"model_id": {
"type": "string"
}
}
},
"schemas.ProviderResponse": {
"schemas.ModelResponse": {
"type": "object",
"properties": {
"message": {
Expand All @@ -828,6 +888,21 @@
}
}
},
"schemas.OverrideChatRequest": {
"type": "object",
"required": [
"message",
"model_id"
],
"properties": {
"message": {
"$ref": "#/definitions/schemas.ChatMessage"
},
"model_id": {
"type": "string"
}
}
},
"schemas.TokenUsage": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 4edb644

Please sign in to comment.