Skip to content

Commit 12c4e1e

Browse files
committed
👌 IMPROVE: lint
1 parent 6724f01 commit 12c4e1e

15 files changed

+469
-887
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pytest -v
7979
8080
### 5. Run All Checks at Once
8181
```bash
82-
# This runs all pre-commit hooks (black, isort, ruff, mypy)
82+
# This runs all pre-commit hooks (black, isort)
8383
pre-commit run --all-files
8484
```
8585

langbase/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
429: "RateLimitError",
2727
}
2828

29+
BASE_URL = "https://api.langbase.com"
2930
# API Endpoints
3031
PIPES_ENDPOINT = "/v1/pipes"
3132
PIPE_DETAIL_ENDPOINT = "/v1/pipes/{name}"

langbase/langbase.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def __init__(self, api_key: str = "", base_url: str = "https://api.langbase.com"
3131
Initialize the Langbase client.
3232
3333
Args:
34-
api_key: The API key for authentication. If not provided, it will be read
35-
from the LANGBASE_API_KEY environment variable.
34+
api_key: The API key for authentication.
3635
base_url: The base URL for the API.
3736
"""
3837
self.base_url = base_url

langbase/primitives/parser.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@ def parser(
4747
Returns:
4848
Dictionary with document name and extracted content
4949
"""
50-
files = convert_document_to_request_files(document, document_name, content_type)
50+
document_content = convert_document_to_request_files(
51+
document, document_name, content_type
52+
)
5153

52-
response = requests.post(
53-
f"{self.parent.base_url}{PARSER_ENDPOINT}",
54+
response = self.request.post(
55+
PARSER_ENDPOINT,
5456
headers={"Authorization": f"Bearer {self.parent.api_key}"},
55-
files=files,
57+
document=document_content,
5658
)
5759

58-
if not response.ok:
59-
self.request.handle_error_response(response)
60+
# Transform API response: rename documentName to document_name
61+
if isinstance(response, dict) and "documentName" in response:
62+
response["document_name"] = response.pop("documentName")
63+
64+
print("response", response)
6065

61-
return response.json()
66+
return response

langbase/primitives/threads.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def update(self, thread_id: str, metadata: Dict[str, str]) -> ThreadsBaseRespons
7979
Returns:
8080
Updated thread object
8181
"""
82-
options = {"threadId": thread_id, "metadata": metadata}
82+
options = {"metadata": metadata}
8383
return self.request.post(
8484
THREAD_DETAIL_ENDPOINT.format(thread_id=thread_id), options
8585
)
@@ -121,8 +121,10 @@ def append(
121121
Returns:
122122
List of added messages
123123
"""
124+
options = {"messages": messages}
125+
124126
return self.request.post(
125-
THREAD_MESSAGES_ENDPOINT.format(thread_id=thread_id), messages
127+
THREAD_MESSAGES_ENDPOINT.format(thread_id=thread_id), options
126128
)
127129

128130
def list(self, thread_id: str) -> List[ThreadMessagesBaseResponse]:

langbase/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def post(
316316
body: Optional[Dict[str, Any]] = None,
317317
headers: Optional[Dict[str, str]] = None,
318318
stream: bool = False,
319-
files: Optional[Dict[str, Any]] = None,
319+
document: Optional[Dict[str, Any]] = None,
320320
) -> Any:
321321
"""
322322
Send a POST request to the API.
@@ -331,7 +331,7 @@ def post(
331331
Returns:
332332
Processed API response
333333
"""
334-
return self.send(endpoint, "POST", headers, body, stream, files)
334+
return self.send(endpoint, "POST", headers, body, stream, document)
335335

336336
def get(
337337
self,

langbase/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Message(TypedDict, total=False):
8383
"""Basic message structure."""
8484

8585
role: Role
86-
content: string | NULL
86+
content: Optional[str]
8787
name: Optional[str]
8888
tool_call_id: Optional[str]
8989
tool_calls: Optional[List[ToolCall]]

requirements-dev.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ responses>=0.23.0
1111
black>=22.1.0
1212
isort>=5.10.1
1313

14-
# Type checking
15-
mypy>=1.0.0
16-
types-requests>=2.28.0
17-
18-
# Linting
19-
ruff>=0.1.0
20-
2114
# Pre-commit hooks
2215
pre-commit>=3.0.0
2316

@@ -27,4 +20,4 @@ twine>=4.0.0
2720

2821
# Development utilities
2922
ipdb>=0.13.0
30-
python-dotenv>=0.19.0
23+
python-dotenv>=0.19.0

tests/conftest.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,33 @@ def mock_responses():
186186
"created_at": timestamp,
187187
"metadata": {},
188188
},
189+
"threads_create_with_metadata": {
190+
"id": "thread_123",
191+
"object": "thread",
192+
"created_at": timestamp,
193+
"metadata": {"user_id": "123", "session": "abc"},
194+
},
195+
"threads_create_with_thread_id": {
196+
"id": "custom_thread_456",
197+
"object": "thread",
198+
"created_at": timestamp,
199+
"metadata": {},
200+
},
201+
"threads_create_with_messages": {
202+
"id": "thread_123",
203+
"object": "thread",
204+
"created_at": timestamp,
205+
"metadata": {},
206+
"messages": [
207+
{"role": "user", "content": "Hello"},
208+
{"role": "assistant", "content": "Hi there!"},
209+
],
210+
},
189211
"threads_update": {
190212
"id": "thread_123",
191213
"object": "thread",
192214
"created_at": timestamp,
193-
"metadata": {"updated": "true"},
215+
"metadata": {"user_id": "123", "session": "abc"},
194216
},
195217
"threads_get": {
196218
"id": "thread_123",
@@ -244,7 +266,7 @@ def mock_responses():
244266
"embed": [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]],
245267
"chunker": ["First chunk", "Second chunk", "Third chunk"],
246268
"parser": {
247-
"document_name": "test.pdf",
269+
"documentName": "test.pdf",
248270
"content": "Parsed document content from test.pdf",
249271
},
250272
# Agent run response (similar to pipe run)

tests/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
AUTHORIZATION_HEADER = {
2+
"Authorization": "Bearer test-api-key",
3+
}
4+
5+
JSON_CONTENT_TYPE_HEADER = {
6+
"Content-Type": "application/json",
7+
}
8+
9+
AUTH_AND_JSON_CONTENT_HEADER = {
10+
**AUTHORIZATION_HEADER,
11+
**JSON_CONTENT_TYPE_HEADER,
12+
}

0 commit comments

Comments
 (0)