-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (34 loc) · 1.11 KB
/
index.js
File metadata and controls
43 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as dotenv from 'dotenv'
import { PineconeClient } from '@pinecone-database/pinecone'
import * as readline from 'readline'
import { PromptTemplate } from 'langchain/prompts'
import { queryPineconeVectorStoreAndQueryLLM } from './utils/queryPineconeAndQueryLLM.js'
dotenv.config()
const client = new PineconeClient()
await client.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT
})
function askQuestion(query) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
return new Promise((resolve) =>
rl.question(query, (ans) => {
rl.close()
resolve(ans)
})
)
}
const question = await askQuestion('Fai una domanda ')
const prompt = PromptTemplate.fromTemplate(
`Respond to the following question in the most complete way possible. {question}?`
)
const formattedPrompt = await prompt.format({
question
})
const indexName = process.env.PINECONE_INDEX_NAME
;(async () => {
await queryPineconeVectorStoreAndQueryLLM(client, indexName, formattedPrompt)
})()