Skip to content

Commit e6aa6f6

Browse files
committed
lint
Signed-off-by: Filinto Duran <[email protected]>
1 parent f4ee187 commit e6aa6f6

File tree

5 files changed

+166
-133
lines changed

5 files changed

+166
-133
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ coverage.xml
5050
# Editor config
5151
.idea
5252
.vscode
53+
.cursor
5354

5455
# Translations
5556
*.mo

examples/conversation/conversation.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@
3131

3232
for output in response.outputs:
3333
print(f'Result: {output.result}')
34-
34+
3535
# Check for usage information
3636
if response.usage:
37-
print(f'Usage: {response.usage.prompt_tokens} prompt + {response.usage.completion_tokens} completion = {response.usage.total_tokens} total tokens')
37+
prompt_tokens = response.usage.prompt_tokens
38+
completion_tokens = response.usage.completion_tokens
39+
total_tokens = response.usage.total_tokens
40+
usage_parts = [
41+
f'Usage: {prompt_tokens} prompt',
42+
f'{completion_tokens} completion',
43+
f'{total_tokens} total tokens',
44+
]
45+
print(' + '.join(usage_parts[:2]) + ' = ' + usage_parts[2])
3846
else:
39-
print('No usage information available (echo component doesn\'t provide token counts)')
47+
print("No usage information available (echo component doesn't provide token counts)")

examples/conversation/streaming_async_comprehensive.py

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,88 @@
1313
"""
1414

1515
import asyncio
16+
1617
from dapr.aio.clients import DaprClient
1718
from dapr.clients.grpc._request import ConversationInput
1819

20+
21+
async def basic_streaming_test(d):
22+
"""Test basic async streaming conversation."""
23+
print('\n📡 Testing async streaming conversation...')
24+
inputs = [ConversationInput(content='Hello from async Python SDK streaming test!', role='user')]
25+
26+
chunks_received = []
27+
final_usage = None
28+
async for chunk in d.converse_stream_alpha1(
29+
name='echo', inputs=inputs, context_id='async-test-session-456'
30+
):
31+
if chunk.result and chunk.result.result:
32+
print(f'📦 Async chunk: "{chunk.result.result}"')
33+
chunks_received.append(chunk.result.result)
34+
if chunk.context_id:
35+
print(f'🆔 Async context ID: {chunk.context_id}')
36+
if chunk.usage:
37+
prompt_tokens = chunk.usage.prompt_tokens
38+
completion_tokens = chunk.usage.completion_tokens
39+
total_tokens = chunk.usage.total_tokens
40+
usage_parts = [
41+
f'📊 Async usage: {prompt_tokens} prompt',
42+
f'{completion_tokens} completion',
43+
f'{total_tokens} total tokens',
44+
]
45+
print(' + '.join(usage_parts[:2]) + ' = ' + usage_parts[2])
46+
final_usage = chunk.usage
47+
48+
print(f'\n✅ Async success! Received {len(chunks_received)} chunks')
49+
print(f'📝 Full async response: {"".join(chunks_received)}')
50+
if final_usage:
51+
print(f'💰 Total async usage: {final_usage.total_tokens} tokens')
52+
else:
53+
no_usage_msg = 'ℹ️ No usage information available'
54+
echo_note = " (echo component doesn't provide token counts)"
55+
print(no_usage_msg + echo_note)
56+
57+
58+
async def concurrent_conversations_test(d):
59+
"""Test multiple concurrent conversations."""
60+
print('\n🔄 Testing concurrent conversations...')
61+
62+
async def run_conversation(message, session_id):
63+
inputs = [ConversationInput(content=message, role='user')]
64+
chunks = []
65+
async for chunk in d.converse_stream_alpha1(
66+
name='echo', inputs=inputs, context_id=session_id
67+
):
68+
if chunk.result and chunk.result.result:
69+
chunks.append(chunk.result.result)
70+
return f"Session {session_id}: {''.join(chunks)}"
71+
72+
# Run 3 conversations concurrently
73+
tasks = [
74+
run_conversation('First conversation', 'session-1'),
75+
run_conversation('Second conversation', 'session-2'),
76+
run_conversation('Third conversation', 'session-3'),
77+
]
78+
79+
results = await asyncio.gather(*tasks)
80+
for result in results:
81+
print(f'🎯 {result}')
82+
83+
1984
async def main():
2085
print('🧪 Testing asynchronous streaming conversation with echo component...')
21-
86+
2287
try:
2388
async with DaprClient() as d:
2489
print('✓ Connected to Dapr sidecar (async)')
25-
26-
# Test basic async streaming conversation
27-
print('\n📡 Testing async streaming conversation...')
28-
inputs = [
29-
ConversationInput(content="Hello from async Python SDK streaming test!", role='user')
30-
]
31-
32-
chunks_received = []
33-
final_usage = None
34-
async for chunk in d.converse_stream_alpha1(
35-
name='echo',
36-
inputs=inputs,
37-
context_id='async-test-session-456'
38-
):
39-
if chunk.result and chunk.result.result:
40-
print(f'📦 Async chunk: "{chunk.result.result}"')
41-
chunks_received.append(chunk.result.result)
42-
if chunk.context_id:
43-
print(f'🆔 Async context ID: {chunk.context_id}')
44-
if chunk.usage:
45-
print(f'📊 Async usage: {chunk.usage.prompt_tokens} prompt + {chunk.usage.completion_tokens} completion = {chunk.usage.total_tokens} total tokens')
46-
final_usage = chunk.usage
47-
48-
print(f'\n✅ Async success! Received {len(chunks_received)} chunks')
49-
print(f'📝 Full async response: {"".join(chunks_received)}')
50-
if final_usage:
51-
print(f'💰 Total async usage: {final_usage.total_tokens} tokens')
52-
else:
53-
print('ℹ️ No usage information available (echo component doesn\'t provide token counts)')
54-
55-
# Test multiple concurrent conversations
56-
print('\n🔄 Testing concurrent conversations...')
57-
58-
async def run_conversation(message, session_id):
59-
inputs = [ConversationInput(content=message, role='user')]
60-
chunks = []
61-
async for chunk in d.converse_stream_alpha1(
62-
name='echo',
63-
inputs=inputs,
64-
context_id=session_id
65-
):
66-
if chunk.result and chunk.result.result:
67-
chunks.append(chunk.result.result)
68-
return f"Session {session_id}: {''.join(chunks)}"
69-
70-
# Run 3 conversations concurrently
71-
tasks = [
72-
run_conversation("First conversation", "session-1"),
73-
run_conversation("Second conversation", "session-2"),
74-
run_conversation("Third conversation", "session-3")
75-
]
76-
77-
results = await asyncio.gather(*tasks)
78-
for result in results:
79-
print(f'🎯 {result}')
90+
await basic_streaming_test(d)
91+
await concurrent_conversations_test(d)
8092

8193
except Exception as e:
8294
print(f'❌ Async error: {e}')
8395
print('\n💡 Make sure to start the Dapr sidecar with:')
8496
print(' python tools/run_dapr_dev.py')
8597

98+
8699
if __name__ == '__main__':
87-
asyncio.run(main())
100+
asyncio.run(main())

examples/conversation/streaming_comprehensive.py

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,91 +15,97 @@
1515
- Use tools/run_dapr_dev.py to start a development sidecar with echo component
1616
"""
1717

