Skip to content

Commit

Permalink
fix multi session tags and add an example (#112)
Browse files Browse the repository at this point in the history
* fix multi session tags issue and add an example

* update example with a no tag in between

* bump version 0.6.6
  • Loading branch information
wenzhe-log10 authored Feb 26, 2024
1 parent 016c45d commit 3d3f957
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
33 changes: 33 additions & 0 deletions examples/logging/async_multi_session_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import asyncio

import openai
from magentic import AsyncStreamedStr, OpenaiChatModel, prompt

from log10.load import log10, log10_session


log10(openai)


@prompt("What is {a} * {b}?", model=OpenaiChatModel(model="gpt-4-turbo-preview"))
async def do_math_with_llm_async(a: int, b: int) -> AsyncStreamedStr:
...


async def main():
with log10_session(tags=["test_tag_a"]):
result = await do_math_with_llm_async(2, 2)
async for chunk in result:
print(chunk, end="", flush=True)

result = await do_math_with_llm_async(2.5, 2.5)
async for chunk in result:
print(chunk, end="", flush=True)

with log10_session(tags=["test_tag_b"]):
result = await do_math_with_llm_async(3, 3)
async for chunk in result:
print(chunk, end="", flush=True)


asyncio.run(main())
1 change: 1 addition & 0 deletions examples/logging/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
magentic
11 changes: 7 additions & 4 deletions log10/_httpx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from httpx import Request, Response

from log10.llm import Log10Config
from log10.load import global_tags, sessionID
from log10.load import get_log10_session_tags, sessionID


logger: logging.Logger = logging.getLogger("LOG10")
Expand Down Expand Up @@ -81,8 +81,9 @@ async def log_request(request: Request):
"orig_qualname": orig_qualname,
"request": request.content.decode("utf-8"),
"session_id": sessionID,
"tags": global_tags,
}
if get_log10_session_tags():
log_row["tags"] = get_log10_session_tags()
_try_post_request(url=f"{base_url}/api/completions/{completion_id}", payload=log_row)


Expand Down Expand Up @@ -160,8 +161,9 @@ async def aiter_bytes(self, *args, **kwargs):
"kind": "chat",
"request": self.request.content.decode("utf-8"),
"session_id": sessionID,
"tags": global_tags,
}
if get_log10_session_tags():
log_row["tags"] = get_log10_session_tags()
_try_post_request(url=f"{base_url}/api/completions/{completion_id}", payload=log_row)


Expand Down Expand Up @@ -200,8 +202,9 @@ async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
"kind": "chat",
"request": request.content.decode("utf-8"),
"session_id": sessionID,
"tags": global_tags,
}
if get_log10_session_tags():
log_row["tags"] = get_log10_session_tags()
_try_post_request(url=f"{base_url}/api/completions/{completion_id}", payload=log_row)
return response
elif response.headers.get("content-type") == "text/event-stream":
Expand Down
4 changes: 4 additions & 0 deletions log10/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def get_session_id():
global_tags = []


def get_log10_session_tags():
return global_tags


class log10_session:
def __init__(self, tags=None):
self.tags = tags
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.6.5"
version = "0.6.6"
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.6.5",
version="0.6.6",
description="Log10 LLM data management",
author="Log10 team",
author_email="team@log10.io",
Expand Down

0 comments on commit 3d3f957

Please sign in to comment.