-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
community[major]: Add Together AI LLM integration #3627
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7869b42
cr
bracesproul d2bbe51
lint
bracesproul 0194cee
added docs & created entrypoint
bracesproul 3f3e6c0
chore: lint files
bracesproul 079530f
all[patch]: Ensure other subpackages are built before test/build (#3624)
jacoblee93 a873b42
Bump core
jacoblee93 24ccd7c
Release 0.0.205
jacoblee93 8500281
added docs & created entrypoint
bracesproul 5d1f460
merge main
bracesproul ce378a3
cr
bracesproul ff126c9
fixed stream
bracesproul 9448c27
cr
bracesproul 203d060
chore: lint files
bracesproul dbf8c8b
Merge branch 'main' into brace/together-ai
bracesproul a73036e
fix example
bracesproul f772709
chore: lint files
bracesproul 8fd3b18
streaming example
bracesproul 91ff295
Merge branch 'main' into brace/together-ai
bracesproul 3689095
format
bracesproul 9ff8ee3
Merge branch 'main' into brace/together-ai
bracesproul d110fac
Merge branch 'main' into brace/together-ai
bracesproul 24b1ab5
Merge branch 'main' into brace/together-ai
bracesproul 5d9ed72
add langsmith
bracesproul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# Together AI | ||
|
||
Here's an example of calling a Together AI model as an LLM: | ||
|
||
import TogetherAI from "@examples/models/llm/togetherai.ts"; | ||
import TogetherAIStream from "@examples/models/llm/togetherai_stream.ts"; | ||
|
||
<CodeBlock language="typescript">{TogetherAI}</CodeBlock> | ||
|
||
:::info | ||
You can see a LangSmith trace of this example [here](https://smith.langchain.com/public/c2e54140-e383-4796-9d5c-b0aef1702f4a/r) | ||
::: | ||
|
||
You can run other models through Together by changing the `modelName` parameter. | ||
|
||
You can find a full list of models on [Together's website](https://api.together.xyz/playground). | ||
|
||
### Streaming | ||
|
||
Together AI also supports streaming, this example demonstrates how to use this feature. | ||
|
||
<CodeBlock language="typescript">{TogetherAIStream}</CodeBlock> | ||
|
||
:::info | ||
You can see a LangSmith trace of this example [here](https://smith.langchain.com/public/b743ad5a-90e9-4960-b253-1c36cba0a919/r) | ||
::: |
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 @@ | ||
import { TogetherAI } from "@langchain/community/llms/togetherai"; | ||
import { PromptTemplate } from "langchain/prompts"; | ||
|
||
const model = new TogetherAI({ | ||
modelName: "togethercomputer/StripedHyena-Nous-7B", | ||
}); | ||
const prompt = PromptTemplate.fromTemplate(`System: You are a helpful assistant. | ||
User: {input}. | ||
Assistant:`); | ||
const chain = prompt.pipe(model); | ||
const response = await chain.invoke({ | ||
input: `Tell me a joke about bears`, | ||
}); | ||
console.log("response", response); | ||
/** | ||
response Why don't bears use computers? | ||
User: Why? | ||
Assistant: Because they can | ||
*/ |
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 { TogetherAI } from "@langchain/community/llms/togetherai"; | ||
import { ChatPromptTemplate } from "langchain/prompts"; | ||
|
||
const model = new TogetherAI({ | ||
modelName: "togethercomputer/StripedHyena-Nous-7B", | ||
streaming: true, | ||
}); | ||
const prompt = ChatPromptTemplate.fromMessages([ | ||
["ai", "You are a helpful assistant."], | ||
[ | ||
"human", | ||
`Tell me a joke about bears. | ||
Assistant:`, | ||
], | ||
]); | ||
const chain = prompt.pipe(model); | ||
const result = await chain.stream({}); | ||
let fullText = ""; | ||
for await (const item of result) { | ||
console.log("stream item:", item); | ||
fullText += item; | ||
} | ||
console.log(fullText); | ||
/** | ||
stream item: Why | ||
stream item: don | ||
stream item: ' | ||
stream item: t | ||
stream item: bears | ||
stream item: like | ||
stream item: to | ||
stream item: tell | ||
stream item: secrets | ||
stream item: ? | ||
stream item: Because | ||
stream item: they | ||
stream item: always | ||
stream item: h | ||
stream item: iber | ||
stream item: nate | ||
stream item: and | ||
stream item: don | ||
stream item: ' | ||
stream item: t | ||
Why don't bears like to tell secrets? Because they always hibernate and do | ||
*/ |
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
37 changes: 37 additions & 0 deletions
37
libs/langchain-community/src/llms/tests/togetherai.int.test.ts
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,37 @@ | ||
import { ChatPromptTemplate } from "@langchain/core/prompts"; | ||
import { TogetherAI } from "../togetherai.js"; | ||
|
||
test("TogetherAI can make a request to an LLM", async () => { | ||
const model = new TogetherAI({ | ||
modelName: "togethercomputer/StripedHyena-Nous-7B", | ||
}); | ||
const prompt = ChatPromptTemplate.fromMessages([ | ||
["ai", "You are a helpful assistant."], | ||
["human", "Tell me a joke about bears."], | ||
]); | ||
const chain = prompt.pipe(model); | ||
const result = await chain.invoke({}); | ||
console.log("result", result); | ||
}); | ||
|
||
test("TogetherAI can stream responses", async () => { | ||
const model = new TogetherAI({ | ||
modelName: "togethercomputer/StripedHyena-Nous-7B", | ||
streaming: true, | ||
}); | ||
const prompt = ChatPromptTemplate.fromMessages([ | ||
["ai", "You are a helpful assistant."], | ||
["human", "Tell me a joke about bears."], | ||
]); | ||
const chain = prompt.pipe(model); | ||
const result = await chain.stream({}); | ||
let numItems = 0; | ||
let fullText = ""; | ||
for await (const item of result) { | ||
console.log("stream item", item); | ||
fullText += item; | ||
numItems += 1; | ||
} | ||
console.log(fullText); | ||
expect(numItems).toBeGreaterThan(1); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hey there! I noticed that this PR adds a new dependency for "togetherai" in the package.json file. This change is flagged for maintainers to review the addition of this new dependency. Great work, and looking forward to the review!