import langchain import time from langchain.llms import OpenAI from langchain.cache import InMemoryCache from langchain.cache import SQLiteCache from redis import Redis from langchain.cache import RedisCache # InMemoryCache or SQLiteCache or RedisCache # use 'rm .langchain.db' to delete db when use SQLiteCache。 # langchain.llm_cache = InMemoryCache() # langchain.llm_cache = SQLiteCache() # langchain.llm_cache = RedisCache(redis_=Redis()) llm = OpenAI(model_name="text-davinci-002", n=2, best_of=2) start = time.perf_counter() print(llm("今日中国新闻有哪些")) print("first suspend:", time.perf_counter() - start) start = time.perf_counter() print(llm("今日中国新闻有哪些")) print("second suspend:{:0.10f}".format(time.perf_counter() - start))