diff --git a/README.md b/README.md index a06c4f0..5cc465b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ openai_reply = openai_chat.query("Say test") claude_chat = TB.chat('claude-3-5-sonnet-20241022') claude_reply = claude_chat.query("Say test") +groq_chat = TB.chat('gemma2-9b-it') +groq_reply = groq_chat.query("Say test") + # OLLAMA_PROXY_URL set for URL, can handle Basic Auth in URL ollama_chat = TB.chat('ollama/gemma2:2b') ollama_reply = ollama_chat.query("Say test") @@ -31,6 +34,9 @@ ollama_user_info = ollama_chat.query("Extract the name and the age: 'John is 20 # Using instructor[anthropic] claude_user_info = claude_chat.query("Extract the name and the age: 'John is 20 years old'", UserInfo) +# Using instructor[groq] +groq_user_info = groq_chat.query("Extract the name and the age: 'John is 20 years old'", UserInfo) + ``` # Install diff --git a/tests/test_105_synopsis.py b/tests/test_105_synopsis.py new file mode 100644 index 0000000..70f956d --- /dev/null +++ b/tests/test_105_synopsis.py @@ -0,0 +1,69 @@ +import unittest +import warnings +import os +from unittest.mock import patch +import requests +from tackleberry import TB +from tackleberry.chat import TBChat +from tackleberry.context import TBContext +from pydantic import BaseModel + +import sys + +class UserInfo(BaseModel): + name: str + age: int + +class TestTB(unittest.TestCase): + + def test_010_openai(self): + """Test OpenAI""" + if os.environ.get("OPENAI_API_KEY"): + openai_chat = TB.chat('gpt-4o-mini') + self.assertIsInstance(openai_chat, TBChat) + openai_reply = openai_chat.query("Say test") + self.assertTrue(len(openai_reply) > 0, "Reply shouldn't be empty") + else: + warnings.warn("Can't test OpenAI runtime without OPENAI_API_KEY", UserWarning) + + def test_020_anthropic(self): + """Test Anthropic""" + if os.environ.get("ANTHROPIC_API_KEY"): + claude_chat = TB.chat('claude-3-5-sonnet-20241022') + self.assertIsInstance(claude_chat, TBChat) + claude_reply = claude_chat.query("Say test") + self.assertTrue(len(claude_reply) > 0, "Reply shouldn't be empty") + else: + warnings.warn("Can't test Anthropic runtime without ANTHROPIC_API_KEY", UserWarning) + + def test_030_groq(self): + """Test Groq""" + if os.environ.get("GROQ_API_KEY"): + groq_chat = TB.chat('gemma2-9b-it') + self.assertIsInstance(groq_chat, TBChat) + groq_reply = groq_chat.query("Say test") + self.assertTrue(len(groq_reply) > 0, "Reply shouldn't be empty") + groq_user_info = groq_chat.query("Extract the name and the age: 'John is 20 years old'", UserInfo) + self.assertIsInstance(groq_user_info, UserInfo) + self.assertEqual(groq_user_info.name, "John") + self.assertEqual(groq_user_info.age, 20) + else: + warnings.warn("Can't test Groq runtime without GROQ_API_KEY", UserWarning) + + def test_040_ollama(self): + """Test Ollama""" + ollama_model = os.environ.get("TACKLEBERRY_OLLAMA_TEST_MODEL") or 'gemma2:2b' + if os.environ.get("OLLAMA_HOST") or os.environ.get("OLLAMA_PROXY_URL"): + ollama_chat = TB.chat('ollama/'+ollama_model) + self.assertIsInstance(ollama_chat, TBChat) + ollama_reply = ollama_chat.query("Say test") + self.assertTrue(len(ollama_reply) > 0, "Reply shouldn't be empty") + ollama_user_info = ollama_chat.query("Extract the name and the age: 'John is 20 years old'", UserInfo) + self.assertIsInstance(ollama_user_info, UserInfo) + self.assertEqual(ollama_user_info.name, "John") + self.assertEqual(ollama_user_info.age, 20) + else: + warnings.warn("Can't test Ollama runtime without explicit setting OLLAMA_HOST or OLLAMA_PROXY_URL", UserWarning) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/tests/test_110_standard_query.py b/tests/test_110_standard_query.py index 56e380e..1346f91 100644 --- a/tests/test_110_standard_query.py +++ b/tests/test_110_standard_query.py @@ -42,7 +42,7 @@ def test_030_groq(self): def test_040_ollama(self): """Test Ollama""" ollama_model = os.environ.get("TACKLEBERRY_OLLAMA_TEST_MODEL") or 'gemma2:2b' - if (os.environ.get("OLLAMA_HOST") or os.environ.get("OLLAMA_PROXY_URL")) and ollama_model: + if os.environ.get("OLLAMA_HOST") or os.environ.get("OLLAMA_PROXY_URL"): chat = TB.chat('ollama/'+ollama_model) test_resp = chat.query("Say test") self.assertIsInstance(test_resp, str)