Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky parent for openai instrumentation #931

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backend/chainlit/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
)
from chainlit.user import PersistedUser, User
from literalai import Attachment
from literalai import PaginatedResponse as LiteralPaginatedResponse
from literalai import Score as LiteralScore
from literalai import Step as LiteralStep
from literalai.filter import threads_filters as LiteralThreadsFilters
Expand Down Expand Up @@ -431,7 +430,7 @@ async def list_threads(
}
)

literal_response: LiteralPaginatedResponse = await self.client.api.list_threads(
literal_response = await self.client.api.list_threads(
first=pagination.first,
after=pagination.cursor,
filters=literal_filters,
Expand Down
14 changes: 5 additions & 9 deletions backend/chainlit/openai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union
import asyncio
from typing import Union

from chainlit.context import get_context
from chainlit.step import Step
from chainlit.utils import check_module_version
Expand All @@ -15,7 +16,7 @@ def instrument_openai():

from literalai.instrumentation.openai import instrument_openai

async def on_new_generation(
def on_new_generation(
generation: Union["ChatGeneration", "CompletionGeneration"], timing
):
context = get_context()
Expand Down Expand Up @@ -51,11 +52,6 @@ async def on_new_generation(
step.input = generation.prompt
step.output = generation.completion

await step.send()
asyncio.create_task(step.send())

def on_new_generation_sync(
generation: Union["ChatGeneration", "CompletionGeneration"], timing
):
asyncio.create_task(on_new_generation(generation, timing))

instrument_openai(None, on_new_generation_sync)
instrument_openai(None, on_new_generation)
Loading