mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
use http.client instead of urllib3 (#12660)
dep problems with requests cloudflare debugging not worth it with urllib
This commit is contained in:
parent
eee5181b7a
commit
14340ee7cd
@ -6,7 +6,7 @@ from typing_extensions import Annotated
|
|||||||
from langchain_cli.namespaces import app as app_namespace
|
from langchain_cli.namespaces import app as app_namespace
|
||||||
from langchain_cli.namespaces import template as template_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 = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||||
app.add_typer(
|
app.add_typer(
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
|
import http.client
|
||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Optional, TypedDict
|
from typing import Any, Dict, List, Optional, TypedDict
|
||||||
|
|
||||||
import urllib3
|
|
||||||
|
|
||||||
WRITE_KEY = "310apTK0HUFl4AOv"
|
WRITE_KEY = "310apTK0HUFl4AOv"
|
||||||
|
|
||||||
|
|
||||||
@ -11,43 +10,32 @@ class EventDict(TypedDict):
|
|||||||
properties: Optional[Dict[str, Any]]
|
properties: Optional[Dict[str, Any]]
|
||||||
|
|
||||||
|
|
||||||
def create_event(event: EventDict) -> None:
|
def create_events(events: List[EventDict]) -> Optional[Any]:
|
||||||
"""
|
|
||||||
Creates a new event with the given type and payload.
|
|
||||||
"""
|
|
||||||
data = {
|
|
||||||
"write_key": WRITE_KEY,
|
|
||||||
"event": event["event"],
|
|
||||||
"properties": event.get("properties"),
|
|
||||||
}
|
|
||||||
try:
|
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 = {
|
data = {
|
||||||
"events": [
|
"events": [
|
||||||
{
|
{
|
||||||
"write_key": WRITE_KEY,
|
"write_key": WRITE_KEY,
|
||||||
"event": event["event"],
|
"name": event["event"],
|
||||||
"properties": event.get("properties"),
|
"properties": event.get("properties"),
|
||||||
}
|
}
|
||||||
for event in events
|
for event in events
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
urllib3.request(
|
conn = http.client.HTTPSConnection("app.firstpartyhq.com")
|
||||||
"POST",
|
|
||||||
"https://app.firstpartyhq.com/events/v1/track/bulk",
|
payload = json.dumps(data)
|
||||||
body=json.dumps(data),
|
|
||||||
headers={"Content-Type": "application/json"},
|
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:
|
except Exception:
|
||||||
pass
|
return None
|
||||||
|
6
libs/cli/poetry.lock
generated
6
libs/cli/poetry.lock
generated
@ -692,13 +692,13 @@ text-helpers = ["chardet (>=5.1.0,<6.0.0)"]
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "langserve"
|
name = "langserve"
|
||||||
version = "0.0.19"
|
version = "0.0.20"
|
||||||
description = ""
|
description = ""
|
||||||
optional = true
|
optional = true
|
||||||
python-versions = ">=3.8.1,<4.0.0"
|
python-versions = ">=3.8.1,<4.0.0"
|
||||||
files = [
|
files = [
|
||||||
{file = "langserve-0.0.19-py3-none-any.whl", hash = "sha256:f644aed61dda42ad1c70770a41285e4069e0233435b7452b4af5b026188c00b0"},
|
{file = "langserve-0.0.20-py3-none-any.whl", hash = "sha256:7c0f0c9989a6423a72229c4b7d39d8c08d912a8a8b19e0bc0037ee24305bc13e"},
|
||||||
{file = "langserve-0.0.19.tar.gz", hash = "sha256:930f6a6a090deec2ef3d6375212d06c95dd547ffb7cafe969c286df94fe6823f"},
|
{file = "langserve-0.0.20.tar.gz", hash = "sha256:2b16a33e647f107388d2da644373368ff627bbb96358a401523b9ef6effed834"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "langchain-cli"
|
name = "langchain-cli"
|
||||||
version = "0.0.10"
|
version = "0.0.11"
|
||||||
description = "CLI for interacting with LangChain"
|
description = "CLI for interacting with LangChain"
|
||||||
authors = ["Erick Friis <erick@langchain.dev>"]
|
authors = ["Erick Friis <erick@langchain.dev>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
7
libs/cli/tests/test_events.py
Normal file
7
libs/cli/tests/test_events.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from langchain_cli.utils.events import EventDict, create_events
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_events() -> None:
|
||||||
|
assert create_events(
|
||||||
|
[EventDict(event="Test Event", properties={"test": "test"})]
|
||||||
|
) == {"status": "success"}
|
Loading…
Reference in New Issue
Block a user