-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SimFG <bang.fu@zilliz.com>
- Loading branch information
Showing
6 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import time | ||
|
||
from langchain import OpenAI | ||
from langchain.chains.question_answering import load_qa_chain | ||
from langchain.schema import Document | ||
|
||
from gptcache import cache | ||
from gptcache.adapter.api import init_similar_cache | ||
from gptcache.adapter.langchain_models import LangChainLLMs | ||
|
||
|
||
def get_content_func(data, **_): | ||
return data.get("prompt").split("Question:")[-1] | ||
|
||
|
||
init_similar_cache(pre_func=get_content_func) | ||
cache.set_openai_key() | ||
|
||
mkt_qa = load_qa_chain(llm=LangChainLLMs(llm=OpenAI(temperature=0)), chain_type="stuff") | ||
|
||
msg = "What is Traditional marketing?" | ||
|
||
|
||
before = time.time() | ||
answer = mkt_qa.run(question=msg, input_documents=[Document(page_content="marketing is hello world")]) | ||
print(answer) | ||
print("Time Spent:", time.time() - before) | ||
|
||
before = time.time() | ||
answer = mkt_qa.run(question=msg, input_documents=[Document(page_content="marketing is hello world")]) | ||
print(answer) | ||
print("Time Spent:", time.time() - before) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters