Skip to content

Commit

Permalink
use uuid to generate completion id and session id (#138)
Browse files Browse the repository at this point in the history
* use uuid to generate completion id and session id

* remove extra code

* bump version to 0.7.5
  • Loading branch information
wenzhe-log10 authored Apr 10, 2024
1 parent e16516a commit b43c76f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
10 changes: 2 additions & 8 deletions log10/_httpx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import time
import traceback
import uuid
from datetime import datetime, timezone

import httpx
Expand Down Expand Up @@ -112,14 +113,7 @@ async def get_completion_id(request: Request):
logger.warning("Currently logging is only available for v1/chat/completions.")
return

completion_url = "/api/completions"
res = await _try_post_request_async(url=f"{base_url}{completion_url}")
try:
completion_id = res.json().get("completionID")
except Exception as e:
logger.error(f"Failed to get completion ID. Error: {e}. Skipping completion recording.")
else:
request.headers["x-log10-completion-id"] = completion_id
request.headers["x-log10-completion-id"] = str(uuid.uuid4())


async def log_request(request: Request):
Expand Down
34 changes: 4 additions & 30 deletions log10/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import threading
import time
import traceback
import uuid
from contextlib import contextmanager
from copy import deepcopy
from importlib.metadata import version
Expand Down Expand Up @@ -38,7 +39,6 @@
from log10.bigquery import initialize_bigquery

bigquery_client, bigquery_table = initialize_bigquery()
import uuid
from datetime import datetime, timezone
elif target_service is None:
target_service = "log10" # default to log10
Expand Down Expand Up @@ -102,35 +102,9 @@ def post_request(url: str, json_payload: dict = {}) -> requests.Response:


def get_session_id():
if target_service == "bigquery":
return str(uuid.uuid4())

session_id = None
try:
res = post_session_request()
session_id = res.json()["sessionID"]
except requests.HTTPError as http_err:
if "401" in str(http_err):
logging.warn(
"Failed anthorization. Please verify that LOG10_TOKEN and LOG10_ORG_ID are set correctly and try again."
+ "\nSee https://github.com/log10-io/log10#%EF%B8%8F-setup for details"
)
else:
logging.warn(f"Failed to create LOG10 session. Error: {http_err}")
except requests.ConnectionError:
logging.warn(
"Invalid LOG10_URL. Please verify that LOG10_URL is set correctly and try again."
+ "\nSee https://github.com/log10-io/log10#%EF%B8%8F-setup for details"
)
except Exception as e:
logging.warn(
"Failed to create LOG10 session: "
+ str(e)
+ "\nLikely cause: LOG10 env vars missing or not picked up correctly!"
+ "\nSee https://github.com/log10-io/log10#%EF%B8%8F-setup for details"
)

return session_id
id = str(uuid.uuid4())
logger.debug(f"Session ID: {id}")
return id


# Global variable to store the current sessionID.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "log10-io"

version = "0.7.4"
version = "0.7.5"
authors = ["log10 team"]
license = "MIT"
description = "Unified LLM data management"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="Log10",
version="0.7.4",
version="0.7.5",
description="Log10 LLM data management",
author="Log10 team",
author_email="team@log10.io",
Expand Down

0 comments on commit b43c76f

Please sign in to comment.