Skip to content

Commit 4bf4aaf

Browse files
committed
ran tox -e ruff, even though tox -e flake8 was fine
Signed-off-by: Filinto Duran <[email protected]>
1 parent 5bec64e commit 4bf4aaf

File tree

7 files changed

+111
-101
lines changed

7 files changed

+111
-101
lines changed

dapr/aio/clients/grpc/client.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,11 +1770,15 @@ async def converse_alpha1(
17701770
response = await self._stub.ConverseAlpha1(request)
17711771

17721772
outputs = [
1773-
conversation.ConversationResultAlpha1(result=output.result, parameters=output.parameters)
1773+
conversation.ConversationResultAlpha1(
1774+
result=output.result, parameters=output.parameters
1775+
)
17741776
for output in response.outputs
17751777
]
17761778

1777-
return conversation.ConversationResponseAlpha1(context_id=response.contextID, outputs=outputs)
1779+
return conversation.ConversationResponseAlpha1(
1780+
context_id=response.contextID, outputs=outputs
1781+
)
17781782

17791783
except grpc.aio.AioRpcError as err:
17801784
raise DaprGrpcError(err) from err
@@ -1862,11 +1866,14 @@ async def converse_alpha2(
18621866

18631867
try:
18641868
response, call = await self.retry_policy.run_rpc_async(
1865-
self._stub.ConverseAlpha2, request)
1869+
self._stub.ConverseAlpha2, request
1870+
)
18661871

18671872
outputs = conversation._get_outputs_from_grpc_response(response)
18681873

1869-
return conversation.ConversationResponseAlpha2(context_id=response.context_id, outputs=outputs)
1874+
return conversation.ConversationResponseAlpha2(
1875+
context_id=response.context_id, outputs=outputs
1876+
)
18701877

18711878
except grpc.aio.AioRpcError as err:
18721879
raise DaprGrpcError(err) from err

dapr/clients/grpc/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,11 +1774,15 @@ def converse_alpha1(
17741774
response, call = self.retry_policy.run_rpc(self._stub.ConverseAlpha1.with_call, request)
17751775

17761776
outputs = [
1777-
conversation.ConversationResultAlpha1(result=output.result, parameters=output.parameters)
1777+
conversation.ConversationResultAlpha1(
1778+
result=output.result, parameters=output.parameters
1779+
)
17781780
for output in response.outputs
17791781
]
17801782

1781-
return conversation.ConversationResponseAlpha1(context_id=response.contextID, outputs=outputs)
1783+
return conversation.ConversationResponseAlpha1(
1784+
context_id=response.contextID, outputs=outputs
1785+
)
17821786
except RpcError as err:
17831787
raise DaprGrpcError(err) from err
17841788

dapr/clients/grpc/conversation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ def _indent_lines(title: str, text: str, indent: int) -> str:
7171

7272
class HasNameAndContent:
7373
"""Mixin Protocol for name and content typing."""
74+
7475
name: Optional[str] = None
7576
content: List[ConversationMessageContent] = field(default_factory=list)
7677

7778

7879
class UserTracePrintMixin(HasNameAndContent):
7980
"""Mixin for trace_print for text based message content from user to LLM."""
81+
8082
def trace_print(self, indent: int = 0) -> None:
8183
base = ' ' * indent
8284
if self.name:
@@ -577,7 +579,9 @@ def create_tool_message(tool_id: str, name: str, content: Any) -> ConversationMe
577579
)
578580

579581

580-
def _get_outputs_from_grpc_response(response: api_v1.ConversationResponseAlpha2) -> List[ConversationResultAlpha2]:
582+
def _get_outputs_from_grpc_response(
583+
response: api_v1.ConversationResponseAlpha2,
584+
) -> List[ConversationResultAlpha2]:
581585
"""Helper to get outputs from a Converse gRPC response from dapr sidecar."""
582586
outputs: List[ConversationResultAlpha2] = []
583587
for output in response.outputs:
@@ -591,11 +595,7 @@ def _get_outputs_from_grpc_response(response: api_v1.ConversationResponseAlpha2)
591595
)
592596
if not tool_call.id:
593597
tool_call.id = _generate_unique_tool_call_id()
594-
tool_calls.append(
595-
ConversationToolCalls(
596-
id=tool_call.id, function=function_call
597-
)
598-
)
598+
tool_calls.append(ConversationToolCalls(id=tool_call.id, function=function_call))
599599

600600
result_message = ConversationResultAlpha2Message(
601601
content=choice.message.content, tool_calls=tool_calls

examples/conversation/conversation_alpha2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
with DaprClient() as d:
2020
inputs = [
21+
ConversationInputAlpha2(messages=[create_user_message("What's Dapr?")], scrub_pii=True),
2122
ConversationInputAlpha2(
22-
messages=[create_user_message("What's Dapr?")], scrub_pii=True),
23-
ConversationInputAlpha2(
24-
messages=[create_user_message('Give a brief overview.')], scrub_pii=True),
23+
messages=[create_user_message('Give a brief overview.')], scrub_pii=True
24+
),
2525
]
2626

