-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cosmos DB chat history feature to the frontend
- Loading branch information
Showing
8 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { IHistoryProvider, Answers, HistoryProviderOptions, HistoryMetaData } from "./IProvider"; | ||
import { deleteChatHistoryApi, getChatHistoryApi, getChatHistoryListApi, postChatHistoryApi } from "../../api"; | ||
|
||
export class CosmosDBProvider implements IHistoryProvider { | ||
getProviderName = () => HistoryProviderOptions.CosmosDB; | ||
|
||
private continuationToken: string | undefined; | ||
private isItemEnd: boolean = false; | ||
|
||
resetContinuationToken() { | ||
this.continuationToken = undefined; | ||
this.isItemEnd = false; | ||
} | ||
|
||
async getNextItems(count: number, idToken?: string): Promise<HistoryMetaData[]> { | ||
if (this.isItemEnd) { | ||
return []; | ||
} | ||
|
||
try { | ||
const response = await getChatHistoryListApi(count, this.continuationToken, idToken || ""); | ||
this.continuationToken = response.continuation_token; | ||
if (!this.continuationToken) { | ||
this.isItemEnd = true; | ||
} | ||
return response.items.map(item => ({ | ||
id: item.id, | ||
title: item.title || "untitled", | ||
timestamp: item._ts * 1000 | ||
})); | ||
} catch (e) { | ||
console.error(e); | ||
return []; | ||
} | ||
} | ||
|
||
async addItem(id: string, answers: Answers, idToken?: string): Promise<void> { | ||
await postChatHistoryApi({ id, answers }, idToken || ""); | ||
return; | ||
} | ||
|
||
async getItem(id: string, idToken?: string): Promise<Answers | null> { | ||
const response = await getChatHistoryApi(id, idToken || ""); | ||
return response.answers || null; | ||
} | ||
|
||
async deleteItem(id: string, idToken?: string): Promise<void> { | ||
await deleteChatHistoryApi(id, idToken || ""); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters