Skip to content
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

Helenlei/costing admin page #439

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

leihelen
Copy link
Contributor

@leihelen leihelen commented Mar 24, 2024

Created a dashboard summary of OpenAI API costs that can be reached at '/admin/costing'. Can choose on the dropdown menu a minimum number of reviews to run the summary on and then will generate the costing estimates for that minimum.
Screenshot 2024-03-23 at 9 33 13 PM

@leihelen leihelen requested a review from a team as a code owner March 24, 2024 01:38
@dti-github-bot
Copy link
Member

[diff-counting] Significant lines: 261.

Copy link
Contributor

@qiandrewj qiandrewj left a comment

Choose a reason for hiding this comment

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

Overall, the implementation of the costing page was really well done, and used a clean UI that I thought was perfect for getting all of the behind-the-scenes information from the admin page -- I'll be drawing from that for the future. Only some small changes I left throughout the code to keep the codebase clean, but this will be useful for us moving forward!

getCostingData(value, setTotalTokens);
}}
>
<option value="100000">x</option>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of setting the initial or "empty" state as an arbitrarily high limit for minimum reviews, it could just default to the lowest minimum number of reviews (3).

@@ -6,6 +6,7 @@ import { Home } from './modules/Home'
import { Course } from './modules/Course'
import { Profile } from './modules/Profile'
import { Admin } from './modules/Admin'
import { AdminCosting } from './modules/AdminCosting'
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I'm not quite sure about, but could be a more clean way to separate the admin page and its functionality from the rest of the app - maybe Admin could contain a router of its own so that new pages to Admin are not all added to the overall app.

function getCostingData(min: number, setTotalTokens: React.Dispatch<React.SetStateAction<number>>) {
console.log('loading costing data...');

axios.post('/ai/costing', { min })
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be more clear what this route is related to if it was changed to something like /admin/aicosting

Comment on lines +36 to +40
if (res.data.result) {
setIsAdmin(true)
} else {
setIsAdmin(false)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could condense this into setIsAdmin(res.data.result) for easier readability.

<p>$1.50/1M tokens output</p>
</div>

<div className="other-numbers">
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of "other-numbers", this class name could be "review-stats" or "review-numbers" to better represent the information rendered here.


function adminLogin() {
if (loading) {
return <div>Loading...</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Once you pull Andrew's PR for the loading screen, replace "Loading..." with the loading spinner component using return <Loading />

Comment on lines +13 to +27
try {
const costing = await minReviewsCosting(min);
if (minReviewsCosting === null) {
return res.status(400).json({
error: `No reviews found`,
});
}

return res.status(200).json({
message: 'Retrieved all pending reviews',
result: costing,
});
} catch (err) {
return res.status(500).json({ error: `Internal Server Error: ${err}` });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move around some of these status responses to keep it consistent with the rest of the codebase

Suggested change
try {
const costing = await minReviewsCosting(min);
if (minReviewsCosting === null) {
return res.status(400).json({
error: `No reviews found`,
});
}
return res.status(200).json({
message: 'Retrieved all pending reviews',
result: costing,
});
} catch (err) {
return res.status(500).json({ error: `Internal Server Error: ${err}` });
}
try {
const costing = await minReviewsCosting(min);
if (!costing) {
return res.status(500).json({ error: `Internal Server Error` });
}
return res.status(200).json({
message: `Retrieved all pending reviews for a minimum value of ${min}`,
result: costing,
});
} catch (err) {
return res
.status(400)
.json({ error: `No reviews found` });
}

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.

None yet

4 participants