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

Adding yaml prompt support to other models #72

Closed
therealpaulgg opened this issue Jul 18, 2023 · 1 comment · Fixed by #74
Closed

Adding yaml prompt support to other models #72

therealpaulgg opened this issue Jul 18, 2023 · 1 comment · Fixed by #74

Comments

@therealpaulgg
Copy link
Contributor

Hey,

I was trying to use the new yaml prompt file feature but realized that it's currently only supported with OpenAI.

I see this is the code that does it:

 const trimmedPrompt = prompt.trim();
    if (trimmedPrompt.startsWith('- role:')) {
      try {
        // Try YAML
        messages = yaml.load(prompt) as { role: string; content: string }[];
      } catch (err) {
        throw new Error(
          `OpenAI Chat Completion prompt is not a valid YAML string: ${err}\n\n${prompt}`,
        );
      }
    } else {
      try {
        // Try JSON
        messages = JSON.parse(prompt) as { role: string; content: string }[];
      } catch (err) {
        if (
          process.env.PROMPTFOO_REQUIRE_JSON_PROMPTS ||
          trimmedPrompt.startsWith('{') ||
          trimmedPrompt.startsWith('[')
        ) {
          throw new Error(
            `OpenAI Chat Completion prompt is not a valid JSON string: ${err}\n\n${prompt}`,
          );
        }

        // Fall back to wrapping the prompt in a user message
        messages = [{ role: 'user', content: prompt }];
      }
    }

Wondering if this code should be moved out to a preprocessing layer before the provider is called, that way it would be called regardless of the provider. Thoughts?

@typpo
Copy link
Collaborator

typpo commented Jul 21, 2023

Thanks Paul - this went out in version 0.17.6!

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

Successfully merging a pull request may close this issue.

2 participants