CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/chat/llm-cost-estimation.tsx
Views: 687
1
import { Tooltip } from "antd";
2
import { useIntl } from "react-intl";
3
4
import { CSS } from "@cocalc/frontend/app-framework";
5
import { HelpIcon, Paragraph } from "@cocalc/frontend/components";
6
import {
7
ESTIMATION_HELP_TEXT,
8
MODEL_FREE_TO_USE,
9
} from "@cocalc/frontend/misc/llm-cost-estimation";
10
11
export function LLMCostEstimationChat({
12
costEstimate,
13
compact,
14
style,
15
}: {
16
costEstimate?: { min: number; max: number } | null;
17
compact: boolean; // only mean is shown
18
style?: CSS;
19
}) {
20
const intl = useIntl();
21
22
if (!costEstimate) {
23
return null;
24
}
25
26
const { min, max } = costEstimate;
27
const sum = min + max;
28
if (min == null || max == null || isNaN(sum)) return null;
29
const isFree = min === 0 && max === 0;
30
const range = (
31
<>
32
${min.toFixed(2)} - ${max.toFixed(2)}
33
</>
34
);
35
const 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
);
44
45
return (
46
<Paragraph
47
type="secondary"
48
style={{
49
whiteSpace: "nowrap",
50
...style,
51
}}
52
>
53
{cost}{" "}
54
<HelpIcon title={"LLM Cost Estimation"} placement={"topLeft"}>
55
<Paragraph>
56
This chat message mentions a language model or replies in a thread.
57
This means, right after sending the message, the message and the
58
content of the current thread will be sent to the LLM for processing.
59
Then, the LLM will start replying to your message.
60
</Paragraph>
61
<Paragraph>
62
{isFree ? (
63
<>{intl.formatMessage(MODEL_FREE_TO_USE)}</>
64
) : (
65
<>
66
The 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
}
76
77