2727
metadata = {

tests/clients/test_conversation.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -929,44 +929,38 @@ async def echo(value: str, delay: float = 0.0) -> str:
929929

930930
class TestIndentLines(unittest.TestCase):
931931
def test_single_line_with_indent(self):
932-
result = conversation._indent_lines("Note", "Hello", 2)
933-
self.assertEqual(result, " Note: Hello")
932+
result = conversation._indent_lines('Note', 'Hello', 2)
933+
self.assertEqual(result, ' Note: Hello')
934934

935935
def test_multiline_example(self):
936-
text = "This is a long\nmultiline\ntext block"
937-
result = conversation._indent_lines("Description", text, 4)
936+
text = 'This is a long\nmultiline\ntext block'
937+
result = conversation._indent_lines('Description', text, 4)
938938
expected = (
939-
" Description: This is a long\n"
940-
" multiline\n"
941-
" text block"
939+
' Description: This is a long\n'
940+
' multiline\n'
941+
' text block'
942942
)
943943
self.assertEqual(result, expected)
944944

945945
def test_zero_indent(self):
946-
result = conversation._indent_lines("Title", "Line one\nLine two", 0)
947-
expected = (
948-
"Title: Line one\n"
949-
" Line two"
950-
)
946+
result = conversation._indent_lines('Title', 'Line one\nLine two', 0)
947+
expected = 'Title: Line one\n' ' Line two'
951948
self.assertEqual(result, expected)
952949

953950
def test_empty_string(self):
954-
result = conversation._indent_lines("Empty", "", 3)
951+
result = conversation._indent_lines('Empty', '', 3)
955952
# Should end with a space after colon
956-
self.assertEqual(result, " Empty: ")
953+
self.assertEqual(result, ' Empty: ')
957954

958955
def test_none_text(self):
959-
result = conversation._indent_lines("NoneCase", None, 1)
960-
self.assertEqual(result, " NoneCase: ")
956+
result = conversation._indent_lines('NoneCase', None, 1)
957+
self.assertEqual(result, ' NoneCase: ')
961958

962959
def test_title_length_affects_indent(self):
963960
# Title length is 1, indent_after_first_line should be indent + len(title) + 2
964961
# indent=2, len(title)=1 => 2 + 1 + 2 = 5 spaces on continuation lines
965-
result = conversation._indent_lines("T", "a\nb", 2)
966-
expected = (
967-
" T: a\n"
968-
" b"
969-
)
962+
result = conversation._indent_lines('T', 'a\nb', 2)
963+
expected = ' T: a\n' ' b'
970964
self.assertEqual(result, expected)
971965

972966

tests/clients/test_dapr_grpc_client_async.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,9 @@ async def test_converse_alpha2_basic_user_message(self):
11781178
)
11791179
)
11801180

1181-
input_alpha2 = conversation.ConversationInputAlpha2(messages=[user_message], scrub_pii=False)
1181+
input_alpha2 = conversation.ConversationInputAlpha2(
1182+
messages=[user_message], scrub_pii=False
1183+
)
11821184

11831185
response = await dapr.converse_alpha2(name='test-llm', inputs=[input_alpha2])
11841186

@@ -1232,7 +1234,9 @@ async def test_converse_alpha2_with_tools_weather_request(self):
12321234
self.assertEqual(len(choice.message.tool_calls), 1)
12331235
tool_call = choice.message.tool_calls[0]
12341236
self.assertEqual(tool_call.function.name, 'get_weather')
1235-
self.assertEqual(tool_call.function.arguments, '{"location": "San Francisco", "unit": "celsius"}')
1237+
self.assertEqual(
1238+
tool_call.function.arguments, '{"location": "San Francisco", "unit": "celsius"}'
1239+
)
12361240
self.assertTrue(tool_call.id.startswith('call_'))
12371241
await dapr.close()
12381242

@@ -1242,7 +1246,9 @@ async def test_converse_alpha2_system_message(self):
12421246

12431247
system_message = conversation.ConversationMessage(
12441248
of_system=conversation.ConversationMessageOfSystem(
1245-
content=[conversation.ConversationMessageContent(text='You are a helpful assistant.')]
1249+
content=[
1250+
conversation.ConversationMessageContent(text='You are a helpful assistant.')
1251+
]
12461252
)
12471253
)
12481254

@@ -1325,9 +1331,7 @@ async def test_converse_alpha2_assistant_message(self):
13251331

13261332
self.assertIsNotNone(response)
13271333
choice = response.outputs[0].choices[0]
1328-
self.assertEqual(
1329-
choice.message.content, 'Assistant continued: I understand your request.'
1330-
)
1334+
self.assertEqual(choice.message.content, 'Assistant continued: I understand your request.')
13311335
await dapr.close()
13321336

13331337
async def test_converse_alpha2_multiple_messages(self):
@@ -1357,9 +1361,7 @@ async def test_converse_alpha2_multiple_messages(self):
13571361
response.outputs[0].choices[0].message.content,
13581362
'System acknowledged: You are helpful.',
13591363
)
1360-
self.assertEqual(
1361-
response.outputs[0].choices[1].message.content, 'Response to user: Hello!'
1362-
)
1364+
self.assertEqual(response.outputs[0].choices[1].message.content, 'Response to user: Hello!')
13631365
await dapr.close()
13641366

13651367
async def test_converse_alpha2_with_context_and_options(self):
@@ -1392,9 +1394,7 @@ async def test_converse_alpha2_with_context_and_options(self):
13921394
self.assertIsNotNone(response)
13931395
self.assertEqual(response.context_id, 'chat-session-123')
13941396
choice = response.outputs[0].choices[0]
1395-
self.assertEqual(
1396-
choice.message.content, 'Response to user: Continue our conversation'
1397-
)
1397+
self.assertEqual(choice.message.content, 'Response to user: Continue our conversation')
13981398
await dapr.close()
13991399

14001400
async def test_converse_alpha2_error_handling(self):

0 commit comments

Comments
 (0)