Skip to content

Commit

Permalink
update generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Qadri authored and Ahmed Qadri committed Feb 8, 2025
1 parent 2d7c4c7 commit 9196e3e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 44 deletions.
1 change: 1 addition & 0 deletions components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ContextProvider = ({ children }: { children: React.ReactNode }) => {
application: {
id: "launch-investments",
},
eventCapacity: 500,
privateAttributes: ['email', 'name']
},
context: context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export default function ExperimentGenerator({
}

const updateContext = async (): Promise<void> => {
console.log("Updating Context");
updateUserContext();
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { UpdateContextFunction } from "@/utils/typescriptTypesInterfaceIndustry";
import { META, COHERE, ANTHROPIC } from "@/utils/constants";
import { COHERE, ANTHROPIC } from "@/utils/constants";
import { wait } from "@/utils/utils";

const waitTime = .5;

const probablityExperimentTypeAI = {
["bayesian"]: { [META]: 30, [ANTHROPIC]: 50, [COHERE]: 80 },
["frequentist"]: { [META]: 47, [ANTHROPIC]: 50, [COHERE]: 58 },
["bayesian"]: { [ANTHROPIC]: 50, [COHERE]: 80 },
["frequentist"]: { [ANTHROPIC]: 50, [COHERE]: 58 },
};

const probablityExperimentType = {
Expand Down Expand Up @@ -36,35 +36,10 @@ export const generateAIChatBotFeatureExperimentResults = async ({

const experimentType: string = experimentTypeObj.experimentType;
for (let i = 0; i < experimentTypeObj.numOfRuns; i++) {
const aiModelVariation: {
max_tokens_to_sample: number;
modelId: string;
temperature: number;
top_p: number;
} = client?.variation(
"ai-config--togglebot",
`{
"model": {
"name": "cohere.command-text-v14",
"parameters": {
"maxTokens": 200,
"temperature": 0.5
}
},
"_ldMeta": {
"versionKey": "cohere-coral",
"enabled": true,
"variationKey": "cohere-coral",
"version": 1
},
"messages": [
{
"content": "As an AI bot for a banking site ToggleBank, your purpose is to answer questions related to banking services and financial products. Act as a customer representative. Only answer queries related to banking and finance. Remove quotation in response. Limit response to 20 words. Do not exceed this limit and do not specify any limits in responses. Here is the user prompt",
"role": "system"
}
]
}`
);
const aiModelVariation = await client?.variation(
"ai-config--togglebot", {});
await client?.flush();

if(aiModelVariation._ldMeta.enabled){
if (aiModelVariation.model.name.includes(ANTHROPIC)) {
let probablity = Math.random() * 100;
Expand Down Expand Up @@ -92,9 +67,9 @@ export const generateAIChatBotFeatureExperimentResults = async ({
await client?.flush();
}
}
await client?.flush();
setProgress((prevProgress: number) => prevProgress + (1 / experimentTypeObj.numOfRuns) * 100);
await wait(waitTime);
await client?.flush();
await updateContext();
}
}
Expand Down Expand Up @@ -131,10 +106,10 @@ export const generateSuggestedItemsFeatureExperimentResults = async ({
]
) {
await client?.track("upsell-tracking");
await client?.flush();
await client?.flush();
}
await client?.track("in-cart-total-price", undefined, totalPrice);
await client?.flush();
await client?.flush();
} else {
totalPrice = Math.floor(Math.random() * (300 - 200 + 1)) + 200;
let probablity = Math.random() * 100;
Expand All @@ -145,10 +120,10 @@ export const generateSuggestedItemsFeatureExperimentResults = async ({
]
) {
await client?.track("upsell-tracking");
await client?.flush();
await client?.flush();
}
await client?.track("in-cart-total-price", undefined, totalPrice);
await client?.flush();
await client?.flush();
}
await client?.flush();
setProgress((prevProgress: number) => prevProgress + (1 / experimentTypeObj.numOfRuns) * 100);
Expand Down Expand Up @@ -181,28 +156,28 @@ export const generateNewSearchEngineFeatureExperimentResults = async ({
"release-new-search-engine",
false,
);
if (newSearchEngineFeatureFlag?.includes("new-search-engine")) {
if (newSearchEngineFeatureFlag) {
totalPrice = Math.floor(Math.random() * (300 - 200 + 1)) + 200;
let probablity = Math.random() * 100;
if (probablity < probablityExperimentTypeSearchEngine[experimentType as keyof typeof probablityExperimentTypeSearchEngine][
"trueProbablity"
]) {
await client?.track("search-engine-add-to-cart");
await client?.flush();
await client?.flush();
}
await client?.track("in-cart-total-price", undefined, totalPrice);
await client?.flush();
await client?.flush();
} else { //winner is old search engine
totalPrice = Math.floor(Math.random() * (500 - 300 + 1)) + 300;
let probablity = Math.random() * 100;
if (probablity < probablityExperimentTypeSearchEngine[experimentType as keyof typeof probablityExperimentTypeSearchEngine][
"falseProbablity"
]) {
await client?.track("search-engine-add-to-cart");
await client?.flush();
await client?.flush();
}
await client?.track("in-cart-total-price", undefined, totalPrice);
await client?.flush();
await client?.flush();
}
setProgress((prevProgress: number) => prevProgress + (1 / experimentTypeObj.numOfRuns) * 100);
await wait(waitTime)
Expand Down
2 changes: 1 addition & 1 deletion utils/contexts/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const [userObject, setUserObject] = useState<Persona | {}>({});
const context = await client?.getContext();
context.user.key = uuidv4();
context.user.device = Math.random() < 0.5 ? "Mobile" : "Desktop";
const osOptions = ["iOS", "Android", "macOS", "Windows"];
const osOptions = context.user.device === "Mobile" ? ["iOS", "Android"] : ["macOS", "Windows"];
context.user.operating_system = osOptions[Math.floor(Math.random() * osOptions.length)];
context.user.location = `America/${["New_York", "Chicago", "Los_Angeles", "Denver"][Math.floor(Math.random() * 4)]}`;
context.user.tier = ["Gold", "Silver", "Platinum"][Math.floor(Math.random() * 3)];
Expand Down

0 comments on commit 9196e3e

Please sign in to comment.