2
3export const conversationalRetrievalQAChainStreamingExample = (async () => {
4 const { ChatOpenAI } = await import(
5 "https://esm.sh/langchain/chat_models/openai"
6 );
7 const { OpenAIEmbeddings } = await import(
8 "https://esm.sh/langchain/embeddings/openai"
9 );
10 const { BufferMemory } = await import("https://esm.sh/langchain/memory");
16 );
17 let streamedResponse = "";
18 const streamingModel = new ChatOpenAI({
19 openAIApiKey: process.env.OPENAI_API_KEY,
20 streaming: true,
21 callbacks: [{
25 }],
26 });
27 const nonStreamingModel = new ChatOpenAI({
28 openAIApiKey: process.env.OPENAI_API_KEY,
29 });
30 /* Create the vectorstore */
36 ],
37 [{ id: 2 }, { id: 1 }, { id: 3 }],
38 new OpenAIEmbeddings({
39 openAIApiKey: process.env.OPENAI_API_KEY,
40 }),
41 );
1export const getJoke = (async () => {
2 const { ChatCompletion } = await import("npm:openai");
3 const result = await ChatCompletion.create({
4 model: "gpt-3.5-turbo",
4 const builder = await getModelBuilder({
5 type: "chat",
6 provider: "openai",
7 });
8 const model = await builder();
4 const builder = await getMemoryBuilder({
5 type: "summary",
6 provider: "openai",
7 });
8 const memory = await builder();
3// Shows how to use the Brave Search tool in a LangChain agent
4export const braveAgent = (async () => {
5 const { ChatOpenAI } = await import(
6 "https://esm.sh/langchain/chat_models/openai"
7 );
8 const { BraveSearch } = await import("https://esm.sh/langchain/tools");
13 "https://esm.sh/langchain/agents"
14 );
15 const model = new ChatOpenAI({
16 temperature: 0,
17 openAIApiKey: process.env.OPENAI_API_KEY,
18 });
19 const tools = [
28 const imageURL =
29 (await textToImageDalle(
30 process.env.openai,
31 text,
32 1,
4 const builder = await getMemoryBuilder({
5 type: "vector",
6 provider: "openai",
7 });
8 const memory = await builder();
4
5export let autoGPT_Test = (async () => {
6 const { Configuration, OpenAIApi } = await import("npm:openai@3.2.1");
7 const configuration = new Configuration({
8 apiKey: process.env.openai,
9 });
10 const openai = new OpenAIApi(configuration);
11 const completion = await openai.createChatCompletion({
12 model: "gpt-4",
13 messages: [
2
3export const langchainEx = (async () => {
4 const { ChatOpenAI } = await import(
5 "https://esm.sh/langchain/chat_models/openai"
6 );
7 const { PromptTemplate } = await import("https://esm.sh/langchain/prompts");
8 const { LLMChain } = await import("https://esm.sh/langchain/chains");
9 const model = new ChatOpenAI({
10 temperature: 0.9,
11 openAIApiKey: process.env.OPENAI_API_KEY,
12 verbose: true,
13 });
2
3export const chatAgentWithCustomPrompt = (async () => {
4 const { ChatOpenAI } = await import(
5 "https://esm.sh/langchain/chat_models/openai"
6 );
7 const { initializeAgentExecutorWithOptions } = await import(
11 "https://esm.sh/langchain/tools/calculator"
12 );
13 const model = new ChatOpenAI({
14 temperature: 0,
15 openAIApiKey: process.env.OPENAI_API_KEY,
16 });
17 const tools = [