diff --git a/opol/python-client/autopush.sh b/opol/python-client/autopush.sh index b8d437d..0b20d33 100644 --- a/opol/python-client/autopush.sh +++ b/opol/python-client/autopush.sh @@ -13,7 +13,7 @@ python3 -m build # Use python3 if python is not available git add . # Commit changes with a message -git commit -m "Updating package (oops)" +git commit -m "Updating package" VERSION=$(grep -oP '(?<=version = )\d+\.\d+\.\d+' setup.cfg) diff --git a/opol/python-client/dist/opol-0.1.17.tar.gz b/opol/python-client/dist/opol-0.1.17.tar.gz deleted file mode 100644 index 5098c96..0000000 Binary files a/opol/python-client/dist/opol-0.1.17.tar.gz and /dev/null differ diff --git a/opol/python-client/dist/opol-0.1.17-py3-none-any.whl b/opol/python-client/dist/opol-0.1.18-py3-none-any.whl similarity index 68% rename from opol/python-client/dist/opol-0.1.17-py3-none-any.whl rename to opol/python-client/dist/opol-0.1.18-py3-none-any.whl index b15ebdb..c0edc72 100644 Binary files a/opol/python-client/dist/opol-0.1.17-py3-none-any.whl and b/opol/python-client/dist/opol-0.1.18-py3-none-any.whl differ diff --git a/opol/python-client/dist/opol-0.1.18.tar.gz b/opol/python-client/dist/opol-0.1.18.tar.gz new file mode 100644 index 0000000..a497574 Binary files /dev/null and b/opol/python-client/dist/opol-0.1.18.tar.gz differ diff --git a/opol/python-client/opol.egg-info/PKG-INFO b/opol/python-client/opol.egg-info/PKG-INFO index 96ddae3..eebcc80 100644 --- a/opol/python-client/opol.egg-info/PKG-INFO +++ b/opol/python-client/opol.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: opol -Version: 0.1.17 +Version: 0.1.18 Summary: Main API client to interact with all OPOL services. Home-page: https://github.com/open-politics/opol Author: Jim Vincent Wagner diff --git a/opol/python-client/opol/main.py b/opol/python-client/opol/main.py index 24a5915..73564da 100644 --- a/opol/python-client/opol/main.py +++ b/opol/python-client/opol/main.py @@ -10,23 +10,23 @@ class OPOL: """ Main API client to interact with all OPOL services. """ - def __init__( - self, - mode: str = None, - api_key: str = None, - timeout: int = 60, - provider: str = "Google", - model_name: str = "models/gemini-1.5-flash-latest", - llm_api_key: str = None): - + def __init__(self, mode: str = None, api_key: str = None, timeout: int = 60): mode = mode if mode else os.getenv('OPOL_MODE', 'remote') - - # Opol Services self.geo = Geo(mode, api_key, timeout=timeout) self.articles = Articles(mode, api_key, timeout=timeout) self.entities = Entities(mode, api_key, timeout=timeout) self.scraping = Scraping(mode, api_key, timeout=timeout) self.legislation = Legislation(mode, api_key, timeout=timeout) + self._classification = None # Lazy initialization - # Classification Service (usage with Ollama or LLM provider) - self.classification = Classification(mode, api_key, timeout=timeout, provider=provider, model_name=model_name, llm_api_key=llm_api_key) \ No newline at end of file + def classification(self, provider: str = "Google", model_name: str = "models/gemini-1.5-flash-latest", llm_api_key: str = None): + if not self._classification: + self._classification = Classification( + mode=os.getenv('OPOL_MODE', 'remote'), + api_key=os.getenv('OPOL_API_KEY', None), + timeout=60, + provider=provider, + model_name=model_name, + llm_api_key=llm_api_key + ) + return self._classification \ No newline at end of file diff --git a/opol/python-client/prototype.ipynb b/opol/python-client/prototype.ipynb index 50b2fc6..c066a15 100644 --- a/opol/python-client/prototype.ipynb +++ b/opol/python-client/prototype.ipynb @@ -2612,7 +2612,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -2620,8 +2620,14 @@ "output_type": "stream", "text": [ "User preference rating: 10\n", - "Extracted keywords: ['madagascan', 'wilds', 'biggest', 'animal', 'elephant']\n", - "Classified request: keywords=['madagascar', 'wildlife', 'elephant'] relevance_level=8\n" + "Extracted keywords: ['madagascan wilds', 'elephant', 'globe finance trade', 'offshore jurisdiction diffusion']\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Classified request: keywords=['madagascar', 'elephant', 'wildlife', 'global finance', 'offshore jurisdiction', 'diffusion'] relevance_level=7\n" ] } ], @@ -2634,23 +2640,23 @@ "opol = OPOL(mode=\"local\")\n", "\n", "# Set the API key for accessing the Google Generative AI service\n", - "# api_key = \"\" # oops\n", + "# api_key = \"\"\n", "api_key = os.environ[\"GOOGLE_API_KEY\"]\n", "\n", "\n", "# Initialize the classification service with the specified provider, model, and API key\n", - "opol.classification(provider=\"Google\", model_name=\"models/gemini-1.5-flash-latest\", llm_api_key=api_key)\n", + "xclass = opol.classification(provider=\"Google\", model_name=\"models/gemini-1.5-flash-latest\", llm_api_key=api_key)\n", "\n", "# Example 1: Classify user preference for frozen dairy products on a scale of 1 to 10\n", "user_input = \"I love ice cream\"\n", "prompt = \"On a 1-10 scale how much the user likes frozen dairy products\"\n", - "int_value = opol.classification.classify(\"int\", prompt, user_input)\n", + "int_value = xclass.classify(\"int\", prompt, user_input)\n", "print(\"User preference rating:\", int_value)\n", "\n", "# Example 2: Extract keywords from a given text\n", - "text = \"In the madagascan wilds the biggest animal is the elephant\"\n", - "instruction = \"The keywords relevant to this text. Only semantically relevant to a content system\"\n", - "keywords = opol.classification.classify(\"List[str]\", instruction, text)\n", + "text = \"In the madagascan wilds the biggest wild animal is the elephant in the globe finance trade is offshore jusrisdiction diffusion\"\n", + "instruction = \"The topics relevant to this text. Only semantically relevant to a content system\"\n", + "keywords = xclass.classify(\"List[str]\", instruction, text)\n", "print(\"Extracted keywords:\", keywords)\n", "\n", "# Example 3: Use a Pydantic model to classify request types with keywords and relevance level\n", @@ -2665,7 +2671,7 @@ " relevance_level: int = Field(description=\"On a 1-10 scale how much the content is relevant\")\n", "\n", "# Classify the request using the Pydantic model\n", - "request = opol.classification.classify(RequestType, instruction, text)\n", + "request = xclass.classify(RequestType, instruction, text)\n", "print(\"Classified request:\", request)\n", "\n", "## Results\n", diff --git a/opol/python-client/pyproject.toml b/opol/python-client/pyproject.toml index f36ccbc..b495210 100644 --- a/opol/python-client/pyproject.toml +++ b/opol/python-client/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "opol" -version = "0.1.17" +version = "0.1.18" description = "Main API client to interact with all OPOL services." authors = [ { name = "Jim Vincent Wagner", email = "jimvw@open-politics.org" } diff --git a/opol/python-client/setup.cfg b/opol/python-client/setup.cfg index 987f817..04f66d6 100644 --- a/opol/python-client/setup.cfg +++ b/opol/python-client/setup.cfg @@ -1,7 +1,7 @@ # setup.cfg [metadata] name = opol -version = 0.1.17 +version = 0.1.18 author = Jim Vincent Wagner author_email = jimvw@open-politics.org description = Main API client to interact with all opol services.