olbrain-python-sdk 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {olbrain_python_sdk-0.5.0/olbrain_python_sdk.egg-info → olbrain_python_sdk-0.5.1}/PKG-INFO +1 -1
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/AGENTS.md +4 -2
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/__init__.py +1 -1
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/client.py +6 -7
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/olbrain.py +2 -1
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1/olbrain_python_sdk.egg-info}/PKG-INFO +1 -1
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/SOURCES.txt +1 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/setup.py +1 -1
- olbrain_python_sdk-0.5.1/tests/conftest.py +7 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_client.py +9 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_olbrain.py +5 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/.gitignore +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/LICENSE +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/MANIFEST.in +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/README.md +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/advanced_features.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/basic_usage.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/error_handling.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/session_management.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/examples/streaming_responses.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/exceptions.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/research.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/session.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/streaming.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain/utils.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/dependency_links.txt +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/not-zip-safe +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/requires.txt +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/top_level.txt +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/pyproject.toml +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/requirements.txt +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/setup.cfg +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/__init__.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_exceptions.py +0 -0
- {olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/tests/test_session.py +0 -0
|
@@ -56,7 +56,8 @@ with AgentClient(agent_id="your-agent-id", api_key=os.environ["OLBRAIN_API_KEY"]
|
|
|
56
56
|
- `agent_id`: required. An empty value raises `ValueError`.
|
|
57
57
|
- `api_key`: must start with `ak_`, `sk_live_`, `org_live_`, `sk_` or `org_`,
|
|
58
58
|
or the constructor raises `ValueError`.
|
|
59
|
-
- `agent_url`: optional. Defaults to `
|
|
59
|
+
- `agent_url`: optional. Defaults to the `OLBRAIN_AGENT_URL` environment
|
|
60
|
+
variable if set, otherwise `https://webhook.olbrain.com`.
|
|
60
61
|
|
|
61
62
|
Chat calls are `POST {agent_url}/api/agents/webhook/{agent_id}` with
|
|
62
63
|
`Authorization: Bearer <api_key>`. Session reads are
|
|
@@ -146,7 +147,8 @@ olbrain = Olbrain(api_key=os.environ["OLBRAIN_API_KEY"]) # server / sc
|
|
|
146
147
|
|
|
147
148
|
`Olbrain(api_key=None, get_id_token=None, base_url=None, timeout=30)`:
|
|
148
149
|
`api_key` must start `ak_`; `get_id_token` is a callable returning the
|
|
149
|
-
token and is called before **every** request; `base_url` defaults to
|
|
150
|
+
token and is called before **every** request; `base_url` defaults to the
|
|
151
|
+
`OLBRAIN_AGENT_URL` environment variable if set, otherwise
|
|
150
152
|
`https://webhook.olbrain.com`; `timeout` is in seconds. Give **exactly one** of
|
|
151
153
|
`api_key` or `get_id_token`, or the constructor raises `ValidationError`.
|
|
152
154
|
|
|
@@ -9,6 +9,7 @@ FIXES:
|
|
|
9
9
|
- send_and_wait() now works correctly
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
+
import os
|
|
12
13
|
import requests
|
|
13
14
|
import logging
|
|
14
15
|
import time
|
|
@@ -150,7 +151,8 @@ class AgentClient:
|
|
|
150
151
|
Args:
|
|
151
152
|
agent_id: Agent identifier
|
|
152
153
|
api_key: Access key (ak_…); 'sk_live_', 'org_live_', 'sk_' and 'org_' are also accepted
|
|
153
|
-
agent_url: Optional
|
|
154
|
+
agent_url: Optional API base URL. Falls back to the OLBRAIN_AGENT_URL
|
|
155
|
+
environment variable, then https://webhook.olbrain.com
|
|
154
156
|
|
|
155
157
|
Raises:
|
|
156
158
|
ValueError: If agent_id or api_key is invalid
|
|
@@ -167,12 +169,9 @@ class AgentClient:
|
|
|
167
169
|
self.agent_id = agent_id
|
|
168
170
|
self.api_key = api_key
|
|
169
171
|
|
|
170
|
-
#
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
else:
|
|
174
|
-
# The Olbrain API. The old run.app host this SDK defaulted to no longer exists.
|
|
175
|
-
self.agent_url = "https://webhook.olbrain.com"
|
|
172
|
+
# Explicit argument, then OLBRAIN_AGENT_URL, then the Olbrain API
|
|
173
|
+
agent_url = agent_url or os.environ.get("OLBRAIN_AGENT_URL") or "https://webhook.olbrain.com"
|
|
174
|
+
self.agent_url = agent_url.rstrip('/')
|
|
176
175
|
|
|
177
176
|
self._streams = {} # session_id -> MessageStream
|
|
178
177
|
self._running = False
|
|
@@ -5,6 +5,7 @@ Olbrain sign-in (get_id_token). The same API as the JavaScript SDK's `Olbrain`.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import json
|
|
8
|
+
import os
|
|
8
9
|
from types import SimpleNamespace
|
|
9
10
|
from typing import Any, Callable, Dict, Iterator, Optional
|
|
10
11
|
from urllib.parse import urlencode
|
|
@@ -70,7 +71,7 @@ class Olbrain:
|
|
|
70
71
|
raise ValidationError("api_key must be an Olbrain access key (ak_…)")
|
|
71
72
|
self._api_key = api_key
|
|
72
73
|
self._get_id_token = get_id_token
|
|
73
|
-
self.base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
|
|
74
|
+
self.base_url = (base_url or os.environ.get("OLBRAIN_AGENT_URL") or DEFAULT_BASE_URL).rstrip("/")
|
|
74
75
|
self.timeout = timeout
|
|
75
76
|
|
|
76
77
|
def runs(agent_id):
|
|
@@ -26,6 +26,15 @@ class TestAgentClient:
|
|
|
26
26
|
client = AgentClient(agent_id="a1", api_key="ak_test", agent_url="https://custom.example/")
|
|
27
27
|
assert client.agent_url == "https://custom.example"
|
|
28
28
|
|
|
29
|
+
def test_env_url(self, monkeypatch):
|
|
30
|
+
monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080/")
|
|
31
|
+
assert AgentClient(agent_id="a1", api_key="ak_test").agent_url == "http://localhost:8080"
|
|
32
|
+
|
|
33
|
+
def test_argument_beats_env_url(self, monkeypatch):
|
|
34
|
+
monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080")
|
|
35
|
+
client = AgentClient(agent_id="a1", api_key="ak_test", agent_url="https://custom.example")
|
|
36
|
+
assert client.agent_url == "https://custom.example"
|
|
37
|
+
|
|
29
38
|
def test_chat_goes_to_the_agent_webhook(self, client, requests_mock):
|
|
30
39
|
requests_mock.post(CHAT, json={"session_id": "s1", "response": "Hi", "success": True})
|
|
31
40
|
assert client.create_session(title="Hello") == "s1"
|
|
@@ -36,6 +36,11 @@ class TestConfig:
|
|
|
36
36
|
with pytest.raises(ValidationError, match="ak_"):
|
|
37
37
|
Olbrain(api_key="sk_live_x")
|
|
38
38
|
|
|
39
|
+
def test_env_url(self, monkeypatch):
|
|
40
|
+
monkeypatch.setenv("OLBRAIN_AGENT_URL", "http://localhost:8080/")
|
|
41
|
+
assert Olbrain(api_key="ak_test").base_url == "http://localhost:8080"
|
|
42
|
+
assert Olbrain(api_key="ak_test", base_url="https://custom.example").base_url == "https://custom.example"
|
|
43
|
+
|
|
39
44
|
def test_asks_for_a_fresh_sign_in_token_on_every_call(self, requests_mock):
|
|
40
45
|
tokens = iter(["t1", "t2"])
|
|
41
46
|
olbrain = Olbrain(get_id_token=lambda: next(tokens))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/requires.txt
RENAMED
|
File without changes
|
{olbrain_python_sdk-0.5.0 → olbrain_python_sdk-0.5.1}/olbrain_python_sdk.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|