-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
241 additions
and
60 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
Empty file.
Empty file.
Empty file.
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,42 @@ | ||
import os | ||
|
||
import pytest | ||
from dotenv import load_dotenv | ||
|
||
from arcan.ai.llm import LLM, ChatGroq, ChatOpenAI, LLMFactory, OpenAI | ||
|
||
load_dotenv() | ||
|
||
|
||
def test_create_llm_chatopenai(): | ||
llm = LLMFactory.create_llm("ChatOpenAI", temperature=0.7) | ||
assert isinstance(llm, ChatOpenAI) | ||
assert llm.temperature == 0.7 | ||
assert llm.model_name == os.getenv("OPENAI_MODEL", "gpt-3.5-turbo-0125") | ||
|
||
def test_create_llm_chattogetherai(): | ||
llm = LLMFactory.create_llm("ChatTogetherAI", temperature=0.7) | ||
assert isinstance(llm, ChatOpenAI) | ||
assert llm.temperature == 0.7 | ||
assert llm.model_name == "mistralai/Mixtral-8x7B-Instruct-v0.1" | ||
assert llm.openai_api_base == "https://api.together.xyz/v1" | ||
|
||
def test_create_llm_chatgroq(): | ||
llm = LLMFactory.create_llm("ChatGroq", temperature=0.7) | ||
assert isinstance(llm, ChatGroq) | ||
assert llm.temperature == 0.7 | ||
assert llm.model_name == "llama3-8b-8192" | ||
|
||
def test_create_llm_not_implemented(): | ||
with pytest.raises(NotImplementedError): | ||
LLMFactory.create_llm("InvalidProvider") | ||
|
||
|
||
def test_llm_factory_create_llm_with_known_provider(): | ||
llm = LLMFactory.create_llm(provider="ChatOpenAI") | ||
assert isinstance(llm, ChatOpenAI) | ||
|
||
|
||
def test_llm_factory_create_llm_with_unknown_provider(): | ||
with pytest.raises(NotImplementedError): | ||
LLMFactory.create_llm(provider="UnknownProvider") |
Empty file.
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,94 @@ | ||
import os | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
from httpx import AsyncClient | ||
from sqlalchemy.orm import Session | ||
|
||
from arcan.api import app # Adjust this import based on your project structure | ||
from arcan.api.datamodels import get_db | ||
from arcan.api.session import ArcanSession | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_redirect_root_to_docs(): | ||
async with AsyncClient(app=app, base_url="http://test") as ac: | ||
response = await ac.get("/") | ||
assert response.status_code == 307 # Redirect status code | ||
assert response.headers["location"] == "/docs" | ||
|
||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_index(): | ||
async with AsyncClient(app=app, base_url="http://test") as ac: | ||
response = await ac.get("/api/check") | ||
assert response.status_code == 200 | ||
assert response.json() == {"message": "Arcan is Running!"} | ||
|
||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
|
||
@pytest.mark.asyncio | ||
@patch('arcan.api.datamodels.get_db') # Correct the import path as necessary | ||
async def test_chat(mock_get_db): | ||
# Create a mock session | ||
mock_session = MagicMock() | ||
mock_get_db.return_value = mock_session | ||
|
||
# Mock specific behaviors, e.g., query handling | ||
# mock_session.query.return_value.filter.return_value.one.return_value = YourUserModel(id="1", name="Test User") | ||
|
||
# # Set up a test response for `run_agent` if needed | ||
# with patch('your_module_path.run_agent') as mock_run_agent: | ||
# mock_run_agent.return_value = "Test Response" | ||
|
||
async with AsyncClient(app=app, base_url="http://test") as ac: | ||
response = await ac.get("/api/chat", params={"user_id": "test_user", "query": "testinggggg$#@"}) | ||
assert response.status_code == 200 | ||
assert response.json() == {"response": "test"} | ||
|
||
|
||
|
||
# def test_llm_endpoints(): | ||
# response = client.get("/openai") | ||
# assert response.status_code == 200 | ||
|
||
# response = client.get("/groq") | ||
# assert response.status_code == 200 | ||
|
||
# response = client.get("/together") | ||
# assert response.status_code == 200 | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# # Initialize the test client | ||
# client = TestClient(app) | ||
|
||
# def test_redirect_root_to_docs(): | ||
# response = client.get("/") | ||
# assert response.status_code == 307 | ||
# assert response.headers["location"] == "/docs" | ||
|
||
# def test_check_api(): | ||
# response = client.get("/api/check") | ||
# assert response.status_code == 200 | ||
# assert response.json() == {"message": "Arcan is Running!"} | ||
|
||
# def test_chat_api(): | ||
# user_id = "test_user" | ||
# query = "Hello, Arcan!" | ||
# response = client.get(f"/api/chat?user_id={user_id}&query={query}") | ||
# assert response.status_code == 200 | ||
# assert "response" in response.json() | ||
|