Skip to content

Commit

Permalink
feat: Implement Langfuse vote tracking for AI replies
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jan 26, 2025
1 parent 78770a3 commit 401f925
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions components/AIReplySection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { t } from 'ttag';
import { LangfuseWeb } from 'langfuse';

import { Box, Button, makeStyles } from '@material-ui/core';
import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
Expand All @@ -25,12 +26,21 @@ const useStyles = makeStyles(theme => ({
},
}));

function AIReplySection({ defaultExpand = false, aiReplyText = '' }) {
function AIReplySection({ defaultExpand = false, aiReplyText = '', traceId }) {
const [expand, setExpand] = useState(defaultExpand);
const classes = useStyles();

const langfuseWeb = new LangfuseWeb({
publicKey: process.env.NEXT_PUBLIC_LANGFUSE_PUBLIC_KEY,
baseUrl: 'https://cloud.langfuse.com'
});

const handleVote = (vote: 1 | -1) => {
// send vote to Langfuse via LangfuseWeb, AI!
const handleVote = async (vote: 1 | -1) => {
await langfuseWeb.score({
traceId,
name: 'ai_reply_feedback',
value: vote === 1 ? 1 : 0
});
};

return (
Expand Down

0 comments on commit 401f925

Please sign in to comment.