Skip to content

feat: Implement AI Wizard for experiment generation and enhance exper… #93

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yashpatil641
Copy link
Collaborator

Reviewer: @poornimaramesh @Jayprakash-SE @sidravi1
Estimate:


Ticket

Implement AI Wizard for experiment generation

Description

Goal

This pull request introduces the AI Experiment Wizard, a new feature designed to simplify the experiment creation process. The goal is to empower non-technical platform owners to design and launch robust experiments by answering a few high-level questions, aligning with our core design principle of making the Experiments Engine simple and accessible.

Changes

  • AI Wizard UI: Created a new page at /experiments/add/ai-wizard where users can input their experiment goal, outcome, and the desired number of variants.
  • Backend Integration: Implemented new API endpoints in backend/app/ai_helpers/routers.py that use the Gemini API to generate a complete experiment configuration, including a suggested name, description, experiment type, arms, and contexts.
  • State Management: Updated the useExperimentStore to handle the state of the AI Wizard. The generated experiment details are used to pre-populate the standard experiment creation form for user review.
  • Enhanced Summary Page: The experiment summary component (/frontend/src/app/(protected)/experiments/add/components/summary.tsx) now displays the AI-generated goal and outcome, providing better context for the experiment's purpose.
  • Validation & Alerts: Added validation alerts to the summary page to notify users if required information is missing before creation.

Future Tasks (optional)

How has this been tested?

To-do before merge (optional)

Checklist

Fill with x for completed.

  • My code follows the style guidelines of this project
  • I have reviewed my own code to ensure good quality
  • I have tested the functionality of my code to ensure it works as intended
  • I have resolved merge conflicts
  • I have updated the automated tests (if applicable)
  • I have updated the requirements (if applicable)
  • I have updated the README file (if applicable)
  • I have updated affected documentation (if applicable)
  • I have added a blogpost in Latest Updates
  • I have updated the CI/CD scripts in workflows
  • I have updated the Terraform code

Demo Video:

rec2.mp4

Copy link
Member

@sidravi1 sidravi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yashpatil641. Left a few comments.

I think this repo is going to become obsolete very soon. It'd be good to have you work on the evidential repos instead.

Also, big PRs are very hard to review. Think about how you can break them up into smaller pieces (e.g. backend only, front end but not connected, integration etc.) to make it easier for the reviewer. You can also use feature branches to make it easier.

from typing import Any, Optional

from fastapi import APIRouter, HTTPException
from google import genai
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Litellm wherever possible to remain foundation model agnostic

router = APIRouter(prefix="/ai_helpers", tags=["AI Helpers"])


class ExperimentAIGenerateRequest(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move these to a schemas.py file. See other routers


goal: str
outcome: str
num_variants: int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in an int?


name: str
description: str
methodType: str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enumeration for this?


api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
raise HTTPException(status_code=500, detail="Gemini API key not set")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code with run at load time before fastapi app is running so should be a different exception - not HTTPException.

) -> list[dict[str, Any]]:
"""Suggest arms for Bayesian A/B test."""
# System instruction for arms suggestion
system_instruction = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/IDinsight/ask-a-question for how to move this our to a different file where we can manage prompts. Also, can i suggest using """ for multiline strings and textwrap.dedent?

"No explanation, no markdown."
)

user_prompt = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use JSON? and then use pydantic to dump JSON

),
)
return json.loads(response.text)
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't catch base exceptions! What exception are you expecting here? Let's just catch those


component: AddNotifications
},
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use prettier to format typescript code? Can i suggest using it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants