Skip to content

Commit

Permalink
Merge pull request #1716 from tommygonzaleza/development
Browse files Browse the repository at this point in the history
Add user auth context to rigobot
  • Loading branch information
tommygonzaleza authored Nov 26, 2024
2 parents d344c13 + 1325ef9 commit c22ed8c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/common/context/AuthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ModalInfo from '../../js_modules/moduleMap/modalInfo';
import Text from '../components/Text';
import { SILENT_CODE } from '../../lib/types';
import { warn } from '../../utils/logging';
import { generateUserContext } from '../../utils/rigobotContext';

const initialState = {
isLoading: true,
Expand Down Expand Up @@ -240,7 +241,10 @@ function AuthProvider({ children, pageProps }) {
useEffect(() => {
if (user && isRigoInitialized) {
const token = getToken();
const context = generateUserContext(user);

rigo.updateOptions({
context,
user: {
token,
nickname: `${user.first_name} ${user.last_name}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ORIGIN_HOST, BREATHECODE_HOST } from '../../../../../utils/variables';
import useSession from '../../../../../common/hooks/useSession';
import { log } from '../../../../../utils/logging';
import completions from './completion-jobs.json';
import { generateUserContext } from '../../../../../utils/rigobotContext';

function SyllabusContent() {
const { t, lang } = useTranslation('syllabus');
Expand Down Expand Up @@ -233,9 +234,11 @@ function SyllabusContent() {
} else aiContext = cachedContext;

if (aiContext) {
const userContext = generateUserContext(user);

rigo.updateOptions({
showBubble: false,
context: aiContext.ai_context,
context: `${userContext ? `Here is some information about this user: ${userContext}. \n` : ''}${aiContext.ai_context}`,
completions,
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/utils/rigobotContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const generateUserContext = (user) => {
const { first_name, last_name, date_joined, roles, settings } = user;
let ai_context = '';

if (first_name) ai_context += "The user's first name is " + first_name + '. ';
if (last_name) ai_context += "The user's last name is " + last_name + '. ';
if (date_joined) ai_context += 'The user joined on ' + date_joined + '. ';
if (roles) roles.forEach((role) => ai_context += 'The user has the role of ' + role.role + ' in the academy of ' + role.academy.name + '. ');
if (settings) ai_context += 'The user has the following settings: Default language: ' + settings.lang + '.';

return ai_context;
};

0 comments on commit c22ed8c

Please sign in to comment.