Skip to content

Commit a22f6d9

Browse files
committed
RDBC-925 Run black linter
1 parent 470107f commit a22f6d9

11 files changed

+80
-97
lines changed

ravendb/documents/ai/ai_agent_parameters_builder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class IAiAgentParametersBuilder(ABC, Generic[TResponse]):
1717
def with_parameter(self, name: str, value: Any) -> IAiAgentParametersBuilder[TResponse]:
1818
"""
1919
Adds a parameter to the conversation.
20-
20+
2121
Args:
2222
name: The parameter name
2323
value: The parameter value
24-
24+
2525
Returns:
2626
The builder instance for method chaining
2727
"""
@@ -31,7 +31,7 @@ def with_parameter(self, name: str, value: Any) -> IAiAgentParametersBuilder[TRe
3131
def build(self) -> IAiConversationOperations[TResponse]:
3232
"""
3333
Builds and returns the conversation operations instance.
34-
34+
3535
Returns:
3636
The conversation operations interface
3737
"""
@@ -46,7 +46,7 @@ class AiAgentParametersBuilder(IAiAgentParametersBuilder[TResponse]):
4646
def __init__(self, conversation_factory):
4747
"""
4848
Initializes the parameters builder.
49-
49+
5050
Args:
5151
conversation_factory: A callable that creates the conversation with the built parameters
5252
"""
@@ -56,11 +56,11 @@ def __init__(self, conversation_factory):
5656
def with_parameter(self, name: str, value: Any) -> IAiAgentParametersBuilder[TResponse]:
5757
"""
5858
Adds a parameter to the conversation.
59-
59+
6060
Args:
6161
name: The parameter name
6262
value: The parameter value
63-
63+
6464
Returns:
6565
The builder instance for method chaining
6666
"""
@@ -70,7 +70,7 @@ def with_parameter(self, name: str, value: Any) -> IAiAgentParametersBuilder[TRe
7070
def build(self) -> IAiConversationOperations[TResponse]:
7171
"""
7272
Builds and returns the conversation operations instance.
73-
73+
7474
Returns:
7575
The conversation operations interface
7676
"""

ravendb/documents/ai/ai_conversation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def with_conversation_id(
4949
) -> AiConversation[TResponse]:
5050
"""
5151
Creates a conversation instance for continuing an existing conversation.
52-
52+
5353
Args:
5454
store: The document store
5555
conversation_id: The ID of the existing conversation
5656
change_vector: Optional change vector for optimistic concurrency
57-
57+
5858
Returns:
5959
A new conversation instance
6060
"""
@@ -92,9 +92,7 @@ def add_action_response(self, action_id: str, action_response: Union[str, TRespo
9292
# More robust JSON serialization
9393
try:
9494
response.content = json.dumps(
95-
action_response.__dict__ if hasattr(action_response, '__dict__')
96-
else action_response,
97-
default=str
95+
action_response.__dict__ if hasattr(action_response, "__dict__") else action_response, default=str
9896
)
9997
except (TypeError, ValueError) as e:
10098
response.content = str(action_response)
@@ -144,7 +142,7 @@ def run(self) -> AiConversationResult[TResponse]:
144142
self._change_vector = result.change_vector
145143

146144
# Preserve agent ID for future conversation turns
147-
if not self._agent_id and hasattr(operation, '_agent_id'):
145+
if not self._agent_id and hasattr(operation, "_agent_id"):
148146
self._agent_id = operation._agent_id
149147

150148
# Clear processed data for next turn

ravendb/documents/ai/ai_conversation_operations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def required_actions(self) -> List[AiAgentActionRequest]:
3232
def add_action_response(self, action_id: str, action_response: Union[str, TResponse]) -> None:
3333
"""
3434
Adds a response for a given action request.
35-
35+
3636
Args:
3737
action_id: The ID of the action to respond to
3838
action_response: The response content (string or typed response object)
@@ -45,7 +45,7 @@ def run(self) -> AiConversationResult[TResponse]:
4545
Executes one "turn" of the conversation:
4646
sends the current prompt, processes any required actions,
4747
and awaits the agent's reply.
48-
48+
4949
Returns:
5050
The result of the conversation turn
5151
"""
@@ -55,7 +55,7 @@ def run(self) -> AiConversationResult[TResponse]:
5555
def set_user_prompt(self, user_prompt: str) -> None:
5656
"""
5757
Sets the next user prompt to send to the AI agent.
58-
58+
5959
Args:
6060
user_prompt: The prompt text to send to the agent
6161
"""

ravendb/documents/ai/ai_conversation_result.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,4 @@ def get_action_request_by_id(self, action_id: str) -> Optional[AiAgentActionRequ
5555
Returns:
5656
The action request if found, None otherwise
5757
"""
58-
return next(
59-
(request for request in self.action_requests if request.tool_id == action_id),
60-
None
61-
)
58+
return next((request for request in self.action_requests if request.tool_id == action_id), None)

ravendb/documents/ai/ai_operations.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,89 +20,79 @@ def __init__(self, store: DocumentStore):
2020
self._store = store
2121

2222
def add_or_update_agent(
23-
self,
24-
configuration: AiAgentConfiguration,
25-
schema_type: Type = None
23+
self, configuration: AiAgentConfiguration, schema_type: Type = None
2624
) -> AiAgentConfigurationResult:
2725
"""
2826
Adds or updates an AI agent configuration.
29-
27+
3028
Args:
3129
configuration: The AI agent configuration to add or update
3230
schema_type: Optional type to use for generating sample schema
33-
31+
3432
Returns:
3533
Result containing the agent identifier and raft command index
3634
"""
3735
from ravendb.documents.operations.ai.agents import AddOrUpdateAiAgentOperation
38-
36+
3937
operation = AddOrUpdateAiAgentOperation(configuration, schema_type)
4038
return self._store.maintenance.send(operation)
4139

4240
def delete_agent(self, identifier: str) -> AiAgentConfigurationResult:
4341
"""
4442
Deletes an AI agent configuration.
45-
43+
4644
Args:
4745
identifier: The identifier of the agent to delete
48-
46+
4947
Returns:
5048
Result containing the raft command index
5149
"""
5250
from ravendb.documents.operations.ai.agents import DeleteAiAgentOperation
53-
51+
5452
operation = DeleteAiAgentOperation(identifier)
5553
return self._store.maintenance.send(operation)
5654

5755
def get_agents(self, agent_id: str = None) -> GetAiAgentsResponse:
5856
"""
5957
Gets AI agent configurations.
60-
58+
6159
Args:
6260
agent_id: Optional specific agent ID to retrieve. If None, returns all agents.
63-
61+
6462
Returns:
6563
Response containing the list of AI agent configurations
6664
"""
6765
from ravendb.documents.operations.ai.agents import GetAiAgentOperation
68-
66+
6967
operation = GetAiAgentOperation(agent_id)
7068
return self._store.maintenance.send(operation)
7169

72-
def conversation(
73-
self,
74-
agent_id: str,
75-
parameters: Dict[str, Any] = None
76-
) -> IAiConversationOperations:
70+
def conversation(self, agent_id: str, parameters: Dict[str, Any] = None) -> IAiConversationOperations:
7771
"""
7872
Creates a new conversation with the specified AI agent.
79-
73+
8074
Args:
8175
agent_id: The identifier of the AI agent to start a conversation with
8276
parameters: Optional parameters to pass to the agent
83-
77+
8478
Returns:
8579
Conversation operations interface for managing the conversation
8680
"""
8781
from ravendb.documents.ai.ai_conversation import AiConversation
88-
82+
8983
return AiConversation(self._store, agent_id, parameters)
9084

91-
def conversation_with_id(
92-
self,
93-
conversation_id: str,
94-
change_vector: str = None
95-
) -> IAiConversationOperations:
85+
def conversation_with_id(self, conversation_id: str, change_vector: str = None) -> IAiConversationOperations:
9686
"""
9787
Continues an existing conversation by its ID.
98-
88+
9989
Args:
10090
conversation_id: The ID of the existing conversation
10191
change_vector: Optional change vector for optimistic concurrency
102-
92+
10393
Returns:
10494
Conversation operations interface for managing the conversation
10595
"""
10696
from ravendb.documents.ai.ai_conversation import AiConversation
107-
97+
10898
return AiConversation.with_conversation_id(self._store, conversation_id, change_vector)

ravendb/documents/operations/ai/agents/add_or_update_ai_agent_operation.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ def __init__(self, configuration: AiAgentConfiguration, schema_type: Type = None
3131
if configuration is None:
3232
raise ValueError("configuration cannot be None")
3333

34-
if (
35-
not configuration.output_schema
36-
and not configuration.sample_object
37-
and schema_type is None
38-
):
34+
if not configuration.output_schema and not configuration.sample_object and schema_type is None:
3935
raise ValueError(
4036
"Please provide a non-empty value for either output_schema or sample_object or schema_type"
4137
)
@@ -70,7 +66,7 @@ def create_request(self, node: ServerNode) -> requests.Request:
7066

7167
# Set sample object if not provided but we have a schema type
7268
if not config_to_send.sample_object and self._sample_schema:
73-
if hasattr(self._sample_schema, '__dict__'):
69+
if hasattr(self._sample_schema, "__dict__"):
7470
config_to_send.sample_object = json.dumps(self._sample_schema.__dict__)
7571
else:
7672
config_to_send.sample_object = json.dumps(self._sample_schema)
@@ -96,4 +92,5 @@ def set_response(self, response: str, from_cache: bool) -> None:
9692
def get_raft_unique_request_id(self) -> str:
9793
# Generate a unique ID for Raft operations
9894
import uuid
95+
9996
return str(uuid.uuid4())

ravendb/documents/operations/ai/agents/ai_agent_configuration.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentToolQuery:
3232
instance.name = json_dict.get("name") or json_dict.get("Name")
3333
instance.description = json_dict.get("description") or json_dict.get("Description")
3434
instance.query = json_dict.get("query") or json_dict.get("Query")
35-
instance.parameters_sample_object = json_dict.get("parametersSampleObject") or json_dict.get("ParametersSampleObject")
35+
instance.parameters_sample_object = json_dict.get("parametersSampleObject") or json_dict.get(
36+
"ParametersSampleObject"
37+
)
3638
instance.parameters_schema = json_dict.get("parametersSchema") or json_dict.get("ParametersSchema")
3739
return instance
3840

@@ -63,7 +65,9 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentToolAction:
6365
instance = cls()
6466
instance.name = json_dict.get("name") or json_dict.get("Name")
6567
instance.description = json_dict.get("description") or json_dict.get("Description")
66-
instance.parameters_sample_object = json_dict.get("parametersSampleObject") or json_dict.get("ParametersSampleObject")
68+
instance.parameters_sample_object = json_dict.get("parametersSampleObject") or json_dict.get(
69+
"ParametersSampleObject"
70+
)
6771
instance.parameters_schema = json_dict.get("parametersSchema") or json_dict.get("ParametersSchema")
6872
return instance
6973

@@ -88,7 +92,9 @@ def to_json(self) -> Dict[str, Any]:
8892
def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentPersistenceConfiguration:
8993
instance = cls()
9094
instance.conversation_id_prefix = json_dict.get("conversationIdPrefix") or json_dict.get("ConversationIdPrefix")
91-
instance.conversation_expiration_in_sec = json_dict.get("conversationExpirationInSec") or json_dict.get("ConversationExpirationInSec")
95+
instance.conversation_expiration_in_sec = json_dict.get("conversationExpirationInSec") or json_dict.get(
96+
"ConversationExpirationInSec"
97+
)
9298
return instance
9399

94100

@@ -121,7 +127,9 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentSummarizationByTokens:
121127
instance.summarization_task_beginning_prompt = json_dict.get("SummarizationTaskBeginningPrompt")
122128
instance.summarization_task_end_prompt = json_dict.get("SummarizationTaskEndPrompt")
123129
instance.result_prefix = json_dict.get("ResultPrefix")
124-
instance.max_tokens_before_summarization = json_dict.get("MaxTokensBeforeSummarization", cls.DEFAULT_MAX_TOKENS_BEFORE_SUMMARIZATION)
130+
instance.max_tokens_before_summarization = json_dict.get(
131+
"MaxTokensBeforeSummarization", cls.DEFAULT_MAX_TOKENS_BEFORE_SUMMARIZATION
132+
)
125133
instance.max_tokens_after_summarization = json_dict.get("MaxTokensAfterSummarization", 1024)
126134
return instance
127135

@@ -146,8 +154,12 @@ def to_json(self) -> Dict[str, Any]:
146154
@classmethod
147155
def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentTruncateChat:
148156
instance = cls()
149-
instance.messages_length_before_truncate = json_dict.get("MessagesLengthBeforeTruncate", cls.DEFAULT_MESSAGES_LENGTH_BEFORE_TRUNCATE)
150-
instance.messages_length_after_truncate = json_dict.get("MessagesLengthAfterTruncate", cls.DEFAULT_MESSAGES_LENGTH_BEFORE_TRUNCATE // 2)
157+
instance.messages_length_before_truncate = json_dict.get(
158+
"MessagesLengthBeforeTruncate", cls.DEFAULT_MESSAGES_LENGTH_BEFORE_TRUNCATE
159+
)
160+
instance.messages_length_after_truncate = json_dict.get(
161+
"MessagesLengthAfterTruncate", cls.DEFAULT_MESSAGES_LENGTH_BEFORE_TRUNCATE // 2
162+
)
151163
return instance
152164

153165

@@ -227,10 +239,7 @@ def __init__(self, name: str = None, connection_string_name: str = None, system_
227239

228240
def to_json(self) -> Dict[str, Any]:
229241
# Convert parameters set to list of parameter objects using list comprehension
230-
parameters_list = [
231-
{"Name": param_name, "Description": None}
232-
for param_name in self.parameters
233-
]
242+
parameters_list = [{"Name": param_name, "Description": None} for param_name in self.parameters]
234243

235244
return {
236245
"Identifier": self.identifier,
@@ -284,5 +293,7 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentConfiguration:
284293
if trimming_data:
285294
instance.chat_trimming = AiAgentChatTrimmingConfiguration.from_json(trimming_data)
286295

287-
instance.max_model_iterations_per_call = json_dict.get("maxModelIterationsPerCall") or json_dict.get("MaxModelIterationsPerCall")
296+
instance.max_model_iterations_per_call = json_dict.get("maxModelIterationsPerCall") or json_dict.get(
297+
"MaxModelIterationsPerCall"
298+
)
288299
return instance

ravendb/documents/operations/ai/agents/delete_ai_agent_operation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ def set_response(self, response: str, from_cache: bool) -> None:
4646
def get_raft_unique_request_id(self) -> str:
4747
# Generate a unique ID for Raft operations
4848
import uuid
49+
4950
return str(uuid.uuid4())

ravendb/documents/operations/ai/agents/get_ai_agent_operation.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ def __init__(self):
2020
@classmethod
2121
def from_json(cls, json_dict: Dict[str, Any]) -> GetAiAgentsResponse:
2222
from ravendb.documents.operations.ai.agents.ai_agent_configuration import AiAgentConfiguration
23-
23+
2424
response = cls()
2525
if json_dict.get("AiAgents"):
26-
response.ai_agents = [
27-
AiAgentConfiguration.from_json(agent_json)
28-
for agent_json in json_dict["AiAgents"]
29-
]
26+
response.ai_agents = [AiAgentConfiguration.from_json(agent_json) for agent_json in json_dict["AiAgents"]]
3027
return response
3128

3229

0 commit comments

Comments
 (0)