Langchain 1.0 | Prompt template

Hi!

I used to use PromptTemplate to substitute variables in prompts, but now (in the new version of langchain js), as far as I understand, this functionality is no longer available in the regular langchain package. What should I use instead?

Hi @hwndrer

I can see that Manage prompts programmatically - Docs by LangChain and I still can create a prompty from template in V1 (V0 docs Prompt Templates | 🦜️🔗 Langchain):

import { PromptTemplate } from "@langchain/core/prompts";

const promptTemplate = PromptTemplate.fromTemplate(
  "Tell me a joke about {topic}"
);

(async function() {
    const prompt = await promptTemplate.invoke({ topic: "cats" });
    console.log(prompt.toChatMessages());
})()

Response:

[
  HumanMessage {
    "content": "Tell me a joke about cats",
    "additional_kwargs": {},
    "response_metadata": {}
  }
]

Hi @pawel-twardziak!

I am trying to import a template using the specified path, but I am getting the following error:

Hi @hwndrer

can you find this path node_modules/@langchain/core/dist/prompts/index.js in your node modules?
And what’s the exact version in your node_modules/@langchain/core/package.json?

Yes, i have this one.

I don’t know why my editor doesn’t suggest these paths. Additionally, I don’t have autocomplete (always returning any from .invoke() ) working for structured output, neither for the model (new ChatOpenAI) nor for agents (createAgent).


All is good. It’s just an IDE that misbehaves :slight_smile: What’s your IDE?

Hi!
I figured out why this was happening, and I had to change module and moduleresolution to nodenext.

1 Like
import { PromptTemplate } from "@langchain/core/prompts";

TS2307: Cannot find module @langchain/core/prompts or its corresponding type declarations. IDE is webstorm

Hi @GzRichChen

what is your package.json and tsconfg.json file?