[Bug]: Gptcache server: with OpenAi embedding cache seems to be not working properly.
Current Behavior
After i start the gptcache server with below command: python server.py (file is from https://github.com/zilliztech/GPTCache/tree/main/gptcache_server) -s 0.0.0.0 -p 8000 -of gptcache.yml -o True
the service is up and running. Now from a client program , when i make a request , for example:
- user question is - "President of pakistan" , i get a correct response but after this , when i post a new question , lets say
- "capital of India?" , the response for this question is the answer from the question "President of pakistan". Its retrieving from the cache. No matter how many new questions i ask , its the same answer from the cache.
This is happening , when i set embedding - "openai" in gptcache.yaml file.
Also irrespective of embedding, there is an issue in semantic cache.
- For "President of pakistan". and for "President of India" , the answer is same from the cache.
Expected Behavior
- When a client make a request to the gptcache server running , it should check whether there is a exact or similar cache entry in the cache, if so , the answer should be from the cache, else the answer should from open ai, and response to be stored in cache.
Steps To Reproduce
1) Copy the server.py from the gptcache_Server foler into a dir you want.
2) Configure gptcache.yaml file:
embedding:
openai
embedding_config:
# Set embedding model params here
storage_config:
data_dir:
/Users/swathinarayanan/tolka_feedback_sep/gptdocker/gptcache_server/gptcache_data
manager:
sqlite,faiss
vector_params:
# Set vector storage related params here
evaluation:
distance
evaluation_config:
# Set evaluation metric kws here
pre_function:
last_content
post_function:
first
config:
similarity_threshold: 0.8
# Set other config here
3) Start the server:
python server.py -s 0.0.0.0 -p 8000 -of gptcache.yml -o True
4) Create a client program or API call and make request to gptcache server.
Example program:
import requests
import json
import time
def call_chat_completions_endpoint(base_url, api_key, user_question):
# Endpoint URL
url = f"{base_url}/v1/chat/completions"
# Headers including the authorization token
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}'
}
# Request payload
payload = {
'model': 'gpt-3.5-turbo',
'messages': [{"role": "system", "content": "You are a helpful assistant."},
{'role': 'user', 'content': user_question}],
'top_k': 10,
}
# Send POST request
start_time = time.time()
response = requests.post(url, headers=headers, data=json.dumps(payload))
# Check if the request was successful
if response.status_code == 200:
# Process the successful response
print("Success:", response.json())
print("Time Consumed: {:.2f}s".format(time.time() - start_time))
else:
# Handle errors
print(f"Error: {response.status_code}, Message: {response.text}")
# Example usage
if __name__ == "__main__":
# Define the base URL of your FastAPI application
BASE_URL = "http://localhost:8000"
# Your API key for authorization (if needed)
API_KEY = "****************************"
# User question to be sent to the chat completions endpoint
USER_QUESTION = "what is coral reef ?"
call_chat_completions_endpoint(BASE_URL, API_KEY, USER_QUESTION)Environment
MAC OS
M1 chipAnything else?
The docker build image given by you not working, when running the docker getting below error:
successfully installed package: openai Traceback (most recent call last): File "/usr/local/bin/gptcache_server", line 5, in from gptcache_server.server import main File "/usr/local/lib/python3.8/site-packages/gptcache_server/server.py", line 8, in from gptcache.adapter import openai File "/usr/local/lib/python3.8/site-packages/gptcache/adapter/openai.py", line 31, in class ChatCompletion(openai.ChatCompletion, BaseCacheLLM): File "/usr/local/lib/python3.8/site-packages/openai/lib/_old_api.py", line 39, in call raise APIRemovedInV1(symbol=self._symbol) openai.lib._old_api.APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28
Source: zilliztech/GPTCache