Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/chat/llm-cost-estimation.tsx
1496 views
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
import type { CostEstimate } from "./types";
11
12
export function LLMCostEstimationChat({
13
costEstimate,
14
compact,
15
style,
16
}: {
17
costEstimate?: CostEstimate;
18
compact: boolean; // only mean is shown
19
style?: CSS;
20
}) {
21
const intl = useIntl();
22
23
if (!costEstimate) {
24
return null;
25
}
26
27
const { min, max } = costEstimate;
28
const sum = min + max;
29
if (min == null || max == null || isNaN(sum)) return null;
30
const isFree = min === 0 && max === 0;
31
const range = (
32
<>
33
${min.toFixed(2)} - ${max.toFixed(2)}
34
</>
35
);
36
const cost = isFree ? (
37
<>Free</>
38
) : compact ? (
39
<Tooltip title={<>Estimated cost of calling the LLM: {range}</>}>
40
~${(sum / 2).toFixed(2)}
41
</Tooltip>
42
) : (
43
<>{range}</>
44
);
45
46
return (
47
<Paragraph
48
type="secondary"
49
style={{
50
whiteSpace: "nowrap",
51
...style,
52
}}
53
>
54
{cost}{" "}
55
<HelpIcon title={"LLM Cost Estimation"} placement={"topLeft"}>
56
<Paragraph>
57
This chat message mentions a language model or replies in a thread.
58
This means, right after sending the message, the message and the
59
content of the current thread will be sent to the LLM for processing.
60
Then, the LLM will start replying to your message.
61
</Paragraph>
62
<Paragraph>
63
{isFree ? (
64
<>{intl.formatMessage(MODEL_FREE_TO_USE)}</>
65
) : (
66
<>
67
The estimate for this call is between ${min.toFixed(2)} and $
68
{max.toFixed(2)}.
69
</>
70
)}
71
</Paragraph>
72
{ESTIMATION_HELP_TEXT}
73
</HelpIcon>
74
</Paragraph>
75
);
76
}
77
78