Skip to content

Commit

Permalink
Add conversation ID header to API call
Browse files Browse the repository at this point in the history
  • Loading branch information
namanaman committed Sep 5, 2024
1 parent e0357c4 commit 9e73d17
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 132 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ PROMPTFLOW_RESPONSE_TIMEOUT=120
PROMPTFLOW_REQUEST_FIELD_NAME=query
PROMPTFLOW_RESPONSE_FIELD_NAME=reply
PROMPTFLOW_CITATIONS_FIELD_NAME=documents
CONVERSATION_ID_HEADER="12345"
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ async def assets(path):
"show_chat_history_button": app_settings.ui.show_chat_history_button,
},
"sanitize_answer": app_settings.base_settings.sanitize_answer,
"conversation_id_header": app_settings.base_settings.conversation_id_header,
}


Expand Down
1 change: 1 addition & 0 deletions backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ class _BaseSettings(BaseSettings):
auth_enabled: bool = False
sanitize_answer: bool = False
use_promptflow: bool = False
conversation_id_header: Optional[str] = None


class _AppSettings(BaseModel):
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { FileType, UploadedFile } from '../custom/fileUploadUtils'

import { ChatMessage, Conversation, ConversationRequest, CosmosDBHealth, CosmosDBStatus, UserInfo } from './models'

export async function conversationApi(options: ConversationRequest, abortSignal: AbortSignal): Promise<Response> {
export async function conversationApi(
options: ConversationRequest,
abortSignal: AbortSignal,
conversationIdHeader: string | null | undefined
): Promise<Response> {
const formatContent = (message: any) => {
const apiMessage = structuredClone(message)

Expand All @@ -30,7 +34,8 @@ export async function conversationApi(options: ConversationRequest, abortSignal:
const response = await fetch('/conversation', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'conversation-id': conversationIdHeader ?? ''
},
body: JSON.stringify({
messages: options.messages.map(formatContent)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export type FrontendSettings = {
feedback_enabled?: string | null
ui?: UI
sanitize_answer?: boolean
conversation_id_header?: string
}

export enum Feedback {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ const Chat = () => {

let result = {} as ChatResponse
try {
const response = await conversationApi(request, abortController.signal)
const response = await conversationApi(
request,
abortController.signal,
appStateContext?.state.frontendSettings?.conversation_id_header
)
if (response?.body) {
const reader = response.body.getReader()

Expand Down
1 change: 1 addition & 0 deletions static/assets/index-49a94d23.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e73d17

Please sign in to comment.