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 | |
| #5 | from embedchain.config import BaseLlmConfig |
| #6 | from embedchain.llm.together import TogetherLlm |
| #7 | |
| #8 | |
| #9 | @pytest.fixture |
| #10 | def together_llm_config(): |
| #11 | os.environ["TOGETHER_API_KEY"] = "test_api_key" |
| #12 | config = BaseLlmConfig(model="together-ai-up-to-3b", max_tokens=50, temperature=0.7, top_p=0.8) |
| #13 | yield config |
| #14 | os.environ.pop("TOGETHER_API_KEY") |
| #15 | |
| #16 | |
| #17 | def test_init_raises_value_error_without_api_key(mocker): |
| #18 | mocker.patch.dict(os.environ, clear=True) |
| #19 | with pytest.raises(ValueError): |
| #20 | TogetherLlm() |
| #21 | |
| #22 | |
| #23 | def test_get_llm_model_answer_raises_value_error_for_system_prompt(together_llm_config): |
| #24 | llm = TogetherLlm(together_llm_config) |
| #25 | llm.config.system_prompt = "system_prompt" |
| #26 | with pytest.raises(ValueError): |
| #27 | llm.get_llm_model_answer("prompt") |
| #28 | |
| #29 | |
| #30 | def test_get_llm_model_answer(together_llm_config, mocker): |
| #31 | mocker.patch("embedchain.llm.together.TogetherLlm._get_answer", return_value="Test answer") |
| #32 | |
| #33 | llm = TogetherLlm(together_llm_config) |
| #34 | answer = llm.get_llm_model_answer("Test query") |
| #35 | |
| #36 | assert answer == "Test answer" |
| #37 | |
| #38 | |
| #39 | def test_get_llm_model_answer_with_token_usage(together_llm_config, mocker): |
| #40 | test_config = BaseLlmConfig( |
| #41 | temperature=together_llm_config.temperature, |
| #42 | max_tokens=together_llm_config.max_tokens, |
| #43 | top_p=together_llm_config.top_p, |
| #44 | model=together_llm_config.model, |
| #45 | token_usage=True, |
| #46 | ) |
| #47 | mocker.patch( |
| #48 | "embedchain.llm.together.TogetherLlm._get_answer", |
| #49 | return_value=("Test answer", {"prompt_tokens": 1, "completion_tokens": 2}), |
| #50 | ) |
| #51 | |
| #52 | llm = TogetherLlm(test_config) |
| #53 | answer, token_info = llm.get_llm_model_answer("Test query") |
| #54 | |
| #55 | assert answer == "Test answer" |
| #56 | assert token_info == { |
| #57 | "prompt_tokens": 1, |
| #58 | "completion_tokens": 2, |
| #59 | "total_tokens": 3, |
| #60 | "total_cost": 3e-07, |
| #61 | "cost_currency": "USD", |
| #62 | } |
| #63 | |
| #64 | |
| #65 | def test_get_answer_mocked_together(together_llm_config, mocker): |
| #66 | mocked_together = mocker.patch("embedchain.llm.together.ChatTogether") |
| #67 | mock_instance = mocked_together.return_value |
| #68 | mock_instance.invoke.return_value.content = "Mocked answer" |
| #69 | |
| #70 | llm = TogetherLlm(together_llm_config) |
| #71 | prompt = "Test query" |
| #72 | answer = llm.get_llm_model_answer(prompt) |
| #73 | |
| #74 | assert answer == "Mocked answer" |
| #75 |