-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: AI dialogue roles support obtaining data from other nodes #1925
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -156,7 +158,7 @@ def get_details(self, index: int, **kwargs): | |||
'name': self.node.properties.get('stepName'), | |||
"index": index, | |||
'run_time': self.context.get('run_time'), | |||
'system': self.node_params.get('system'), | |||
'system': self.context.get('system'), | |||
'history_message': [{'content': message.content, 'role': message.type} for message in | |||
(self.context.get('history_message') if self.context.get( | |||
'history_message') is not None else [])], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided C# code snippet appears to be part of an AI dialog execution function within a workflow management system. Here are some potential improvements and suggestions:
Potential Issues:
-
Duplicate
system
Variable Assignment: Thesystem
variable is assigned twice before use. This can lead to confusion or unintended behavior because the second assignment does not change the original value.system = this.WorkflowManage.GeneratePrompt(system); self.context['system'] = question.content;
-
Unnecessary Condition Check: After assigning
self.context['system']
, there's an unnecessary condition check to ensurequestion.content
is notNone
.'system': self.context.get('system'), ... if stream: ...
3. **Context Key Naming Confusion**: There seems to be a mix-up between using `self.context['system']` and directly accessing `node_params['system']`. It is unclear which one should be preferred, but it could cause errors if `node_params` contains conflicting keys.
### Optimization Suggestions:
1. **Remove Duplicate Logic**: Since both assignments assign `question.content`, remove the duplicate line:
```csharp
// Remove this line as it duplicates what follows
// system = this.WorkflowManage.GeneratePrompt(system);
-
Simplify Stream Handling: Ensure that the rest of the logic handling
stream
does not rely on whetherquestion.content
exists.if (stream) { ... } else { // Handle streaming case differently, e.g., skip it if not available. }
-
Consistent Access Patterns: Decide whether to access context via
self.context[key]
or through specific method calls (node_properties
, etc.). Consistency will make the code easier to maintain.'name': self.node.properties.get('stepName'), // Could also be done like so: 'name': self.node.GetStepName()
Here’s an improved version of the code incorporating these suggestions:
@@ -110,6 +110,7 @@ def execute(self, model_id, system, prompt, dialogue_number, history_chat_record
self.context['history_message'] = history_message
question = self.generate_prompt_question(prompt)
self.context['question'] = question.content
system = self.workflow_manage.generate_prompt(system)
self.context['system'] = question.content
message_list = self.generate_message_list(system, prompt, history_message)
self.context['message_list'] = message_list
if stream:
@@ -158,9 +162,10 @@ def get_details(self, index: int, **kwargs):
# Add more detail retrieval here if needed
}
This updated version removes the redundant assignment of system
, simplifies the stream handling block, and aims for consistent key access patterns.
@@ -138,7 +140,7 @@ def get_details(self, index: int, **kwargs): | |||
'name': self.node.properties.get('stepName'), | |||
"index": index, | |||
'run_time': self.context.get('run_time'), | |||
'system': self.node_params.get('system'), | |||
'system': self.context.get('system'), | |||
'history_message': [{'content': message.content, 'role': message.type} for message in | |||
(self.context.get('history_message') if self.context.get( | |||
'history_message') is not None else [])], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few issues in the code you've provided:
-
Incorrect Use of
workflow_manage
: The linesystem = self.workflow_manage.generate_prompt(system)
seems to be intended to generate a new system string based on existing one, but there's no context about where this method exists. It should either belong to another class instance or be part of an imported module. -
Redundant Context Update: You're updating the context with the same value twice for
system
: once at the beginning (self.context['system']
) and again after generating it (if stream:
block). This might introduce redundancy unless the workflow manages both contexts differently. -
List Comprehension Formatting: In both instances where you create lists from dictionaries, consider using more compact syntax for readability, e.g.,
[{'content': m.content, 'role': m.type} for m in messages]
.
Overall, make sure that workflow_manage
has its own methods appropriately defined and importable within your current script so that these lines can work without errors. If they need to use external data structures or functions, ensure those components are available and properly structured according to their requirements.
feat: AI dialogue roles support obtaining data from other nodes