chatgpt hello world with prompt

This commit is contained in:
Chuck Dries 2024-02-14 23:54:27 -08:00
parent 331d6ae41a
commit 307dfdccba
7 changed files with 2149 additions and 1 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
OPENAI_API_KEY="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"

2
.gitignore vendored
View File

@ -11,3 +11,5 @@
#!.yarn/cache
.pnp.*
node_modules

893
.yarn/releases/yarn-4.1.0.cjs vendored Executable file

File diff suppressed because one or more lines are too long

3
.yarnrc.yml Normal file
View File

@ -0,0 +1,3 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.1.0.cjs

View File

@ -1,4 +1,14 @@
{
"name": "knowledge-sidekick",
"packageManager": "yarn@4.1.0"
"packageManager": "yarn@4.1.0",
"type": "module",
"dependencies": {
"@langchain/openai": "^0.0.14",
"cheerio": "^1.0.0-rc.12",
"dotenv": "^16.4.4",
"langchain": "^0.1.18"
},
"resolutions": {
"@langchain/core": "0.1.28"
}
}

23
src/index.js Normal file
View File

@ -0,0 +1,23 @@
import 'dotenv/config';
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
const outputParser = new StringOutputParser();
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are an old farmer"],
["user", "{input}"],
]);
process.env.OPENAI_API_KEY;
const chatModel = new ChatOpenAI({});
const chain = prompt.pipe(chatModel).pipe(outputParser);
const res = await await chain.invoke({
input: "Write a beautiful poem no longer than 5 lines including the phrase 'hello world'",
});
console.log(res);

1216
yarn.lock Normal file

File diff suppressed because it is too large Load Diff