Path: blob/master/src/packages/frontend/chat/llm-cost-estimation.tsx
1496 views
import { Tooltip } from "antd";1import { useIntl } from "react-intl";23import { CSS } from "@cocalc/frontend/app-framework";4import { HelpIcon, Paragraph } from "@cocalc/frontend/components";5import {6ESTIMATION_HELP_TEXT,7MODEL_FREE_TO_USE,8} from "@cocalc/frontend/misc/llm-cost-estimation";9import type { CostEstimate } from "./types";1011export function LLMCostEstimationChat({12costEstimate,13compact,14style,15}: {16costEstimate?: CostEstimate;17compact: boolean; // only mean is shown18style?: CSS;19}) {20const intl = useIntl();2122if (!costEstimate) {23return null;24}2526const { min, max } = costEstimate;27const sum = min + max;28if (min == null || max == null || isNaN(sum)) return null;29const isFree = min === 0 && max === 0;30const range = (31<>32${min.toFixed(2)} - ${max.toFixed(2)}33</>34);35const cost = isFree ? (36<>Free</>37) : compact ? (38<Tooltip title={<>Estimated cost of calling the LLM: {range}</>}>39~${(sum / 2).toFixed(2)}40</Tooltip>41) : (42<>{range}</>43);4445return (46<Paragraph47type="secondary"48style={{49whiteSpace: "nowrap",50...style,51}}52>53{cost}{" "}54<HelpIcon title={"LLM Cost Estimation"} placement={"topLeft"}>55<Paragraph>56This chat message mentions a language model or replies in a thread.57This means, right after sending the message, the message and the58content of the current thread will be sent to the LLM for processing.59Then, the LLM will start replying to your message.60</Paragraph>61<Paragraph>62{isFree ? (63<>{intl.formatMessage(MODEL_FREE_TO_USE)}</>64) : (65<>66The estimate for this call is between ${min.toFixed(2)} and $67{max.toFixed(2)}.68</>69)}70</Paragraph>71{ESTIMATION_HELP_TEXT}72</HelpIcon>73</Paragraph>74);75}767778