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

Auth Update #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
.python-version
__pycache__/
build
*.egg-info
*.egg-info
.venv
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -9,7 +9,7 @@ license = {file = "LICENSE"}
readme = "README.md"
requires-python = ">= 3.8.1"
dependencies = [
"guardrails-ai>=0.4.0",
"guardrails-ai>=0.4.2",
"pydantic>=2.4.2",
"tenacity>=8.1.0",
"transformers>=4.11.3",
Expand Down
14 changes: 4 additions & 10 deletions validator/main.py
@@ -1,4 +1,4 @@
import contextvars
import os
import json
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

Expand All @@ -11,6 +11,7 @@
Validator,
register_validator,
)
from guardrails.stores.context import get_call_kwarg
from tenacity import retry, stop_after_attempt, wait_random_exponential
from transformers import pipeline

Expand Down Expand Up @@ -125,15 +126,8 @@ def get_topic_llm(self, text: str, candidate_topics: List[str]) -> ValidationRes
return self.verify_topic(topic)

def get_client_args(self) -> Tuple[Optional[str], Optional[str]]:
kwargs = {}
context_copy = contextvars.copy_context()
for key, context_var in context_copy.items():
if key.name == "kwargs" and isinstance(kwargs, dict):
kwargs = context_var
break

api_key = kwargs.get("api_key")
api_base = kwargs.get("api_base")
api_key = get_call_kwarg("api_key") or os.environ.get("OPENAI_API_KEY")
api_base = get_call_kwarg("api_base") or os.environ.get("OPENAI_API_BASE")

return (api_key, api_base)

Expand Down