Skip to content

Commit

Permalink
docs: update docs usage of useLangGraphRuntime (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 11, 2024
1 parent e9f60ae commit 60ad0fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions apps/docs/content/docs/runtimes/langgraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export const createThread = async () => {

export const sendMessage = async (params: {
threadId: string;
message: LangChainMessage;
messages: LangChainMessage;
}) => {
const client = createClient();
return client.runs.stream(
params.threadId,
process.env["NEXT_PUBLIC_LANGGRAPH_ASSISTANT_ID"]!,
{
input: {
messages: [params.message],
messages: params.messages,
},
streamMode: "messages",
},
Expand Down Expand Up @@ -122,15 +122,15 @@ export function MyRuntimeProvider({
const threadIdRef = useRef<string | undefined>();
const runtime = useLangGraphRuntime({
threadId: threadIdRef.current,
stream: async (message) => {
stream: async (messages) => {
if (!threadIdRef.current) {
const { thread_id } = await createThread();
threadIdRef.current = thread_id;
}
const threadId = threadIdRef.current;
return sendMessage({
threadId,
message,
messages,
});
},
});
Expand Down
4 changes: 2 additions & 2 deletions examples/with-langgraph/app/MyRuntimeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export function MyRuntimeProvider({
const threadIdRef = useRef<string | undefined>();
const runtime = useLangGraphRuntime({
threadId: threadIdRef.current,
stream: async (message) => {
stream: async (messages) => {
if (!threadIdRef.current) {
const { thread_id } = await createThread();
threadIdRef.current = thread_id;
}
const threadId = threadIdRef.current;
return sendMessage({
threadId,
message,
messages,
});
},
});
Expand Down
11 changes: 4 additions & 7 deletions examples/with-langgraph/lib/chatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ export const updateState = async (

export const sendMessage = async (params: {
threadId: string;
message: LangChainMessage | null;
messages: LangChainMessage[];
}) => {
const client = createClient();

let input: Record<string, any> | null = null;
if (params.message !== null) {
input = {
messages: [params.message],
};
}
let input: Record<string, any> | null = {
messages: params.messages,
};
const config = {
configurable: {
model_name: "openai",
Expand Down

0 comments on commit 60ad0fa

Please sign in to comment.