Skip to content

Commit d008cff

Browse files
committed
Fix LangChain session id generation
1 parent bfe3347 commit d008cff

File tree

7 files changed

+951
-860
lines changed

7 files changed

+951
-860
lines changed

.github/workflows/daily-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ jobs:
3232
run: poetry update
3333

3434
- name: Run unit tests
35-
continue-on-error: true
3635
run: poetry run test

graphsignal/callbacks/langchain/v2.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def __init__(self, **kwargs: Any) -> None:
2727
self._span_map = {}
2828

2929
# create session_id, if not passed
30+
self._generated_session_id = False
3031
if 'session_id' not in self._passed_tags and 'session_id' not in self._context_tags:
3132
self._passed_tags['session_id'] = uuid_sha1(size=12)
33+
self._generated_session_id = True
3234

3335
def _start_trace(self, parent_run_id, run_id, operation):
3436
# propagate context tags just in case contextvars are not propagated
@@ -58,7 +60,7 @@ def _stop_trace(self, run_id):
5860
span.stop()
5961

6062
def on_llm_start(
61-
self,
63+
self,
6264
serialized: Dict[str, Any],
6365
prompts: List[str],
6466
*,
@@ -618,7 +620,8 @@ async def on_agent_finish(
618620
self,
619621
finish: AgentFinish,
620622
**kwargs: Any) -> None:
621-
pass
623+
if self._generated_session_id:
624+
graphsignal.set_context_tag('session_id', None)
622625

623626
async def on_text(
624627
self,

graphsignal/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.15.5'
1+
__version__ = '0.15.6'

poetry.lock

Lines changed: 929 additions & 852 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "graphsignal"
3-
version = "0.15.5"
3+
version = "0.15.6"
44
description = "Graphsignal Tracer for Python"
55
authors = ["Graphsignal, Inc. <devops@graphsignal.com>"]
66
license = "Apache-2.0"
@@ -37,8 +37,9 @@ langchain = "*"
3737
langchainhub = "*"
3838
numexpr = "*"
3939
llama_index = "*"
40-
llama-index-llms-langchain = "*"
4140
nltk = "*"
41+
langchain-community = "*"
42+
llama-index-llms-langchain = "*"
4243

4344
[tool.poetry.scripts]
4445
update-client = "tools.update_client:main"

test/callbacks/langchain/test_v2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ async def test_callback_tags(self, mocked_upload_span):
6868
@patch.object(Uploader, 'upload_span')
6969
@patch('graphsignal.callbacks.langchain.v2.uuid_sha1', return_value='s1')
7070
async def test_chain(self, mocked_uuid_sha1, mocked_upload_span):
71+
os.environ["LANGCHAIN_TRACING_V2"] = "false"
72+
7173
graphsignal.set_context_tag('ct1', 'v1')
7274

7375
llm = DummyLLM()
@@ -96,6 +98,8 @@ def find_span(op_name):
9698
@patch.object(Uploader, 'upload_span')
9799
@patch('graphsignal.callbacks.langchain.v2.uuid_sha1', return_value='s1')
98100
async def test_chain_async(self, mocked_uuid_sha1, mocked_upload_span):
101+
os.environ["LANGCHAIN_TRACING_V2"] = "false"
102+
99103
graphsignal.set_context_tag('ct1', 'v1')
100104

101105
llm = DummyLLM()

test/recorders/test_openai_recorder.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from openai.types.create_embedding_response import Usage
2929

3030
os.environ['OPENAI_API_KEY'] = 'sk-kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk'
31+
os.environ['LANGCHAIN_API_KEY'] = 'kkk'
3132

3233
class OpenAIRecorderTest(unittest.IsolatedAsyncioTestCase):
3334
async def asyncSetUp(self):
@@ -410,6 +411,7 @@ async def test_ret_gen():
410411
self.assertEqual(output_json, [{
411412
'choices': [{'delta': {'content': '',
412413
'function_call': None,
414+
'refusal': None,
413415
'role': 'assistant',
414416
'tool_calls': None},
415417
'finish_reason': 'stop',
@@ -419,9 +421,12 @@ async def test_ret_gen():
419421
'id': 'chatcmpl-8OQctcUZdbOT1KO8x2IKGUQE7G33b',
420422
'model': 'gpt-4-0613',
421423
'object': 'chat.completion.chunk',
422-
'system_fingerprint': None},
424+
'service_tier': None,
425+
'system_fingerprint': None,
426+
'usage': None},
423427
{'choices': [{'delta': {'content': 'We',
424428
'function_call': None,
429+
'refusal': None,
425430
'role': None,
426431
'tool_calls': None},
427432
'finish_reason': 'stop',
@@ -431,7 +436,9 @@ async def test_ret_gen():
431436
'id': 'chatcmpl-8OQctcUZdbOT1KO8x2IKGUQE7G33b',
432437
'model': 'gpt-4-0613',
433438
'object': 'chat.completion.chunk',
434-
'system_fingerprint': None}])
439+
'service_tier': None,
440+
'system_fingerprint': None,
441+
'usage': None}])
435442

436443
@patch.object(Uploader, 'upload_span')
437444
async def test_embedding_create(self, mocked_upload_span):

0 commit comments

Comments
 (0)