-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from getzep/v2-integration
feat: Add support for v2 api
- Loading branch information
Showing
34 changed files
with
1,674 additions
and
7,165 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
//setupJest.js or similar file | ||
require('jest-fetch-mock').enableMocks() | ||
// setupJest.js or similar file | ||
require("jest-fetch-mock").enableMocks(); |
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,59 @@ | ||
import { ZepClient } from "../../src"; | ||
import { ZepChatMessageHistory } from "../../src/langchain"; | ||
import { ChatOpenAI } from "@langchain/openai"; | ||
import { | ||
ChatPromptTemplate, | ||
MessagesPlaceholder, | ||
} from "@langchain/core/prompts"; | ||
import { RunnableWithMessageHistory } from "@langchain/core/runnables"; | ||
import { ConsoleCallbackHandler } from "@langchain/core/tracers/console"; | ||
async function main() { | ||
const zepClient = await ZepClient.init( | ||
process.env.ZEP_API_KEY, | ||
process.env.ZEP_API_URL, | ||
); | ||
|
||
const prompt = ChatPromptTemplate.fromMessages([ | ||
["system", "Answer the user's question below. Be polite and helpful:"], | ||
new MessagesPlaceholder("history"), | ||
["human", "{question}"], | ||
]); | ||
|
||
const chain = prompt | ||
.pipe( | ||
new ChatOpenAI({ | ||
temperature: 0.8, | ||
modelName: "gpt-3.5-turbo-1106", | ||
}), | ||
) | ||
.withConfig({ | ||
callbacks: [new ConsoleCallbackHandler()], | ||
}); | ||
|
||
const chainWithHistory = new RunnableWithMessageHistory({ | ||
runnable: chain, | ||
getMessageHistory: (sessionId) => | ||
new ZepChatMessageHistory({ | ||
client: zepClient, | ||
sessionId: sessionId, | ||
memoryType: "perpetual", | ||
}), | ||
inputMessagesKey: "question", | ||
historyMessagesKey: "history", | ||
}); | ||
|
||
const result = await chainWithHistory.invoke( | ||
{ | ||
question: "What did we talk about earlier?", | ||
}, | ||
{ | ||
configurable: { | ||
sessionId: "06d114e2-7c6e-4268-91b9-63a4b9645bbf", | ||
}, | ||
}, | ||
); | ||
|
||
console.log("result", result); | ||
} | ||
|
||
main(); |
Oops, something went wrong.