chatgpt hello world with prompt
This commit is contained in:
parent
331d6ae41a
commit
307dfdccba
1
.env
Normal file
1
.env
Normal file
@ -0,0 +1 @@
|
||||
OPENAI_API_KEY="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"
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,3 +11,5 @@
|
||||
|
||||
#!.yarn/cache
|
||||
.pnp.*
|
||||
|
||||
node_modules
|
893
.yarn/releases/yarn-4.1.0.cjs
vendored
Executable file
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
3
.yarnrc.yml
Normal file
@ -0,0 +1,3 @@
|
||||
nodeLinker: node-modules
|
||||
|
||||
yarnPath: .yarn/releases/yarn-4.1.0.cjs
|
12
package.json
12
package.json
@ -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
23
src/index.js
Normal 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);
|
Loading…
x
Reference in New Issue
Block a user