Compare commits

...

22 Commits

Author SHA1 Message Date
Chester Curme
ebcee67e1c x 2025-05-08 13:07:12 -04:00
Chester Curme
395008456e x 2025-05-08 13:05:28 -04:00
Chester Curme
d9715ad797 x 2025-05-08 13:03:19 -04:00
Chester Curme
3516c2c394 x 2025-05-08 13:01:28 -04:00
Chester Curme
e01c52d2d0 x 2025-05-08 12:59:31 -04:00
Chester Curme
2f39398736 x 2025-05-08 12:56:12 -04:00
Chester Curme
8868c6b1ff x 2025-05-08 11:06:22 -04:00
Chester Curme
18c1d8a50c x 2025-05-08 11:05:09 -04:00
Chester Curme
fc797fadf4 x 2025-05-08 11:03:31 -04:00
Chester Curme
c678528334 x 2025-05-08 11:00:10 -04:00
Chester Curme
a074bd08f7 x 2025-05-08 10:58:36 -04:00
Chester Curme
e7fef3bd8e Revert "xx"
This reverts commit 08574848cc.
2025-05-08 10:56:38 -04:00
Chester Curme
08574848cc xx 2025-05-08 10:55:08 -04:00
Chester Curme
c65571136f x 2025-05-08 10:52:16 -04:00
Chester Curme
6acd55b216 x 2025-05-08 10:50:14 -04:00
Chester Curme
c225f1a4cb x 2025-05-08 10:47:57 -04:00
Chester Curme
50ce3bf5d9 x 2025-05-08 10:45:55 -04:00
Chester Curme
f23b8008ce x 2025-05-08 10:42:52 -04:00
Chester Curme
31077f5df2 x 2025-05-08 10:41:10 -04:00
Chester Curme
1a43bfb55b x 2025-05-08 10:39:42 -04:00
Chester Curme
3c2e05e43f x 2025-05-08 10:38:05 -04:00
Chester Curme
ad68ddbf40 test stream twice 2025-05-08 10:35:31 -04:00
7 changed files with 60 additions and 814 deletions

View File

@@ -14,7 +14,7 @@ test tests:
uv run --group test pytest -vvv --disable-socket --allow-unix-socket $(TEST_FILE)
integration_test integration_tests:
uv run --group test --group test_integration pytest -vvv --timeout 30 $(TEST_FILE)
uv run --group test --group test_integration pytest -vvv --timeout 30 tests/integration_tests/test_chat_models.py
test_watch:
uv run --group test ptw --snapshot-update --now . -- -vv $(TEST_FILE)

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,46 @@
import cProfile
import asyncio
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import AIMessageChunk
MODEL_NAME = "claude-3-5-haiku-latest"
async def test_stream_usage() -> None:
"""Test usage metadata can be excluded."""
model = ChatAnthropic(model_name=MODEL_NAME, stream_usage=False)
async for token in model.astream("hi"):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None
# check we override with kwarg
model = ChatAnthropic(model_name=MODEL_NAME)
assert model.stream_usage
async for token in model.astream("hi", stream_usage=False):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None
# def run_async(func, *args, **kwargs):
# return asyncio.get_event_loop().run_until_complete(func(*args, **kwargs))
# if __name__ == "__main__":
# profiler = cProfile.Profile()
# profiler.enable()
# run_async(test_stream_usage) # your async function here
# profiler.disable()
# profiler.dump_stats('test_stream_usage_master.prof') # or 'test_stream_usage.out'
import yappi
def run_async(func, *args, **kwargs):
return asyncio.get_event_loop().run_until_complete(func(*args, **kwargs))
yappi.start()
run_async(test_stream_usage)
yappi.stop()
yappi.get_func_stats().save('profile.yappi', type='pstat') # pstat format

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long