Skip to content

Commit

Permalink
fix: make sure that not applying a host is fine (#79)
Browse files Browse the repository at this point in the history
test is fine
  • Loading branch information
viveknair committed Apr 28, 2023
1 parent 59c72d1 commit 0708570
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 1 addition & 2 deletions examples/examples/simple/openai/create-completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
load_dotenv()

gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/api/v1"
gentrace.log_level = "info"

gentrace.configure_openai()

openai.api_key = os.getenv("OPENAI_KEY")

result = openai.Completion.create(
pipeline_id="text-generation-test",
pipeline_id="text-generation-test-2",
model="text-davinci-003",
prompt_template="Hello world {{ name }}",
prompt_inputs={"name": "test"},
Expand Down
8 changes: 4 additions & 4 deletions examples/poetry.lock

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

2 changes: 1 addition & 1 deletion examples/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ openai = "^0.27.4"
pinecone-client = "^2.2.1"
python = "^3.11"
python-dotenv = "^1.0.0"
gentrace-py = {path = "../package/dist/gentrace_py-0.5.6.tar.gz", develop = true}
gentrace-py = {path = "../package/dist/gentrace_py-0.7.1.tar.gz", develop = true}

[tool.poetry.group.lint.dependencies]
black = "^23.3.0"
Expand Down
8 changes: 7 additions & 1 deletion package/gentrace/providers/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def test_validity():
if not api_key:
raise ValueError("Gentrace API key not set")

# Totally fine (and expected) to not have a host set
if not host:
return

path = parse_url(host).path

if host and path != "/api/v1" and path != "/api/v1/":
Expand All @@ -28,7 +32,9 @@ def configure_openai():

test_validity()

gentrace_config = GentraceConfiguration(host=host)
resolved_host = host if host else "https://gentrace.ai/api/v1"

gentrace_config = GentraceConfiguration(host=resolved_host)
gentrace_config.access_token = api_key

annotate_openai_module(gentrace_config=gentrace_config)
Expand Down
8 changes: 8 additions & 0 deletions package/tests/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import gentrace


def test_gentrace_no_host_valid():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")

gentrace.configure_openai()

gentrace.api_key = ""


def test_gentrace_localhost_host_valid():
gentrace.api_key = os.getenv("GENTRACE_API_KEY")
gentrace.host = "http://localhost:3000/"
Expand Down

0 comments on commit 0708570

Please sign in to comment.