[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotprompt] Allow for synchronous references to prompt files. #513

Closed
mbleigh opened this issue Jun 28, 2024 · 0 comments · Fixed by #696
Closed

[dotprompt] Allow for synchronous references to prompt files. #513

mbleigh opened this issue Jun 28, 2024 · 0 comments · Fixed by #696
Assignees
Labels
feature New feature or request
Milestone

Comments

@mbleigh
Copy link
Collaborator
mbleigh commented Jun 28, 2024

At the moment, prompt is an async function that loads a prompt from the registry. This is in practice annoying because most of the time you want a prompt to be a high-level reference that is registered at the top level:

const myPrompt = prompt("myPrompt");

const myFlow = defineFlow({...}, input => {
  const result = myPrompt.generate(...);
});

Since top-level await is bad, this desirable pattern is not currently possible.

Proposal: PromptRef

Instead of prompt async returning a Dotprompt class, it can instead return a memoizing proxy ref, something like:

class DotpromptRef {
  name: string;
  private _prompt: Dotprompt;
  constructor(name: string) {
    this.name = name;
    this.loadPrompt(name);
  }

  private async loadPrompt(): Dotprompt {
    if (this._prompt) return this._prompt;
    this._prompt = await lookupPrompt(...);
    return this._prompt;
  }

  async generate(...) {
    return (await this.loadPrompt()).generate(...);
  }
  async render(...) { ... }
}

This way, a prompt reference can be loaded synchronously while still working exactly the same as the async version today in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants