zilliztech / GPTCache

Semantic cache for LLMs. Fully integrated with LangChain and llama_index.
https://gptcache.readthedocs.io
MIT License
6.89k stars 480 forks source link

Fix last_content_without_template #599

Closed ziyi-curiousthing closed 6 months ago

ziyi-curiousthing commented 6 months ago

Fix last_content_without_template when the template looks like "Tell me a joke about {subject} with less than 50 words." where len(field_name_arr) < len(literal_text_arr). Existing implementation error out like the following:

Traceback (most recent call last):
  File "/Users/zz/src/GPTCache/sbert_match.py", line 62, in <module>
    response = openai.ChatCompletion.create(
  File "/Users/zz/src/GPTCache/gptcache/adapter/openai.py", line 125, in create
    return adapt(
  File "/Users/zz/src/GPTCache/gptcache/adapter/adapter.py", line 55, in adapt
    pre_embedding_res = time_cal(
  File "/Users/zz/src/GPTCache/gptcache/utils/time.py", line 9, in inner
    res = func(*args, **kwargs)
  File "/Users/zz/src/GPTCache/gptcache/processor/pre.py", line 134, in last_content_without_template
    pattern_value = _get_pattern_value(cache_config.template, last_content_str)
  File "/Users/zz/src/GPTCache/gptcache/processor/pre.py", line 72, in _get_pattern_value
    pattern_values[field_name_arr[i]] = value_str[start:end]
IndexError: list index out of range
sre-ci-robot commented 6 months ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ziyi-curiousthing 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: - **[OWNERS](https://github.com/zilliztech/GPTCache/blob/dev/OWNERS)** 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 commented 6 months ago

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

SimFG commented 6 months ago

@ziyi-curiousthing thanks your contribution!

ziyi-curiousthing commented 6 months ago

@SimFG It looks like unittest is failing due to missing dependency. I am not sure how to fix it.

SimFG commented 6 months ago

@ziyi-curiousthing i will check it