-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add managed motorhead opt * add example * fix typings * prettier * update linting * headers init * fix specs * Adds backcompat shim and docs * Adds managed motorhead integration test * Formatting --------- Co-authored-by: James O'Dwyer <james@getmetal.io>
- Loading branch information
1 parent
cdd9262
commit c4f4b49
Showing
7 changed files
with
141 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ All Self Query retrievers require `peggy` as a peer dependency: | |
|
||
```bash npm2yarn | ||
npm install -S peggy | ||
``` | ||
``` |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
--- | ||
hide_table_of_contents: true | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# Motörhead Memory | ||
|
||
[Motörhead](https://github.com/getmetal/motorhead) is a memory server implemented in Rust. It automatically handles incremental summarization in the background and allows for stateless applications. | ||
|
||
## Setup | ||
|
||
See instructions at [Motörhead](https://github.com/getmetal/motorhead) for running the server locally, or https://getmetal.io to get API keys for the hosted version. | ||
|
||
## Usage | ||
|
||
import Example from "@examples/memory/motorhead.ts"; | ||
|
||
<CodeBlock language="typescript">{Example}</CodeBlock> |
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,46 @@ | ||
import { MotorheadMemory } from "langchain/memory"; | ||
import { ChatOpenAI } from "langchain/chat_models/openai"; | ||
import { ConversationChain } from "langchain/chains"; | ||
|
||
// Managed Example (visit https://getmetal.io to get your keys) | ||
// const managedMemory = new MotorheadMemory({ | ||
// memoryKey: "chat_history", | ||
// sessionId: "test", | ||
// apiKey: "MY_API_KEY", | ||
// clientId: "MY_CLIENT_ID", | ||
// }); | ||
|
||
// Self Hosted Example | ||
const memory = new MotorheadMemory({ | ||
memoryKey: "chat_history", | ||
sessionId: "test", | ||
url: "localhost:8080", // Required for self hosted | ||
}); | ||
|
||
const model = new ChatOpenAI({ | ||
modelName: "gpt-3.5-turbo", | ||
temperature: 0, | ||
}); | ||
|
||
const chain = new ConversationChain({ llm: model, memory }); | ||
|
||
const res1 = await chain.call({ input: "Hi! I'm Jim." }); | ||
console.log({ res1 }); | ||
/* | ||
{ | ||
res1: { | ||
text: "Hello Jim! It's nice to meet you. My name is AI. How may I assist you today?" | ||
} | ||
} | ||
*/ | ||
|
||
const res2 = await chain.call({ input: "What did I just say my name was?" }); | ||
console.log({ res2 }); | ||
|
||
/* | ||
{ | ||
res1: { | ||
text: "You said your name was Jim." | ||
} | ||
} | ||
*/ |
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,22 @@ | ||
/* eslint-disable no-process-env */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { test, expect } from "@jest/globals"; | ||
import { MotorheadMemory } from "../motorhead_memory.js"; | ||
|
||
test("Test managed motörhead memory", async () => { | ||
const memory = new MotorheadMemory({ | ||
sessionId: new Date().toISOString(), | ||
apiKey: process.env.METAL_API_KEY!, | ||
clientId: process.env.METAL_CLIENT_ID!, | ||
}); | ||
const result1 = await memory.loadMemoryVariables({}); | ||
expect(result1).toStrictEqual({ history: "" }); | ||
|
||
await memory.saveContext( | ||
{ input: "Who is the best vocalist?" }, | ||
{ response: "Ozzy Osbourne" } | ||
); | ||
const expectedString = "Human: Who is the best vocalist?\nAI: Ozzy Osbourne"; | ||
const result2 = await memory.loadMemoryVariables({}); | ||
expect(result2).toStrictEqual({ history: expectedString }); | ||
}); |
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
c4f4b49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
langchainjs-docs – ./
js.langchain.com
langchainjs-docs-langchain.vercel.app
langchainjs-docs-git-main-langchain.vercel.app
langchainjs-docs-ruddy.vercel.app