Skip to content

Commit

Permalink
Updating package
Browse files Browse the repository at this point in the history
  • Loading branch information
JimVincentW committed Dec 23, 2024
1 parent a919527 commit 309ec01
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion opol/python-client/autopush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Binary file removed opol/python-client/dist/opol-0.1.17.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added opol/python-client/dist/opol-0.1.18.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion opol/python-client/opol.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 13 additions & 13 deletions opol/python-client/opol/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
26 changes: 16 additions & 10 deletions opol/python-client/prototype.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2612,16 +2612,22 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"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"
]
}
],
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion opol/python-client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion opol/python-client/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# setup.cfg
[metadata]
name = opol
version = 0.1.17
version = 0.1.18
author = Jim Vincent Wagner
author_email = [email protected]
description = Main API client to interact with all opol services.
Expand Down

0 comments on commit 309ec01

Please sign in to comment.