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

Using vars on rubricPrompt lacks serialization, leading to the failure of the entire assertion. #823

Closed
YiFanChen99 opened this issue May 28, 2024 · 3 comments

Comments

@YiFanChen99
Copy link
Contributor

I intend to use LLM2 to assist in evaluating the response of another LLM1.
Therefore, the vars for the first request will be passed to LLM2 again.
However, if the vars contain special characters (such as \n), it will lead to the failure of the entire llm-rubric assertion.

In the following example for a translation request.
An error occurs due to the \n in the vars.input. (... families are all alike. \nAnd every ...)
And removing this character will make the evaluation be successful.

example.yaml

prompts: >-
  [{
    "role": "system",
    "content": "Translate text into {{ language }}."
  }, {
    "role": "user",
    "content": "{{ input }}"
  }]
providers: [openai:gpt-3.5-turbo]
defaultTest:
  options:
    rubricPrompt:
      - role: system
        content: >-
          Evaluate the quality of the translation provided by an AI assistant to the user input displayed below.
          Score the response on a scale of 0 to 10.
          Output your response in the following JSON format: {pass: bool, score: number, reason: string}
      - role: user
        content: >-
          [Input Start]
          {{ input }}
          [Input End]

          [Translation Start]
          {{ output }}
          [Translation End]

tests:
  - vars:
      input: "Happy families are all alike. \nAnd every unhappy family is unhappy in its own way."
      language: "Chinese"
    assert:
      - type: llm-rubric

Will get the result:
image

Due to the unserialized input:
...\"content\":\"[Input Start] Happy families are all alike. \n And every unhappy family is unhappy in its own way. [Input End]\\n[Translation Start]...

Is there any workaround or maybe a better way to do this, please?

@typpo
Copy link
Collaborator

typpo commented Jun 9, 2024

Related to #759

@YiFanChen99
Copy link
Contributor Author

Hi typpo,

In my personal opinion, this doesn't seem to be related to issue #759.
The key difference is only about whether the tests.vars.input string contains special characters, which has nothing to do with the config generation.

Meanwhile, the problem I see is in the implementation of src/matchers.ts#fromVars.
Currently, it only stringifies object values, but the same treatment should be applied to string values as well.

Did you agree with this perspective?
If you do, I would be happy to submit a request to help fix it. (You can also fix it yourself directly.)

@typpo
Copy link
Collaborator

typpo commented Jun 13, 2024

Thank you for looking into this. I agree and would gladly accept a PR @YiFanChen99 !

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

No branches or pull requests

2 participants