-
Notifications
You must be signed in to change notification settings - Fork 46k
feat(platform): retire brain dump greeting once a user has a session #13804
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fe5d69a
feat(platform): retire the greeting when a user already has a session
Abhi1992002 5d36ec4
fix(platform): address review β dedupe recommended providers, guard tβ¦
Abhi1992002 363aadf
fix(backend): stub the session count in brain dump route tests
Abhi1992002 a4946c0
fix(backend): keep a failed greeting-seen write from 500ing the introβ¦
Abhi1992002 54c140f
Merge upstream/dev into brain-dump-greeting-cleanup
Abhi1992002 f4ed8f0
refactor(platform): address review β presence check, orb module, reduβ¦
Abhi1992002 2c3e8eb
test(backend): cover the session-presence query, hoist its fixture
Abhi1992002 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
Some comments aren't visible on the classic Files Changed page.
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
82 changes: 82 additions & 0 deletions
82
autogpt_platform/backend/backend/api/features/onboarding_dump/intro_test.py
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Tests for the greeting generation's prompt assembly. | ||
|
|
||
| The greeting promises the user specific automations, so what the model is | ||
| told this platform can connect to is part of the contract β a greeting | ||
| built without the registry offers integrations we do not have. | ||
| """ | ||
|
|
||
| import json | ||
| from types import SimpleNamespace | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from backend.api.features.onboarding_dump import intro | ||
|
|
||
| TRANSCRIPT = "I run a bakery and want the weekly order emails handled." | ||
|
|
||
| GENERATION = { | ||
| "greeting": "You mentioned the weekly order emails.", | ||
| "prompts": [ | ||
| {"title": f"Automation number {i}", "prompt": "Do it.", "icon": "sparkle"} | ||
| for i in range(5) | ||
| ], | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(mocker: MockerFixture) -> MagicMock: | ||
| completion = SimpleNamespace( | ||
| choices=[ | ||
| SimpleNamespace(message=SimpleNamespace(content=json.dumps(GENERATION))) | ||
| ] | ||
| ) | ||
| fake = MagicMock() | ||
| fake.chat.completions.create = AsyncMock(return_value=completion) | ||
| mocker.patch( | ||
| "backend.api.features.onboarding_dump.intro.get_openai_client", | ||
| return_value=fake, | ||
| ) | ||
| mocker.patch( | ||
| "backend.api.features.onboarding_dump.intro._fetch_langfuse_prompt", | ||
| new=AsyncMock(return_value=None), | ||
| ) | ||
| return fake | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_greeting_prompt_carries_the_provider_registry( | ||
| client: MagicMock, mocker: MockerFixture | ||
| ): | ||
| mocker.patch( | ||
| "backend.api.features.onboarding_dump.intro.known_providers", | ||
| return_value={"slack": "Team chat", "github": None}, | ||
| ) | ||
|
|
||
| greeting, prompts = await intro.generate_intro(TRANSCRIPT) | ||
|
|
||
| content = client.chat.completions.create.await_args.kwargs["messages"][0]["content"] | ||
| assert "- slack: Team chat" in content | ||
| assert "- github" in content | ||
| # Registry first, then the instructions, then the transcript they end | ||
| # with β the static half of the message stays a stable prefix. | ||
| assert content.index("- slack") < content.index(TRANSCRIPT) | ||
| assert greeting == GENERATION["greeting"] | ||
| assert len(prompts) == 5 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_greeting_prompt_survives_an_empty_registry( | ||
| client: MagicMock, mocker: MockerFixture | ||
| ): | ||
| mocker.patch( | ||
| "backend.api.features.onboarding_dump.intro.known_providers", | ||
| return_value={}, | ||
| ) | ||
|
|
||
| greeting, _ = await intro.generate_intro(TRANSCRIPT) | ||
|
|
||
| content = client.chat.completions.create.await_args.kwargs["messages"][0]["content"] | ||
| assert content.startswith(intro._LOCAL_PROMPT[:40]) | ||
| assert greeting == GENERATION["greeting"] |
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
38 changes: 38 additions & 0 deletions
38
autogpt_platform/backend/backend/api/features/onboarding_dump/providers.py
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """The live integration registry, as prompt context. | ||
|
|
||
| Both LLM jobs need to know what this platform can actually connect to: | ||
| the recommender picks from the list, and the greeting needs it so the | ||
| automations it proposes are ones we can really run. Shared here so the | ||
| two can never drift onto different views of the registry. | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| from backend.api.features.integrations.models import ( | ||
| get_all_provider_names, | ||
| get_provider_description, | ||
| ) | ||
| from backend.blocks import load_all_blocks | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
|
Abhi1992002 marked this conversation as resolved.
|
||
| def known_providers() -> dict[str, str | None]: | ||
| """The live provider registry as ``{id: description}``. | ||
|
|
||
| Mirrors the ``/providers`` endpoint: block modules must be imported | ||
| before AutoRegistry knows about SDK-registered providers. | ||
|
Abhi1992002 marked this conversation as resolved.
Abhi1992002 marked this conversation as resolved.
Abhi1992002 marked this conversation as resolved.
|
||
| """ | ||
|
Abhi1992002 marked this conversation as resolved.
Abhi1992002 marked this conversation as resolved.
|
||
| try: | ||
| load_all_blocks() | ||
| except Exception as e: # static providers still work | ||
|
Abhi1992002 marked this conversation as resolved.
|
||
| logger.warning("Brain dump: block load failed: %s", e) | ||
| return {name: get_provider_description(name) for name in get_all_provider_names()} | ||
|
|
||
|
|
||
| def provider_lines(providers: dict[str, str | None]) -> str: | ||
| """``providers`` as one ``- id: description`` line each.""" | ||
| return "\n".join( | ||
| f"- {name}: {description}" if description else f"- {name}" | ||
| for name, description in providers.items() | ||
| ) | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.