Langchain js - can't get token usage
Labels: name: auto:question, name: area: models

### System Info

Langchain JS 0.0.172 on DEbian Linux 12 using Nodejs 18.15.0

With the following code I don't get the tokenUsage back from the chain/ call. I checked the docs, asked the AI and did a google search. Am I doing anything wrong?

`const chain = RetrievalQAChain.fromLLM(
  model,
  vectorStore.asRetriever(),
  {
    verbose: true,
  }
)
const res = await chain.call({
  context: "You assist a Systems Engineer. Be as concise as possible.",
  query: prompt,
})
console.log('usage:', res.tokenUsage);
`

### Who can help?

@hwchase17 

### Information

- [X] The official example notebooks/scripts
- [X] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

import { DirectoryLoader } from "langchain/document_loaders/fs/directory";
import { TextLoader } from "langchain/document_loaders/fs/text";
import { JSONLoader } from "langchain/document_loaders/fs/json";
import { CSVLoader } from "langchain/document_loaders/fs/csv";
import { OpenAI } from "langchain/llms/openai";
import { RetrievalQAChain, loadQARefineChain } from "langchain/chains";
import { HNSWLib } from "langchain/vectorstores/hnswlib";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import * as dotenv from 'dotenv';

dotenv.config()

const loader = new DirectoryLoader("./docs", {
  ".json": (path) => new JSONLoader(path),
  ".csv": (path) => new CSVLoader(path),
  ".txt": (path) => new TextLoader(path)
})

const normalizeDocuments = (docs) => {
  return docs.map((doc) => {
    if (typeof doc.pageContent === "string") {
      return doc.pageContent;
    } else if (Array.isArray(doc.pageContent)) {
      return doc.pageContent.join("\n");
    }
  });
}

const VECTOR_STORE_PATH = "Documents.index";

export const run = async (params) => {
  console.log("Loading docs...")
  const docs = await loader.load();

  console.log('Processing...')
  const model = new OpenAI({ 
    openAIApiKey: process.env.OPENAI_API_KEY,
    modelName: "gpt-3.5-turbo",
    maxTokens: 2500,
    temperature: 0.1,
    maxConcurrency: 1,
  });

  let vectorStore;
  
  try{
    console.log("Checking for local vectorStore");
    const embeddings = new OpenAIEmbeddings(process.env.OPENAI_API_KEY);
    vectorStore = await HNSWLib.load(VECTOR_STORE_PATH, embeddings);
  }catch(e){
    console.log('Creating new vector store...')
    const textSplitter = new RecursiveCharacterTextSplitter({
      chunkSize: 3000,
    });
    const normalizedDocs = normalizeDocuments(docs);
    const splitDocs = await textSplitter.createDocuments(normalizedDocs);
    console.log('splitdos : ',splitDocs)

    // 8. Generate the vector store from the documents
    vectorStore = await HNSWLib.fromDocuments(
      splitDocs,
      new OpenAIEmbeddings()
    );

    await vectorStore.save(VECTOR_STORE_PATH);
    console.log("Vector store created.")

  }

  console.log("Creating retrieval chain...")
  const chain = RetrievalQAChain.fromLLM(
    model, 
    vectorStore.asRetriever(),
    {
      verbose: true,
    }
  )

  //const promptStart = `rewrite all requirements using the following guidelines:`;
  const promptStart = ``;
  //const reWrite = `Rewrite the Requirement Text so that is does comply.`;
  const reWrite = ``;
  const prompts = [
                  `R3: Requirements should be consistent with each other and should not contain contradictions or conflicts. Report the Id\'s for those that do not comply. Rewrite the Requirement Text so that is does comply with R3 `,
                  ];

  prompts.forEach(async prompt => {
    //console.log("Querying chain...")
    const res = await chain.call({ 
      context: "You assist a Systems Engineer. Be as concise as possible.",
      query: prompt,
    })
    console.log('usage:', res.tokenUsage);

    console.log(prompt);
    console.log('Reply: ',res, '\n')
  });
}

run(process.argv.slice(2))

### Expected behavior

I expect the res object to return the token usage