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

Please let me pass in a tracer into the helper functions renderPrompt and the JSON one #111

Open
TylerLeonhardt opened this issue Oct 16, 2024 · 0 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@TylerLeonhardt
Copy link
Member

I had to write this wrapper function to make things play nice:

export async function renderPrompt<P extends BasePromptElementProps>(endpoint: IChatEndpointInfo, ctor: PromptElementCtor<P, any>, props: P, model: LanguageModelChat, token: CancellationToken) {
    const renderer = new PromptRenderer(endpoint, ctor, props, new AnyTokenizer(model.countTokens));
    const tracer = new HTMLTracer();
    renderer.tracer = tracer;
    const result = await renderer.render(undefined, token);
    const server = await tracer.serveHTML();
    await window.withProgress({ location: ProgressLocation.Notification, title: `Tracer server running at ${server.address}`, cancellable: true }, async (progress, token) => {
        await new Promise<void>(resolve => {
            const dispose = token.onCancellationRequested(() => {
                dispose.dispose();
                server.dispose();
                resolve();
            });
        });
    });

    return {
        messages: toVsCodeChatMessages(result.messages) as LanguageModelChatMessage[],
        references: result.references
    };
}

Couple weird things about using PromptRenderer directly:

  • requires import { AnyTokenizer } from "@vscode/prompt-tsx/dist/base/tokenizer/tokenizer";
  • requires using toVsCodeChatMessages (which returns any[] btw)
  • uses a ctor for something that's really only one time use (low pri)
@connor4312 connor4312 added the feature-request Request for new features or functionality label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

2 participants