langchain/libs/cli/langchain_cli/utils/events.py
Erick Friis 47070b8314
CLI (#12284)
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
2023-10-25 11:06:58 -07:00

53 lines
1.2 KiB
Python

import urllib3
import json
from typing import List, Dict, Any, Optional, TypedDict
WRITE_KEY = "310apTK0HUFl4AOv"
class EventDict(TypedDict):
event: str
properties: Optional[Dict[str, Any]]
def create_event(event: EventDict) -> None:
"""
Creates a new event with the given type and payload.
"""
data = {
"write_key": WRITE_KEY,
"event": event["event"],
"properties": event.get("properties"),
}
try:
urllib3.request(
"POST",
"https://app.firstpartyhq.com/events/v1/track",
body=json.dumps(data),
headers={"Content-Type": "application/json"},
)
except Exception:
pass
def create_events(events: List[EventDict]) -> None:
data = {
"events": [
{
"write_key": WRITE_KEY,
"event": event["event"],
"properties": event.get("properties"),
}
for event in events
]
}
try:
urllib3.request(
"POST",
"https://app.firstpartyhq.com/events/v1/track/bulk",
body=json.dumps(data),
headers={"Content-Type": "application/json"},
)
except Exception:
pass