Skip to content

fix: runs in callbacks #85

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

Merged
merged 2 commits into from
Jul 2, 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
6 changes: 2 additions & 4 deletions literalai/callback/langchain_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def _start_trace(self, run: Run) -> None:
if run.run_type == "agent":
step_type = "run"
elif run.run_type == "chain":
pass
if not self.steps:
step_type = "run"
elif run.run_type == "llm":
step_type = "llm"
elif run.run_type == "retriever":
Expand All @@ -347,9 +348,6 @@ def _start_trace(self, run: Run) -> None:
elif run.run_type == "embedding":
step_type = "embedding"

if not self.steps and step_type != "llm":
step_type = "run"

step = self.client.start_step(
id=str(run.id), name=run.name, type=step_type, parent_id=parent_id
)
Expand Down
7 changes: 0 additions & 7 deletions literalai/callback/llama_index_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(
event_ends_to_ignore=event_ends_to_ignore,
)
self.client = client
self.is_pristine = True

self.steps = {}

Expand Down Expand Up @@ -91,12 +90,6 @@ def on_event_start(
else:
return event_id

step_type = (
"run" if self.is_pristine and step_type != "llm" else "undefined"
)

self.is_pristine = False

step = self.client.start_step(
name=event_type.value,
type=step_type,
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/test_mistralai.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from asyncio import sleep
from literalai.client import LiteralClient
import pytest
import os
from pytest_httpx import HTTPXMock
import urllib.parse
from mistralai.client import MistralClient
from asyncio import sleep

import pytest
from mistralai.async_client import MistralAsyncClient
from mistralai.client import MistralClient
from pytest_httpx import HTTPXMock

from literalai.client import LiteralClient
from literalai.my_types import ChatGeneration, CompletionGeneration


Expand Down Expand Up @@ -92,7 +93,7 @@ def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == ChatGeneration
assert type(step.generation) is ChatGeneration
assert step.generation.settings is not None
assert step.generation.model == "open-mistral-7b"

Expand Down Expand Up @@ -148,7 +149,7 @@ def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == CompletionGeneration
assert type(step.generation) is CompletionGeneration
assert step.generation.settings is not None
assert step.generation.model == "codestral-2405"
assert step.generation.completion == "2\n\n"
Expand Down Expand Up @@ -187,7 +188,6 @@ async def test_async_chat(self, client: "LiteralClient", httpx_mock: "HTTPXMock"

@client.thread
async def main():

# https://docs.mistral.ai/api/#operation/createChatCompletion
await mai_client.chat(
model="open-mistral-7b",
Expand All @@ -213,7 +213,7 @@ async def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == ChatGeneration
assert type(step.generation) is ChatGeneration
assert step.generation.settings is not None
assert step.generation.model == "open-mistral-7b"

Expand Down Expand Up @@ -271,7 +271,7 @@ async def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == CompletionGeneration
assert type(step.generation) is CompletionGeneration
assert step.generation.settings is not None
assert step.generation.model == "codestral-2405"
assert step.generation.completion == "2\n\n"
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == ChatGeneration
assert type(step.generation) is ChatGeneration
assert step.generation.settings is not None
assert step.generation.model == "gpt-3.5-turbo-0613"

Expand Down Expand Up @@ -155,7 +155,7 @@ def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == CompletionGeneration
assert type(step.generation) is CompletionGeneration
assert step.generation.settings is not None
assert step.generation.model == "gpt-3.5-turbo"
assert step.generation.completion == "\n\nThis is indeed a test"
Expand Down Expand Up @@ -223,7 +223,7 @@ async def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == ChatGeneration
assert type(step.generation) is ChatGeneration
assert step.generation.settings is not None
assert step.generation.model == "gpt-3.5-turbo-0613"

Expand Down Expand Up @@ -281,7 +281,7 @@ async def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == CompletionGeneration
assert type(step.generation) is CompletionGeneration
assert step.generation.settings is not None
assert step.generation.model == "gpt-3.5-turbo"
assert step.generation.completion == "\n\nThis is indeed a test"
Expand Down Expand Up @@ -346,7 +346,7 @@ def main():

assert step.type == "llm"
assert step.generation is not None
assert type(step.generation) == CompletionGeneration
assert type(step.generation) is CompletionGeneration
assert step.generation.settings is not None
assert step.generation.model == "gpt-3.5-turbo"
assert step.generation.completion == "\n\nThis is indeed a test"
Expand Down
Loading