Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hub Types #758

Merged
merged 21 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
pydantic-version: ["1.10.9", "2.4.2"]
openai-version: ["1.2.4"]
steps:
- uses: actions/checkout@v4
Expand All @@ -71,7 +70,6 @@ jobs:
# TODO: fix errors so that we can run `make dev` instead
run: |
make full
poetry run pip install pydantic==${{ matrix.pydantic-version }}
poetry run pip install openai==${{ matrix.openai-version }}

- name: Static analysis with pyright
Expand All @@ -86,7 +84,6 @@ jobs:
# TODO: fix errors so that we can run both `make dev` and `make full`
# dependencies: ['dev', 'full']
dependencies: ["full"]
pydantic-version: ["1.10.9", "2.4.2"]
openai-version: ["1.2.4"]
steps:
- uses: actions/checkout@v4
Expand All @@ -107,7 +104,6 @@ jobs:
- name: Install Dependencies
run: |
make ${{ matrix.dependencies }}
poetry run pip install pydantic==${{ matrix.pydantic-version }}
poetry run pip install openai==${{ matrix.openai-version }}

- name: Run Pytests
Expand Down
14 changes: 7 additions & 7 deletions guardrails/cli/hub/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from typing import List, Literal, Union

import typer
from guardrails_hub_types import Manifest
from pydash.strings import snake_case

from guardrails.classes.generic import Stack
from guardrails.cli.hub.hub import hub_command
from guardrails.cli.logger import LEVELS, logger
from guardrails.cli.server.hub_client import get_validator_manifest
from guardrails.cli.server.module_manifest import ModuleManifest

from .console import console

Expand Down Expand Up @@ -81,22 +81,22 @@ def get_site_packages_location():
return pip_location


def get_org_and_package_dirs(manifest: ModuleManifest) -> List[str]:
def get_org_and_package_dirs(manifest: Manifest) -> List[str]:
org_name = manifest.namespace
package_name = manifest.package_name
org = snake_case(org_name if len(org_name) > 1 else "")
package = snake_case(package_name if len(package_name) > 1 else package_name)
return list(filter(None, [org, package]))


def get_hub_directory(manifest: ModuleManifest, site_packages: str) -> str:
def get_hub_directory(manifest: Manifest, site_packages: str) -> str:
org_package = get_org_and_package_dirs(manifest)
return os.path.join(site_packages, "guardrails", "hub", *org_package)


# NOTE: I don't like this but don't see another way without
# shimming the init file with all hub validators
def add_to_hub_inits(manifest: ModuleManifest, site_packages: str):
def add_to_hub_inits(manifest: Manifest, site_packages: str):
org_package = get_org_and_package_dirs(manifest)
exports: List[str] = manifest.exports or []
sorted_exports = sorted(exports, reverse=True)
Expand Down Expand Up @@ -141,7 +141,7 @@ def add_to_hub_inits(manifest: ModuleManifest, site_packages: str):
namespace_init.close()


def run_post_install(manifest: ModuleManifest, site_packages: str):
def run_post_install(manifest: Manifest, site_packages: str):
org_package = get_org_and_package_dirs(manifest)
post_install_script = manifest.post_install

Expand Down Expand Up @@ -180,7 +180,7 @@ def run_post_install(manifest: ModuleManifest, site_packages: str):
sys.exit(1)


def get_install_url(manifest: ModuleManifest) -> str:
def get_install_url(manifest: Manifest) -> str:
repo = manifest.repository
repo_url = repo.url
branch = repo.branch
Expand All @@ -195,7 +195,7 @@ def get_install_url(manifest: ModuleManifest) -> str:
return git_url


def install_hub_module(module_manifest: ModuleManifest, site_packages: str):
def install_hub_module(module_manifest: Manifest, site_packages: str):
install_url = get_install_url(module_manifest)
install_directory = get_hub_directory(module_manifest, site_packages)

Expand Down
6 changes: 3 additions & 3 deletions guardrails/cli/server/hub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from typing import Any, Dict, Optional

import requests
from guardrails_hub_types import Manifest
from jwt import JWT
from jwt.exceptions import JWTDecodeError

from guardrails.classes.credentials import Credentials
from guardrails.cli.logger import logger
from guardrails.cli.server.module_manifest import ModuleManifest

TOKEN_EXPIRED_MESSAGE = (
"Your token has expired. Please run `guardrails configure` to update your token."
Expand Down Expand Up @@ -86,12 +86,12 @@ def get_jwt_token(creds: Credentials) -> Optional[str]:
return token


def fetch_module(module_name: str) -> ModuleManifest:
def fetch_module(module_name: str) -> Optional[Manifest]:
creds = Credentials.from_rc_file(logger)
token = get_jwt_token(creds)

module_manifest_json = fetch_module_manifest(module_name, token, creds.id)
return ModuleManifest.from_dict(module_manifest_json)
return Manifest.from_dict(module_manifest_json)


# GET /validator-manifests/{namespace}/{validatorName}
Expand Down
62 changes: 0 additions & 62 deletions guardrails/cli/server/module_manifest.py

This file was deleted.

24 changes: 19 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python = "^3.8.1"
lxml = "^4.9.3"
openai = "<2"
rich = "^13.6.0"
pydantic = ">=1.10.9, <3.0"
pydantic = ">=2.0, <3.0"
typer = {extras = ["all"], version = "^0.9.0"}
griffe = "^0.36.9"
tenacity = ">=8.1.0"
Expand Down Expand Up @@ -56,8 +56,9 @@ opentelemetry-exporter-otlp-proto-http = "1.20.0"
langchain-core = "^0.1.18"
coloredlogs = "^15.0.1"
requests = "^2.31.0"
guardrails-api-client = "^0.1.1"
guardrails-api-client = ">=0.2.1, <0.3"
jwt = "^1.3.1"
guardrails-hub-types = "^0.0.3"

[tool.poetry.extras]
sql = ["sqlvalidator", "sqlalchemy", "sqlglot"]
Expand Down
Loading
Loading