-
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: shiyu22 <shiyu.chen@zilliz.com>
- Loading branch information
Showing
12 changed files
with
341 additions
and
23 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 |
---|---|---|
|
@@ -60,6 +60,7 @@ coverage.xml | |
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
*.db | ||
|
||
# Flask stuff: | ||
instance/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
|
||
from gptcache.adapter import openai | ||
from gptcache.core import cache, Config | ||
from gptcache.cache.factory import get_ss_data_manager | ||
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation | ||
import numpy as np | ||
|
||
|
||
d = 8 | ||
|
||
|
||
def mock_embeddings(data, **kwargs): | ||
return np.random.random((d, )).astype('float32') | ||
|
||
|
||
def run(): | ||
faiss_file = "faiss.index" | ||
has_data = os.path.isfile(faiss_file) | ||
data_manager = get_ss_data_manager("mariadb", "faiss", | ||
dimension=d, max_size=8, clean_size=2, top_k=3) | ||
cache.init(embedding_func=mock_embeddings, | ||
data_manager=data_manager, | ||
similarity_evaluation=SearchDistanceEvaluation(), | ||
config=Config( | ||
similarity_threshold=0, | ||
), | ||
) | ||
|
||
mock_messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "foo"} | ||
] | ||
if not has_data: | ||
for i in range(10): | ||
question = f"foo{i}" | ||
answer = f"receiver the foo {i}" | ||
cache.data_manager.save(question, answer, cache.embedding_func(question)) | ||
|
||
answer = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=mock_messages, | ||
) | ||
print(answer) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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,48 @@ | ||
import os | ||
|
||
from gptcache.adapter import openai | ||
from gptcache.core import cache, Config | ||
from gptcache.cache.factory import get_ss_data_manager | ||
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation | ||
import numpy as np | ||
|
||
|
||
d = 8 | ||
|
||
|
||
def mock_embeddings(data, **kwargs): | ||
return np.random.random((d, )).astype('float32') | ||
|
||
|
||
def run(): | ||
faiss_file = "faiss.index" | ||
has_data = os.path.isfile(faiss_file) | ||
data_manager = get_ss_data_manager("sqlserver", "faiss", | ||
dimension=d, max_size=8, clean_size=2, top_k=3) | ||
cache.init(embedding_func=mock_embeddings, | ||
data_manager=data_manager, | ||
similarity_evaluation=SearchDistanceEvaluation(), | ||
config=Config( | ||
similarity_threshold=0, | ||
), | ||
) | ||
|
||
mock_messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "foo"} | ||
] | ||
if not has_data: | ||
for i in range(10): | ||
question = f"foo{i}" | ||
answer = f"receiver the foo {i}" | ||
cache.data_manager.save(question, answer, cache.embedding_func(question)) | ||
|
||
answer = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=mock_messages, | ||
) | ||
print(answer) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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,48 @@ | ||
import os | ||
|
||
from gptcache.adapter import openai | ||
from gptcache.core import cache, Config | ||
from gptcache.cache.factory import get_ss_data_manager | ||
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation | ||
import numpy as np | ||
|
||
|
||
d = 8 | ||
|
||
|
||
def mock_embeddings(data, **kwargs): | ||
return np.random.random((d, )).astype('float32') | ||
|
||
|
||
def run(): | ||
faiss_file = "faiss.index" | ||
has_data = os.path.isfile(faiss_file) | ||
data_manager = get_ss_data_manager("mysql", "faiss", | ||
dimension=d, max_size=8, clean_size=2, top_k=3) | ||
cache.init(embedding_func=mock_embeddings, | ||
data_manager=data_manager, | ||
similarity_evaluation=SearchDistanceEvaluation(), | ||
config=Config( | ||
similarity_threshold=0, | ||
), | ||
) | ||
|
||
mock_messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "foo"} | ||
] | ||
if not has_data: | ||
for i in range(10): | ||
question = f"foo{i}" | ||
answer = f"receiver the foo {i}" | ||
cache.data_manager.save(question, answer, cache.embedding_func(question)) | ||
|
||
answer = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=mock_messages, | ||
) | ||
print(answer) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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,54 @@ | ||
from gptcache.utils import import_cxoracle | ||
import_cxoracle() | ||
|
||
import cx_Oracle | ||
import os | ||
|
||
from gptcache.adapter import openai | ||
from gptcache.core import cache, Config | ||
from gptcache.cache.factory import get_ss_data_manager | ||
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation | ||
import numpy as np | ||
|
||
|
||
d = 8 | ||
|
||
|
||
def mock_embeddings(data, **kwargs): | ||
return np.random.random((d, )).astype('float32') | ||
|
||
|
||
def run(): | ||
cx_Oracle.init_oracle_client(lib_dir="/Users/root/Downloads/instantclient_19_8") | ||
|
||
faiss_file = "faiss.index" | ||
has_data = os.path.isfile(faiss_file) | ||
data_manager = get_ss_data_manager("oracle", "faiss", | ||
dimension=d, max_size=8, clean_size=2, top_k=3) | ||
cache.init(embedding_func=mock_embeddings, | ||
data_manager=data_manager, | ||
similarity_evaluation=SearchDistanceEvaluation(), | ||
config=Config( | ||
similarity_threshold=0, | ||
), | ||
) | ||
|
||
mock_messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "foo"} | ||
] | ||
if not has_data: | ||
for i in range(10): | ||
question = f"foo{i}" | ||
answer = f"receiver the foo {i}" | ||
cache.data_manager.save(question, answer, cache.embedding_func(question)) | ||
|
||
answer = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=mock_messages, | ||
) | ||
print(answer) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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,48 @@ | ||
import os | ||
|
||
from gptcache.adapter import openai | ||
from gptcache.core import cache, Config | ||
from gptcache.cache.factory import get_ss_data_manager | ||
from gptcache.similarity_evaluation.simple import SearchDistanceEvaluation | ||
import numpy as np | ||
|
||
|
||
d = 8 | ||
|
||
|
||
def mock_embeddings(data, **kwargs): | ||
return np.random.random((d, )).astype('float32') | ||
|
||
|
||
def run(): | ||
faiss_file = "faiss.index" | ||
has_data = os.path.isfile(faiss_file) | ||
data_manager = get_ss_data_manager("postgresql", "faiss", | ||
dimension=d, max_size=8, clean_size=2, top_k=3) | ||
cache.init(embedding_func=mock_embeddings, | ||
data_manager=data_manager, | ||
similarity_evaluation=SearchDistanceEvaluation(), | ||
config=Config( | ||
similarity_threshold=0, | ||
), | ||
) | ||
|
||
mock_messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "foo"} | ||
] | ||
if not has_data: | ||
for i in range(10): | ||
question = f"foo{i}" | ||
answer = f"receiver the foo {i}" | ||
cache.data_manager.save(question, answer, cache.embedding_func(question)) | ||
|
||
answer = openai.ChatCompletion.create( | ||
model="gpt-3.5-turbo", | ||
messages=mock_messages, | ||
) | ||
print(answer) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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
Oops, something went wrong.