Skip to content

Commit

Permalink
Merge pull request #57 from getzep/paul/zepai-306-facts-update-typesc…
Browse files Browse the repository at this point in the history
…ript-sdk

Paul/zepai 306 facts update typescript sdk
  • Loading branch information
paul-paliychuk authored Mar 14, 2024
2 parents 9b9dc42 + ede584e commit a7fb321
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 173 deletions.
107 changes: 107 additions & 0 deletions examples/memory/chat_shoe_store_history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { RoleType } from "../../src/message_models";

export const history: {
role: string;
role_type: RoleType;
content: string;
metadata?: { [key: string]: any };
}[] = [
{
role: "user",
role_type: "user",
content:
"Hi there, I'm looking for a new pair of shoes. I'm not sure where to start.",
},
{
role: "assistant",
role_type: "assistant",
content:
"Hello! I'd be happy to help you find the perfect pair of shoes. To get started, could you tell me what brand you're interested in, or if you're open to any brand?",
},
{
role: "user",
role_type: "user",
content: "I like Nike and Adidas, but I'm open to other brands too.",
},
{
role: "assistant",
role_type: "assistant",
content:
"That's great! It's important to find the right shoe for your needs. Could you tell me what you'll be using these shoes for mainly? For example, are they for running, basketball, or casual wear?",
},
{
role: "user",
role_type: "user",
content: "I'll be using them for running.",
},
{
role: "assistant",
role_type: "assistant",
content:
"Fantastic! Now, could you please provide me with your shoe size and foot width? This information will help me narrow down the options for you.",
},
{
role: "user",
role_type: "user",
content: "I wear a men's size 10, and I'm not sure about the foot width.",
},
{
role: "assistant",
role_type: "assistant",
content:
"Thank you. Based on your size, I'll make sure to suggest shoes with a wide range of sizes and widths available.",
},
{
role: "user",
role_type: "user",
content:
"I have a bit of a pronation issue. Do I need to consider that while choosing shoes?",
},
{
role: "assistant",
role_type: "assistant",
content:
"Yes, pronation is essential when choosing running shoes. It refers to the way your foot rolls inward or outward when you walk or run. For pronation issues, stability or motion control shoes are usually recommended. I'll make sure to consider this in my suggestions.",
},
{
role: "user",
role_type: "user",
content: "Great, I have a budget of around $120.",
},
{
role: "assistant",
role_type: "assistant",
content:
"Perfect! I'll make sure to find the best running shoes that fit your preferences, taking into account your brand preferences, running needs, size, and budget.",
},
{
role: "assistant",
role_type: "assistant",
content:
"I've found a few great options for you. The first one is the Brooks Ghost 14, which is known for its cushioning and support, ideal for runners with pronation issues. It's available in your size, and it's within your budget.",
metadata: { bar: "foo" },
},
{
role: "user",
role_type: "user",
content:
"I've heard good things about Brooks, but I was kind of hoping to get a Nike or an Adidas shoe.",
},
{
role: "assistant",
role_type: "assistant",
content:
"I understand. In that case, I'd recommend the Adidas Ultraboost 21. It's a popular choice among runners for its comfort, energy return, and stability. Plus, it's on sale at $129.99 today, almost within your budget.",
},
{
role: "user",
role_type: "user",
content: "They're nice looking. Yes, I think I'll go with those.",
},
{
role: "assistant",
role_type: "assistant",
content:
"Excellent choice! To complete the purchase, I'll need you to provide your credit card information in our secure payment form. This will allow us to process your order and ensure a smooth delivery.",
},
];
65 changes: 36 additions & 29 deletions examples/memory/history.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,79 @@
import { RoleType } from "../../src/message_models";

