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-msg-feedback.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Button, Space } from "antd";
7
import { redux } from "@cocalc/frontend/app-framework";
8
import { HelpIcon, Icon, Text } from "@cocalc/frontend/components";
9
import { useProjectContext } from "../project/context";
10
import { ChatActions } from "./actions";
11
import { ChatMessageTyped, Feedback } from "./types";
12
13
interface FeedackLLMProps {
14
actions?: ChatActions;
15
message: ChatMessageTyped;
16
}
17
18
export function FeedbackLLM({ actions, message }: FeedackLLMProps) {
19
const { onCoCalcCom } = useProjectContext();
20
21
if (actions == null) return null;
22
const account_id = redux.getStore("account").get_account_id();
23
24
//const date = message.get("date")?.getTime() ?? 0;
25
const val = message.getIn(["feedback", account_id]);
26
27
function feedback(what: Feedback) {
28
return `Give ${what} feedback about this answer written by the language model.`;
29
}
30
31
const isNegative = val === "negative";
32
const isPositive = val === "positive";
33
34
function renderUnhappy() {
35
if (!isNegative) return null;
36
37
return (
38
<>
39
<Text type="secondary">
40
Try another model!{" "}
41
<HelpIcon title={"Different Language Models"}>
42
Try a different language models by selecting it in the "Regenerate"
43
dropdown or pick another one the next time you query it. No language
44
model is like another one and answers vary from one another.{" "}
45
{onCoCalcCom ? (
46
<>
47
In particular, there is a significant difference between free
48
and paid models. Paid models are more expensive, because they
49
process the information with a larger model, using more
50
computational resources. They usually have a deeper
51
understanding and are more accurate than free models.
52
</>
53
) : undefined}
54
</HelpIcon>
55
</Text>
56
</>
57
);
58
}
59
60
return (
61
<Space size="small" wrap>
62
<Space>
63
<Button
64
style={{ color: "#555" }}
65
size="small"
66
type={isPositive ? "dashed" : "text"}
67
onClick={() =>
68
actions?.feedback(message, isPositive ? null : "positive")
69
}
70
title={feedback("positive")}
71
>
72
<Icon name="thumbs-up" />
73
</Button>
74
<Button
75
style={{ color: "#555" }}
76
size="small"
77
type={isNegative ? "dashed" : "text"}
78
onClick={() =>
79
actions?.feedback(message, isNegative ? null : "negative")
80
}
81
title={feedback("negative")}
82
>
83
<Icon name="thumbs-down" />
84
</Button>
85
</Space>
86
{renderUnhappy()}
87
</Space>
88
);
89
}
90
91