Skip to main content

Using the API

Install the API client library

npm install dewy-ts

Connect to an instance of Dewy

import { Dewy } from 'dewy-ts';
const dewy = new Dewy({endpoint: “http://localhost:3000})

Add documents

await dewy.kb.addDocument({
collection: "main",
url: 'https://arxiv.org/abs/2005.11401',
})

Retrieve document chunks for LLM prompting

const context = await dewy.kb.retrieveChunks({
collection: "main",
query: "tell me about RAG",
n: 10,
});

// Minimal prompt example
const prompt = [
{
role: 'system',
content: `You are a helpful assistant.
You will take into account any CONTEXT BLOCK that is provided in a conversation.
START CONTEXT BLOCK
${context.results.map((c: any) => c.chunk.text).join("\n")}
END OF CONTEXT BLOCK
`,
},
]

// Using OpenAI to generate responses
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
stream: true,
messages: [...prompt, [{role: 'user': content: 'Tell me about RAG'}]]
})