-
Notifications
You must be signed in to change notification settings - Fork 14
User experiment migration tool #1724
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
Open
stephherbers
wants to merge
12
commits into
main
Choose a base branch
from
smh/migration-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
383eb67
add option to skip confirmation so it can be done by celery task
stephherbers 3d148a7
add task linked to banner
stephherbers 41f1683
url
stephherbers b0bd7ac
Merge branch 'smh/exp-pipeline-migration' into smh/migration-tool
stephherbers a0f3223
no task needed
stephherbers 47b482c
refactor: move bulk of logic out of command
stephherbers 0bdec24
add permissions
stephherbers b62d59d
add comments
stephherbers 6067ff0
lint
stephherbers 0b41555
Merge branch 'smh/exp-pipeline-migration' into smh/migration-tool
stephherbers 72c5515
validate pipeline is not already created
stephherbers d3e6bb6
merge main + refactor to use helper functions
stephherbers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,3 +35,83 @@ def duplicate_pipeline_with_new_ids(pipeline_data): | |||||||||
edge["target"] = new_target_id | ||||||||||
|
||||||||||
return new_data, old_to_new_node_ids | ||||||||||
|
||||||||||
|
||||||||||
def convert_non_pipeline_experiment_to_pipeline(experiment): | ||||||||||
snopoke marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
if experiment.assistant: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra paranoid validation that we can actually migrate this before we do
Suggested change
|
||||||||||
pipeline = _create_assistant_pipeline(experiment) | ||||||||||
elif experiment.llm_provider: | ||||||||||
pipeline = _create_llm_pipeline(experiment) | ||||||||||
else: | ||||||||||
raise ValueError(f"Unknown experiment type for experiment {experiment.id}") | ||||||||||
|
||||||||||
experiment.pipeline = pipeline | ||||||||||
experiment.assistant = None | ||||||||||
experiment.llm_provider = None | ||||||||||
experiment.llm_provider_model = None | ||||||||||
experiment.save() | ||||||||||
|
||||||||||
|
||||||||||
def _create_pipeline_with_node(experiment, node_type, node_label, node_params): | ||||||||||
from .models import Pipeline | ||||||||||
|
||||||||||
"""Create a pipeline with start -> custom_node -> end structure.""" | ||||||||||
pipeline_name = f"{experiment.name} Pipeline" | ||||||||||
middle_node_config = { | ||||||||||
"id": str(uuid4()), | ||||||||||
"type": "pipelineNode", | ||||||||||
"position": {"x": 400, "y": 200}, | ||||||||||
"data": {"type": node_type, "label": node_label, "params": node_params}, | ||||||||||
} | ||||||||||
|
||||||||||
return Pipeline._create_pipeline_with_nodes( | ||||||||||
team=experiment.team, name=pipeline_name, middle_nodes_config=middle_node_config | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
def _create_llm_pipeline(experiment): | ||||||||||
from apps.pipelines.nodes.nodes import LLMResponseWithPrompt | ||||||||||
|
||||||||||
"""Create a start -> LLMResponseWithPrompt -> end nodes pipeline for an LLM experiment.""" | ||||||||||
llm_params = { | ||||||||||
"name": "llm", | ||||||||||
"llm_provider_id": experiment.llm_provider.id, | ||||||||||
"llm_provider_model_id": experiment.llm_provider_model.id, | ||||||||||
"llm_temperature": experiment.temperature, | ||||||||||
"history_type": "global", | ||||||||||
"history_name": None, | ||||||||||
"history_mode": "summarize", | ||||||||||
"user_max_token_limit": experiment.llm_provider_model.max_token_limit, | ||||||||||
"max_history_length": 10, | ||||||||||
"source_material_id": experiment.source_material.id if experiment.source_material else None, | ||||||||||
"prompt": experiment.prompt_text or "", | ||||||||||
"tools": list(experiment.tools) if experiment.tools else [], | ||||||||||
"custom_actions": [ | ||||||||||
op.get_model_id(False) for op in experiment.custom_action_operations.select_related("custom_action").all() | ||||||||||
], | ||||||||||
"built_in_tools": [], | ||||||||||
"tool_config": {}, | ||||||||||
} | ||||||||||
|
||||||||||
return _create_pipeline_with_node( | ||||||||||
experiment=experiment, node_type=LLMResponseWithPrompt.__name__, node_label="LLM", node_params=llm_params | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
def _create_assistant_pipeline(experiment): | ||||||||||
from apps.pipelines.nodes.nodes import AssistantNode | ||||||||||
|
||||||||||
"""Create a start -> AssistantNode -> end nodes pipeline for an assistant experiment.""" | ||||||||||
assistant_params = { | ||||||||||
"name": "assistant", | ||||||||||
"assistant_id": str(experiment.assistant.id), | ||||||||||
"citations_enabled": experiment.citations_enabled, | ||||||||||
"input_formatter": experiment.input_formatter or "", | ||||||||||
} | ||||||||||
|
||||||||||
return _create_pipeline_with_node( | ||||||||||
experiment=experiment, | ||||||||||
node_type=AssistantNode.__name__, | ||||||||||
node_label="OpenAI Assistant", | ||||||||||
node_params=assistant_params, | ||||||||||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.