[错误]: Gptcache 服务器: 使用 OpenAI 嵌入缓存似乎没有正常工作。
1) Copy the server.py from the gptcache_Server folder into a directory you want. 2) Configure the 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 a request to the 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, # Set other config here } # 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:") # Print the time taken to process the request print(f"Time taken: {time.time() - start_time} seconds") else: # Handle the error response print("Error:", response.json())
内容来源: zilliztech/GPTCache