use http.client instead of urllib3 (#12660)

dep problems with requests

cloudflare debugging not worth it with urllib
This commit is contained in:
Erick Friis
2023-11-01 11:15:05 -07:00
committed by GitHub
parent eee5181b7a
commit 14340ee7cd
5 changed files with 38 additions and 43 deletions

View File

@@ -6,7 +6,7 @@ from typing_extensions import Annotated
from langchain_cli.namespaces import app as app_namespace
from langchain_cli.namespaces import template as template_namespace
__version__ = "0.0.10"
__version__ = "0.0.11"
app = typer.Typer(no_args_is_help=True, add_completion=False)
app.add_typer(

View File

@@ -1,8 +1,7 @@
import http.client
import json
from typing import Any, Dict, List, Optional, TypedDict
import urllib3
WRITE_KEY = "310apTK0HUFl4AOv"
@@ -11,43 +10,32 @@ class EventDict(TypedDict):
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"),
}
def create_events(events: List[EventDict]) -> Optional[Any]:
try:
urllib3.request(
"POST",
"https://app.firstpartyhq.com/events/v1/track",
body=json.dumps(data),
headers={"Content-Type": "application/json"},
)
except Exception:
pass
data = {
"events": [
{
"write_key": WRITE_KEY,
"name": event["event"],
"properties": event.get("properties"),
}
for event in events
]
}
conn = http.client.HTTPSConnection("app.firstpartyhq.com")
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"},
)
payload = json.dumps(data)
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
conn.request("POST", "/events/v1/track/bulk", payload, headers)
res = conn.getresponse()
return json.loads(res.read())
except Exception:
pass
return None