18-
import time
1918
from dapr.clients import DaprClient
2019
from dapr.clients.grpc._request import ConversationInput
2120

21+
22+
def basic_streaming_test(d):
23+
"""Test basic streaming conversation."""
24+
print('\n📡 Testing basic streaming conversation...')
25+
inputs = [ConversationInput(content='Hello from Python SDK streaming test!', role='user')]
26+
27+
chunks_received = []
28+
final_usage = None
29+
for chunk in d.converse_stream_alpha1(
30+
name='echo', inputs=inputs, context_id='sync-test-session-123'
31+
):
32+
if chunk.result and chunk.result.result:
33+
print(f'📦 Chunk: "{chunk.result.result}"')
34+
chunks_received.append(chunk.result.result)
35+
if chunk.context_id:
36+
print(f'🆔 Context ID: {chunk.context_id}')
37+
if chunk.usage:
38+
prompt_tokens = chunk.usage.prompt_tokens
39+
completion_tokens = chunk.usage.completion_tokens
40+
total_tokens = chunk.usage.total_tokens
41+
usage_parts = [
42+
f'📊 Usage: {prompt_tokens} prompt',
43+
f'{completion_tokens} completion',
44+
f'{total_tokens} total tokens',
45+
]
46+
print(' + '.join(usage_parts[:2]) + ' = ' + usage_parts[2])
47+
final_usage = chunk.usage
48+
49+
print(f'\n✅ Success! Received {len(chunks_received)} chunks')
50+
print(f'📝 Full response: {"".join(chunks_received)}')
51+
if final_usage:
52+
print(f'💰 Total usage: {final_usage.total_tokens} tokens')
53+
else:
54+
no_usage_msg = 'ℹ️ No usage information available'
55+
echo_note = " (echo component doesn't provide token counts)"
56+
print(no_usage_msg + echo_note)
57+
58+
59+
def pii_scrubbing_test(d):
60+
"""Test PII scrubbing functionality."""
61+
print('\n🔒 Testing PII scrubbing...')
62+
pii_inputs = [
63+
ConversationInput(content='My phone number is +1234567890', role='user', scrub_pii=True)
64+
]
65+
66+
scrubbed_chunks = []
67+
for chunk in d.converse_stream_alpha1(name='echo', inputs=pii_inputs, scrub_pii=True):
68+
if chunk.result and chunk.result.result:
69+
print(f'📦 Scrubbed chunk: "{chunk.result.result}"')
70+
scrubbed_chunks.append(chunk.result.result)
71+
72+
scrubbed_response = ''.join(scrubbed_chunks)
73+
print(f'📝 Scrubbed response: {scrubbed_response}')
74+
75+
if '<PHONE_NUMBER>' in scrubbed_response:
76+
print('✅ PII scrubbing working correctly!')
77+
else:
78+
print('⚠️ PII scrubbing may not be working as expected')
79+
80+
81+
def temperature_test(d):
82+
"""Test temperature parameter."""
83+
print('\n🌡️ Testing with temperature parameter...')
84+
temp_inputs = [ConversationInput(content='Test with temperature setting', role='user')]
85+
86+
temp_chunks = []
87+
for chunk in d.converse_stream_alpha1(name='echo', inputs=temp_inputs, temperature=0.7):
88+
if chunk.result and chunk.result.result:
89+
temp_chunks.append(chunk.result.result)
90+
91+
print(f'📝 Temperature test response: {"".join(temp_chunks)}')
92+
93+
2294
def main():
2395
print('🚀 Demonstrating Dapr streaming conversation API features...')
24-
96+
2597
try:
2698
with DaprClient() as d:
2799
print('✓ Connected to Dapr sidecar')
28-
29-
# Test basic streaming conversation
30-
print('\n📡 Testing basic streaming conversation...')
31-
inputs = [
32-
ConversationInput(content="Hello from Python SDK streaming test!", role='user')
33-
]
34-
35-
chunks_received = []
36-
final_usage = None
37-
for chunk in d.converse_stream_alpha1(
38-
name='echo',
39-
inputs=inputs,
40-
context_id='sync-test-session-123'
41-
):
42-
if chunk.result and chunk.result.result:
43-
print(f'📦 Chunk: "{chunk.result.result}"')
44-
chunks_received.append(chunk.result.result)
45-
if chunk.context_id:
46-
print(f'🆔 Context ID: {chunk.context_id}')
47-
if chunk.usage:
48-
print(f'📊 Usage: {chunk.usage.prompt_tokens} prompt + {chunk.usage.completion_tokens} completion = {chunk.usage.total_tokens} total tokens')
49-
final_usage = chunk.usage
50-
51-
print(f'\n✅ Success! Received {len(chunks_received)} chunks')
52-
print(f'📝 Full response: {"".join(chunks_received)}')
53-
if final_usage:
54-
print(f'💰 Total usage: {final_usage.total_tokens} tokens')
55-
else:
56-
print('ℹ️ No usage information available (echo component doesn\'t provide token counts)')
57-
58-
# Test with PII scrubbing
59-
print('\n🔒 Testing PII scrubbing...')
60-
pii_inputs = [
61-
ConversationInput(content="My phone number is +1234567890", role='user', scrub_pii=True)
62-
]
63-
64-
scrubbed_chunks = []
65-
for chunk in d.converse_stream_alpha1(
66-
name='echo',
67-
inputs=pii_inputs,
68-
scrub_pii=True
69-
):
70-
if chunk.result and chunk.result.result:
71-
print(f'📦 Scrubbed chunk: "{chunk.result.result}"')
72-
scrubbed_chunks.append(chunk.result.result)
73-
74-
scrubbed_response = "".join(scrubbed_chunks)
75-
print(f'📝 Scrubbed response: {scrubbed_response}')
76-
77-
if "<PHONE_NUMBER>" in scrubbed_response:
78-
print('✅ PII scrubbing working correctly!')
79-
else:
80-
print('⚠️ PII scrubbing may not be working as expected')
81-
82-
# Test with temperature parameter
83-
print('\n🌡️ Testing with temperature parameter...')
84-
temp_inputs = [
85-
ConversationInput(content="Test with temperature setting", role='user')
86-
]
87-
88-
temp_chunks = []
89-
for chunk in d.converse_stream_alpha1(
90-
name='echo',
91-
inputs=temp_inputs,
92-
temperature=0.7
93-
):
94-
if chunk.result and chunk.result.result:
95-
temp_chunks.append(chunk.result.result)
96-
97-
print(f'📝 Temperature test response: {"".join(temp_chunks)}')
100+
basic_streaming_test(d)
101+
pii_scrubbing_test(d)
102+
temperature_test(d)
98103

99104
except Exception as e:
100105
print(f'❌ Error: {e}')
101106
print('\n💡 Make sure to start the Dapr sidecar with:')
102107
print(' python tools/run_dapr_dev.py')
103108

109+
104110
if __name__ == '__main__':
105-
main()
111+
main()

examples/demo_actor/tol.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global:
2+
tolerations:
3+
- effect: NoSchedule
4+
key: kubernetes.io/arch
5+
value: arm64

0 commit comments

Comments
 (0)