No project description provided
Project description
pylangdb
pylangdb is a Python package for interacting with LangDb APIs. Please find out more at https://langdb.ai/.
Installation
To install pylangdb, use pip:
pip install pylangdb
Usage
Initialize LangDb Client
from pylangdb import LangDb
# Initialize with API key and project ID
client = LangDb(api_key="your_api_key", project_id="your_project_id")
Chat Completions
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello!"}
]
response = client.completion(
model="gemini-1.5-pro-latest",
messages=messages,
temperature=0.7,
max_tokens=100
)
Thread Operations
Get Messages
Retrieve messages from a specific thread:
messages = client.get_messages(thread_id="your_thread_id")
# Access message details
for message in messages:
print(f"Type: {message.type}")
print(f"Content: {message.content}")
if message.tool_calls:
for tool_call in message.tool_calls:
print(f"Tool: {tool_call.function.name}")
Get Thread Cost
Get cost and token usage information for a thread:
usage = client.get_usage(thread_id="your_thread_id")
print(f"Total cost: ${usage.total_cost:.4f}")
print(f"Input tokens: {usage.total_input_tokens}")
print(f"Output tokens: {usage.total_output_tokens}")
Analytics
Get analytics data for specific tags:
# Get raw analytics data
analytics = client.get_analytics(
tags="model1,model2",
start_time_us=None, # Optional: defaults to 24 hours ago
end_time_us=None # Optional: defaults to current time
)
# Get analytics as a pandas DataFrame
df = client.get_analytics_dataframe(
tags="model1,model2",
start_time_us=None,
end_time_us=None
)
Development
Setting up the environment
- Clone the repository
- Create a
.envfile with your credentials:
LANGDB_API_KEY="your_api_key"
LANGDB_PROJECT_ID="your_project_id"
Running Tests
python -m unittest tests/client.py -v
Publishing
poetry build
poetry publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pylangdb-0.2.4.tar.gz
(5.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylangdb-0.2.4.tar.gz.
File metadata
- Download URL: pylangdb-0.2.4.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.12 Linux/5.15.0-131-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a85ec6421893032890a1314a570a8575b2af260a99e4766d1f1a4496ac9f7d4
|
|
| MD5 |
40121ae553b5f90ea1f462db65d26b0d
|
|
| BLAKE2b-256 |
0064509a2f6d57feb1fa33f25926936c7d3bd85818b9cd477bac2ce5163ca00b
|
File details
Details for the file pylangdb-0.2.4-py3-none-any.whl.
File metadata
- Download URL: pylangdb-0.2.4-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.10.12 Linux/5.15.0-131-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5db56e6d27068f3cee52ff67b3f9b3f42494c450acbb9e1ccec3b5e16f9c9447
|
|
| MD5 |
328ed8d08806c9a34ee0a7a47955d371
|
|
| BLAKE2b-256 |
9b643fa7d61ed2d6601e9277bc68531a4e121637c1268b6e557914cd55847f08
|