-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[patch]: Fix remote runnable streamLog type, update docs (#4353)
* Fix remote runnable streamLog type, update docs * Fix lint * Remove bad test
- Loading branch information
1 parent
9a47e4e
commit 1b1ea2f
Showing
8 changed files
with
147 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,127 @@ | ||
import { RemoteRunnable } from "langchain/runnables/remote"; | ||
import { applyPatch } from "@langchain/core/utils/json_patch"; | ||
import { RemoteRunnable } from "@langchain/core/runnables/remote"; | ||
|
||
const remoteChain = new RemoteRunnable({ | ||
url: "https://your_hostname.com/path", | ||
// url: "https://your_hostname.com/path", | ||
url: "https://chat-langchain-backend.langchain.dev/chat", | ||
}); | ||
|
||
const logStream = await remoteChain.streamLog( | ||
{ | ||
param1: "param1", | ||
param2: "param2", | ||
question: "What is a document loader?", | ||
}, | ||
// LangChain runnable config properties | ||
{ | ||
configurable: { | ||
llm: "some_property", | ||
llm: "openai_gpt_3_5_turbo", | ||
}, | ||
metadata: { | ||
conversation_id: "other_metadata", | ||
}, | ||
}, | ||
// Optional additional streamLog properties for filtering outputs | ||
{ | ||
includeNames: [], | ||
includeTags: [], | ||
includeTypes: [], | ||
excludeNames: [], | ||
excludeTags: [], | ||
excludeTypes: [], | ||
// includeNames: [], | ||
// includeTags: [], | ||
// includeTypes: [], | ||
// excludeNames: [], | ||
// excludeTags: [], | ||
// excludeTypes: [], | ||
} | ||
); | ||
|
||
let streamedResponse: Record<string, any> = {}; | ||
let currentState; | ||
|
||
for await (const chunk of logStream) { | ||
console.log(chunk); | ||
streamedResponse = applyPatch(streamedResponse, chunk.ops).newDocument; | ||
if (!currentState) { | ||
currentState = chunk; | ||
} else { | ||
currentState = currentState.concat(chunk); | ||
} | ||
} | ||
|
||
console.log(streamedResponse); | ||
console.log(currentState); | ||
|
||
/* | ||
RunLog { | ||
ops: [ | ||
{ op: 'replace', path: '', value: [Object] }, | ||
{ | ||
op: 'add', | ||
path: '/logs/RunnableParallel<question,chat_history>', | ||
value: [Object] | ||
}, | ||
{ op: 'add', path: '/logs/Itemgetter:question', value: [Object] }, | ||
{ op: 'add', path: '/logs/SerializeHistory', value: [Object] }, | ||
{ | ||
op: 'add', | ||
path: '/logs/Itemgetter:question/streamed_output/-', | ||
value: 'What is a document loader?' | ||
}, | ||
{ | ||
op: 'add', | ||
path: '/logs/SerializeHistory/streamed_output/-', | ||
value: [] | ||
}, | ||
{ | ||
op: 'add', | ||
path: '/logs/RunnableParallel<question,chat_history>/streamed_output/-', | ||
value: [Object] | ||
}, | ||
{ op: 'add', path: '/logs/RetrieveDocs', value: [Object] }, | ||
{ op: 'add', path: '/logs/RunnableSequence', value: [Object] }, | ||
{ | ||
op: 'add', | ||
path: '/logs/RunnableParallel<question,chat_history>/streamed_output/-', | ||
value: [Object] | ||
}, | ||
... 558 more items | ||
], | ||
state: { | ||
id: '415ba646-a3e0-4c76-bff6-4f5f34305244', | ||
streamed_output: [ | ||
'', 'A', ' document', ' loader', ' is', | ||
' a', ' tool', ' used', ' to', ' load', | ||
' data', ' from', ' a', ' source', ' as', | ||
' `', 'Document', '`', "'", 's', | ||
',', ' which', ' are', ' pieces', ' of', | ||
' text', ' with', ' associated', ' metadata', '.', | ||
' It', ' can', ' load', ' data', ' from', | ||
' various', ' sources', ',', ' such', ' as', | ||
' a', ' simple', ' `.', 'txt', '`', | ||
' file', ',', ' the', ' text', ' contents', | ||
' of', ' a', ' web', ' page', ',', | ||
' or', ' a', ' transcript', ' of', ' a', | ||
' YouTube', ' video', '.', ' Document', ' loaders', | ||
' provide', ' a', ' "', 'load', '"', | ||
' method', ' for', ' loading', ' data', ' as', | ||
' documents', ' from', ' a', ' configured', ' source', | ||
' and', ' can', ' optionally', ' implement', ' a', | ||
' "', 'lazy', ' load', '"', ' for', | ||
' loading', ' data', ' into', ' memory', '.', | ||
' [', '1', ']', '' | ||
], | ||
final_output: 'A document loader is a tool used to load data from a source as `Document`\'s, which are pieces of text with associated metadata. It can load data from various sources, such as a simple `.txt` file, the text contents of a web page, or a transcript of a YouTube video. Document loaders provide a "load" method for loading data as documents from a configured source and can optionally implement a "lazy load" for loading data into memory. [1]', | ||
logs: { | ||
'RunnableParallel<question,chat_history>': [Object], | ||
'Itemgetter:question': [Object], | ||
SerializeHistory: [Object], | ||
RetrieveDocs: [Object], | ||
RunnableSequence: [Object], | ||
RunnableLambda: [Object], | ||
'RunnableLambda:2': [Object], | ||
FindDocs: [Object], | ||
HasChatHistoryCheck: [Object], | ||
GenerateResponse: [Object], | ||
RetrievalChainWithNoHistory: [Object], | ||
'Itemgetter:question:2': [Object], | ||
Retriever: [Object], | ||
format_docs: [Object], | ||
ChatPromptTemplate: [Object], | ||
ChatOpenAI: [Object], | ||
StrOutputParser: [Object] | ||
}, | ||
name: '/chat', | ||
type: 'chain' | ||
} | ||
} | ||
*/ |
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