export const history = [
export const history: {
role: string;
role_type: RoleType;
content: string;
metadata?: { [key: string]: any };
}[] = [
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Who was Octavia Butler?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Estelle Butler (June 22, 1947 – February 24, 2006) was an American" +
" science fiction author.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Which books of hers were made into movies?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"The most well-known adaptation of Octavia Butler's work is the FX series" +
" Kindred, based on her novel of the same name.",
},
{
role: "human",
role_type: "user" as RoleType,
content: "Who were her contemporaries?" },
role_type: "user",
content: "Who were her contemporaries?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Butler's contemporaries included Ursula K. Le Guin, Samuel R." +
" Delany, and Joanna Russ.",
},
{
role: "human",
role_type: "user" as RoleType,
content: "What awards did she win?" },
role_type: "user",
content: "What awards did she win?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Butler won the Hugo Award, the Nebula Award, and the MacArthur" +
" Fellowship.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Which other women sci-fi writers might I want to read?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content: "You might want to read Ursula K. Le Guin or Joanna Russ.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content:
"Write a short synopsis of Butler's book, Parable of the Sower. What is it" +
" about?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Parable of the Sower is a science fiction novel by Octavia Butler," +
" published in 1993. It follows the story of Lauren Olamina, a young woman" +
Expand All @@ -75,37 +82,37 @@ export const history = [
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "What inspired Octavia Butler's writing style?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Butler was inspired by a wide range of influences, including her" +
" passion for science fiction, her interest in sociology, and her desire to" +
" explore issues of power, race, and gender in her works.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Did Octavia Butler write only science fiction?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"While Octavia Butler is best known for her contributions to science fiction," +
" she also wrote in other genres, including fantasy and speculative fiction.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Tell me more about the Xenogenesis series.",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"The Xenogenesis series, also known as the Lilith's Brood trilogy, consists" +
" of three novels: Dawn (1987), Adulthood Rites (1988), and Imago (1989)." +
Expand All @@ -114,25 +121,25 @@ export const history = [
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Are there any upcoming adaptations of Octavia Butler's work?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"As of my last update, there were discussions about potential adaptations," +
" but no confirmed upcoming projects. It's advisable to check the latest" +
" news sources for any recent developments.",
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "What is the Earthseed series about?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"The Earthseed series consists of Parable of the Sower (1993) and Parable of" +
" the Talents (1998). It follows the protagonist, Lauren Olamina, as she" +
Expand All @@ -141,12 +148,12 @@ export const history = [
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "How did Octavia Butler impact the science fiction genre?",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Butler made significant contributions to the science fiction genre" +
" by challenging conventions and addressing social issues. Her works" +
Expand All @@ -155,12 +162,12 @@ export const history = [
},
{
role: "human",
role_type: "user" as RoleType,
role_type: "user",
content: "Tell me about Octavia Butler's writing process.",
},
{
role: "ai",
role_type: "assistant" as RoleType,
role_type: "assistant",
content:
"Octavia Butler was known for her disciplined and dedicated writing" +
" process. She often wrote in the early morning hours and set specific" +
Expand Down
35 changes: 34 additions & 1 deletion examples/memory/memory_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../src";

// @ts-ignore
import { history } from "./history";
import { history } from "./chat_shoe_store_history";

function sleep(ms: number) {
const date = Date.now();
Expand Down Expand Up @@ -79,6 +79,39 @@ async function main() {
console.debug("Got error:", error);
}

try {
// Synthesize a question from most recent messages.
// Useful for RAG apps.
// This is faster than using an LLM chain.
console.debug("\n---Synthesize a question from most recent messages");
const question = await client.memory.synthesizeQuestion(sessionID, 3);
console.debug(`Question: ${question}`);
} catch (error) {
console.debug("Got error:", error);
}

try {
// Classify the session.
// Useful for semantic routing, filtering, and many other use cases.
console.debug("\n---Classify the session");
const classes = [
"low spender <$50",
"medium spender >=$50, <$100",
"high spender >=$100",
"unknown",
];
const classification = await client.memory.classifySession(
sessionID,
"spender_category",
classes,
);
console.debug(
`${classification.class} Classification Result: ${classification.name}`,
);
} catch (error) {
console.debug("Got error:", error);
}

console.log("Sleeping for 5 seconds to let background tasks complete...");
sleep(5000); // Sleep for 5 seconds
console.log("Done sleeping!");
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"show-config": "tsc --showConfig",
"name": "@getzep/zep-js",
"version": "2.0.0-rc.3",
"version": "2.0.0-rc.4",
"description": "Zep: Fast, scalable building blocks for production LLM apps",
"private": false,
"publishConfig": {
Expand Down Expand Up @@ -55,8 +55,8 @@
"typescript": "^5.1.6"
},
"peerDependencies": {
"langchain": "^0.1.19",
"@langchain/core": "^0.1.19"
"langchain": "~0.1.19",
"@langchain/core": "~0.1.29"
},
"peerDependenciesMeta": {
"langchain": {
Expand All @@ -67,12 +67,11 @@
}
},
"resolutions": {
"@langchain/core": "^0.1.19"
"@langchain/core": "~0.1.29"
},
"devDependencies": {
"@faker-js/faker": "^8.2.0",
"@langchain/core": "^0.1.23",
"@langchain/openai": "^0.0.14",
"@langchain/openai": "~0.0.14",
"@types/jest": "^29.5.7",
"@types/node": "^20.8.9",
"@types/sax": "^1.2.7",
Expand All @@ -88,7 +87,7 @@
"jest": "^29.6.2",
"jest-fetch-mock": "^3.0.3",
"jsdoc": "^4.0.2",
"langchain": "^0.1.19",
"langchain": "~0.1.19",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand Down
Loading

0 comments on commit a7fb321

Please sign in to comment.