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

[Pre]: Bug fix _get_pattern_value() #645

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Kirushikesh
Copy link

When using the existing _get_pattern_value function for extracting the values i was getting the IndexError: list index out of range error.

Code to Reproduce:

from langchain import PromptTemplate
from gptcache.processor.pre import _get_pattern_value

template_obj = PromptTemplate.from_template("""
tell me a joke about {subject}:{object}
""")

prompt = template_obj.format(subject="animal",object = "dog")

result = _get_pattern_value(template_obj.template, prompt)
print(result)

Error Trace:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input [In [2]](vscode-notebook-cell:?execution_count=2), in <cell line: 10>()
      [4](vscode-notebook-cell:?execution_count=2&line=4) template_obj = PromptTemplate.from_template("""
      [5](vscode-notebook-cell:?execution_count=2&line=5) tell me a joke about {subject}:{object}
      [6](vscode-notebook-cell:?execution_count=2&line=6) """)
      [8](vscode-notebook-cell:?execution_count=2&line=8) prompt = template_obj.format(subject="animal",object = "dog")
---> [10](vscode-notebook-cell:?execution_count=2&line=10) result = _get_pattern_value(template_obj.template, prompt)
     [11](vscode-notebook-cell:?execution_count=2&line=11) print(result)

File /dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:72, in _get_pattern_value(pattern_str, value_str)
     [70](https://vscode-remote+ssh-002dremote-002bcccxl012-002epok-002eibm-002ecom.vscode-resource.vscode-cdn.net/dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:70)         break
     [71](https://vscode-remote+ssh-002dremote-002bcccxl012-002epok-002eibm-002ecom.vscode-resource.vscode-cdn.net/dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:71)     start += len(literal_text)
---> [72](https://vscode-remote+ssh-002dremote-002bcccxl012-002epok-002eibm-002ecom.vscode-resource.vscode-cdn.net/dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:72)     pattern_values[field_name_arr[i]] = value_str[start:end]
     [73](https://vscode-remote+ssh-002dremote-002bcccxl012-002epok-002eibm-002ecom.vscode-resource.vscode-cdn.net/dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:73)     last_end = end
     [74](https://vscode-remote+ssh-002dremote-002bcccxl012-002epok-002eibm-002ecom.vscode-resource.vscode-cdn.net/dccstor/kirushikesh/.conda/pdfrag/lib/python3.10/site-packages/gptcache/processor/pre.py:74) return pattern_values

IndexError: list index out of range

The changes covers the bug fix, but the warning still holds

WARNING: Two parameters without intervals cannot appear in the template,
for example: template = "{foo}{hoo}" is not supported,
but template = "{foo}:{hoo}" is supported

@sre-ci-robot sre-ci-robot requested a review from SimFG September 2, 2024 16:37
@sre-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Kirushikesh
To complete the pull request process, please assign cxie after the PR has been reviewed.
You can assign the PR to them by writing /assign @cxie in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot
Copy link
Collaborator

Welcome @Kirushikesh! It looks like this is your first PR to zilliztech/GPTCache 🎉

Signed-off-by: Kirushikesh <kirushikesh@gmail.com>
@mergify mergify bot added needs-dco and removed dco-passed labels Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants