repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | |
| #3 | import pytest |
| #4 | from chromadb.api.models.Collection import Collection |
| #5 | |
| #6 | from embedchain import App |
| #7 | from embedchain.config import AppConfig, ChromaDbConfig |
| #8 | from embedchain.embedchain import EmbedChain |
| #9 | from embedchain.llm.base import BaseLlm |
| #10 | from embedchain.memory.base import ChatHistory |
| #11 | from embedchain.vectordb.chroma import ChromaDB |
| #12 | |
| #13 | os.environ["OPENAI_API_KEY"] = "test-api-key" |
| #14 | |
| #15 | |
| #16 | @pytest.fixture |
| #17 | def app_instance(): |
| #18 | config = AppConfig(log_level="DEBUG", collect_metrics=False) |
| #19 | return App(config=config) |
| #20 | |
| #21 | |
| #22 | def test_whole_app(app_instance, mocker): |
| #23 | knowledge = "lorem ipsum dolor sit amet, consectetur adipiscing" |
| #24 | |
| #25 | mocker.patch.object(EmbedChain, "add") |
| #26 | mocker.patch.object(EmbedChain, "_retrieve_from_database") |
| #27 | mocker.patch.object(BaseLlm, "get_answer_from_llm", return_value=knowledge) |
| #28 | mocker.patch.object(BaseLlm, "get_llm_model_answer", return_value=knowledge) |
| #29 | mocker.patch.object(BaseLlm, "generate_prompt") |
| #30 | mocker.patch.object(BaseLlm, "add_history") |
| #31 | mocker.patch.object(ChatHistory, "delete", autospec=True) |
| #32 | |
| #33 | app_instance.add(knowledge, data_type="text") |
| #34 | app_instance.query("What text did I give you?") |
| #35 | app_instance.chat("What text did I give you?") |
| #36 | |
| #37 | assert BaseLlm.generate_prompt.call_count == 2 |
| #38 | app_instance.reset() |
| #39 | |
| #40 | |
| #41 | def test_add_after_reset(app_instance, mocker): |
| #42 | mocker.patch("embedchain.vectordb.chroma.chromadb.Client") |
| #43 | |
| #44 | config = AppConfig(log_level="DEBUG", collect_metrics=False) |
| #45 | chroma_config = ChromaDbConfig(allow_reset=True) |
| #46 | db = ChromaDB(config=chroma_config) |
| #47 | app_instance = App(config=config, db=db) |
| #48 | |
| #49 | # mock delete chat history |
| #50 | mocker.patch.object(ChatHistory, "delete", autospec=True) |
| #51 | |
| #52 | app_instance.reset() |
| #53 | |
| #54 | app_instance.db.client.heartbeat() |
| #55 | |
| #56 | mocker.patch.object(Collection, "add") |
| #57 | |
| #58 | app_instance.db.collection.add( |
| #59 | embeddings=[[1.1, 2.3, 3.2], [4.5, 6.9, 4.4], [1.1, 2.3, 3.2]], |
| #60 | metadatas=[ |
| #61 | {"chapter": "3", "verse": "16"}, |
| #62 | {"chapter": "3", "verse": "5"}, |
| #63 | {"chapter": "29", "verse": "11"}, |
| #64 | ], |
| #65 | ids=["id1", "id2", "id3"], |
| #66 | ) |
| #67 | |
| #68 | app_instance.reset() |
| #69 | |
| #70 | |
| #71 | def test_add_with_incorrect_content(app_instance, mocker): |
| #72 | content = [{"foo": "bar"}] |
| #73 | |
| #74 | with pytest.raises(TypeError): |
| #75 | app_instance.add(content, data_type="json") |
| #76 |