cleanup
This commit is contained in:
parent
298596e47e
commit
e3b7dcb870
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "knowledge-sidekick",
|
"name": "langchain-quickstart",
|
||||||
"packageManager": "yarn@4.1.0",
|
"packageManager": "yarn@4.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
27
src/index.js
27
src/index.js
@ -1,8 +1,7 @@
|
|||||||
import 'dotenv/config';
|
import "dotenv/config";
|
||||||
process.env.OPENAI_API_KEY;
|
process.env.OPENAI_API_KEY;
|
||||||
import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
||||||
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
||||||
import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
||||||
import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
||||||
import { createRetrievalChain } from "langchain/chains/retrieval";
|
import { createRetrievalChain } from "langchain/chains/retrieval";
|
||||||
import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
|
||||||
@ -11,9 +10,7 @@ import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";
|
|||||||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
||||||
|
|
||||||
const chatModel = new ChatOpenAI({});
|
const chatModel = new ChatOpenAI({});
|
||||||
const loader = new CheerioWebBaseLoader(
|
const loader = new CheerioWebBaseLoader("https://docs.smith.langchain.com/");
|
||||||
"https://docs.smith.langchain.com/"
|
|
||||||
);
|
|
||||||
|
|
||||||
const docs = await loader.load();
|
const docs = await loader.load();
|
||||||
|
|
||||||
@ -30,14 +27,15 @@ const vectorstore = await MemoryVectorStore.fromDocuments(
|
|||||||
|
|
||||||
const retriever = vectorstore.asRetriever();
|
const retriever = vectorstore.asRetriever();
|
||||||
|
|
||||||
const prompt =
|
const prompt = ChatPromptTemplate.fromTemplate(
|
||||||
ChatPromptTemplate.fromTemplate(`Answer the following question based only on the provided context:
|
`Answer the following question based only on the provided context:
|
||||||
|
|
||||||
<context>
|
<context>
|
||||||
{context}
|
{context}
|
||||||
</context>
|
</context>
|
||||||
|
|
||||||
Question: {input}`);
|
Question: {input}`
|
||||||
|
);
|
||||||
|
|
||||||
const documentChain = await createStuffDocumentsChain({
|
const documentChain = await createStuffDocumentsChain({
|
||||||
llm: chatModel,
|
llm: chatModel,
|
||||||
@ -49,19 +47,8 @@ const retrievalChain = await createRetrievalChain({
|
|||||||
retriever,
|
retriever,
|
||||||
});
|
});
|
||||||
|
|
||||||
const outputParser = new StringOutputParser();
|
|
||||||
|
|
||||||
// const prompt = ChatPromptTemplate.fromMessages([
|
|
||||||
// ["system", "You are an old farmer"],
|
|
||||||
// ["user", "{input}"],
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const chain = prompt.pipe(chatModel).pipe(outputParser);
|
|
||||||
|
|
||||||
const res = await retrievalChain.invoke({
|
const res = await retrievalChain.invoke({
|
||||||
input: "What is langsmith",
|
input: "What is langsmith",
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user