Skip to content

Commit

Permalink
Merge pull request #34 from upstash/fix-history-access
Browse files Browse the repository at this point in the history
fix: history access by removing service prefix
  • Loading branch information
ogzhanolguncu authored Aug 6, 2024
2 parents 9700685 + 136380b commit a944046
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@upstash/rag-chat",
"version": "1.0.4",
"version": "1.0.5",
"main": "./dist/base/index.mjs",
"types": "./dist/base/index.d.ts",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions src/rag-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { RateLimitService } from "./ratelimit-service";
import type { ChatOptions, RAGChatConfig } from "./types";
import type { ModifiedChatOptions } from "./utils";
import { appendDefaultsIfNeeded, sanitizeQuestion } from "./utils";
import type { InMemoryHistory } from "./history-service/in-memory-history";
import type { UpstashRedisHistory } from "./history-service/redis-custom-history";

export type PromptParameters = { chatHistory?: string; question: string; context: string };

Expand All @@ -33,7 +35,7 @@ export class RAGChat {
private ratelimit: RateLimitService;
private llm: LLMService;
context: ContextService;
history: HistoryService;
history: UpstashRedisHistory | InMemoryHistory;
private config: Config;
private debug?: ChatLogger;

Expand All @@ -51,7 +53,7 @@ export class RAGChat {
const vectorService = new Database(this.config.vector);
this.history = new HistoryService({
redis: this.config.redis,
});
}).service;
this.llm = new LLMService(this.config.model);
this.context = new ContextService(vectorService, this.config.namespace ?? DEFAULT_NAMESPACE);
this.debug = this.config.debug
Expand Down Expand Up @@ -106,7 +108,7 @@ export class RAGChat {
onChunk: optionsWithDefault.onChunk,
onComplete: async (output) => {
await this.debug?.endLLMResponse(output);
await this.history.service.addMessage({
await this.history.addMessage({
message: {
content: output,
metadata: optionsWithDefault.metadata,
Expand Down Expand Up @@ -145,7 +147,7 @@ export class RAGChat {
private async getChatHistory(optionsWithDefault: ModifiedChatOptions) {
this.debug?.startRetrieveHistory();
// Gets the chat history from redis or in-memory store.
const originalChatHistory = await this.history.service.getMessages({
const originalChatHistory = await this.history.getMessages({
sessionId: optionsWithDefault.sessionId,
amount: optionsWithDefault.historyLength,
});
Expand All @@ -168,7 +170,7 @@ export class RAGChat {
}

private async addUserMessageToHistory(input: string, optionsWithDefault: ModifiedChatOptions) {
await this.history.service.addMessage({
await this.history.addMessage({
message: { content: input, role: "user" },
sessionId: optionsWithDefault.sessionId,
});
Expand Down

0 comments on commit a944046

Please sign in to comment.