langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.52k stars 2.14k forks source link

Design Question: feasibility of other prompt loaders? (Specifically for Google's Maker Suite) #2564

Closed afirstenberg closed 10 months ago

afirstenberg commented 1 year ago

Google's Maker Suite allows you to build prompt templates (including model details and prompt variables) and save them to Google Drive. It would be useful to be able to load these files directly.

The loadPrompt() function, however, only seems to support the LangChain hub and the local file system. And it only seems to load the template itself. Are there thoughts about reasonable ways to extend this loader? Or would it make sense to have a specialty loader that can return the template, return a new model, or return a new LLMChain with both of these?

Thoughts, @jacoblee93?

dosubot[bot] commented 1 year ago

🤖

Hi @jacoblee93,

Thanks for your question. The current architecture of LangChain does indeed allow for the integration of external storage services like Google Drive. We have an implementation of a document store using Google Cloud Storage (GCS), which is a part of Google Drive's infrastructure. You can find the relevant code in the langchain/src/stores/doc/gcs.ts file.

As for the loadPrompt() function, you're correct that it currently only supports the LangChain hub and the local file system. However, it's certainly feasible to extend this function to support loading from Google Drive. We could add a new method to the GoogleCloudStorageDocstore class to load a prompt template from a GCS bucket, and then modify the loadPrompt() function to call this new method when appropriate.

Here's a rough idea of what the new method in the GoogleCloudStorageDocstore class might look like:

async loadPromptTemplate(fileName: string): Promise<PromptTemplate> {
  const file = await this.getFile(fileName);
  return new PromptTemplate(file);
}

And here's how we could modify the loadPrompt() function:

async function loadPrompt(source: string): Promise<PromptTemplate> {
  if (source.startsWith('gs://')) {
    const fileName = source.slice(5);
    const docstore = new GoogleCloudStorageDocstore({ bucket: 'my-bucket' });
    return await docstore.loadPromptTemplate(fileName);
  }
  // existing code...
}

This is just a rough idea, and the actual implementation might be a bit more complex, especially when it comes to error handling and edge cases. But I hope this gives you a good starting point.

As for your suggestion of a specialty loader that can return the template, return a new model, or return a new LLMChain with both of these, that's an interesting idea. It would certainly make the API more flexible and powerful. However, it would also make the implementation more complex, and it might be overkill for most use cases. I'd be interested to hear more about your use case and why you think this would be useful.

I hope this answers your question. If you have any further questions or need clarification on anything, please don't hesitate to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

jacoblee93 commented 1 year ago

We've actually deprecated the loadPrompt method in favor of a new hub:

https://docs.smith.langchain.com/category/hub

We could certainly have other options though that serialize to LangChain prompts!

afirstenberg commented 1 year ago

Given how specific it is, would it make sense to include it as part of LangChain (and, if so, under what module? Since it clearly doesn't make sense at the top level like hub is), or as a completely separate package which has methods with a similar signature?

And the FAQ for hubs says "Hub currently only supports LangChain prompt objects. We are working on adding support for more!" Are the plans to include other configuration information (model used, temp, etc), or something else?

dosubot[bot] commented 10 months ago

Hi, @afirstenberg,

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, the issue discusses the feasibility of adding support for loading prompt templates from Google's Maker Suite directly into the loadPrompt() function. There have been discussions about extending the loader to return the template, a new model, or a new LLMChain, as well as considerations about including the functionality as part of LangChain or as a separate package. However, it seems that the issue remains unresolved.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

afirstenberg commented 10 months ago

This was implemented in #2733 and merged. Closing

dosubot[bot] commented 10 months ago

Thank you, @afirstenberg, for closing the issue! Your contribution is much appreciated.