Skip to content

Commit

Permalink
ai frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejaco committed Oct 14, 2024
1 parent 7e5398b commit 46af35a
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 71 deletions.
2 changes: 1 addition & 1 deletion devcon-app/src/components/domain/app/schedule/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export const Schedule = (props: any) => {
</div>

<RecoilRoot>
<DevaBot recommendationMode sessions={formattedSessions} />
<DevaBot sessions={formattedSessions} />
</RecoilRoot>

{!personalAgenda && (
Expand Down
7 changes: 5 additions & 2 deletions devcon-app/src/services/event-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { APP_CONFIG } from 'utils/config'

const cache = new Map()
const baseUrl = APP_CONFIG.API_BASE_URL
const eventName = 'devcon-6' // 'devcon-vi-2022' // 'devcon-vi-2022' // 'pwa-data'
const eventName = 'devcon-7' // 'devcon-vi-2022' // 'devcon-vi-2022' // 'pwa-data'
const websiteQuestionId = 29
const twitterQuestionId = 44
const githubQuestionId = 43
Expand Down Expand Up @@ -298,7 +298,10 @@ async function get(slug: string) {
return cache.get(slug)
}

const response = await fetch(`${baseUrl}${slug}`).then(resp => resp.json())
// https://api.devcon.org/events/devcon-7/sessions?size=1000&version=1.0.0

// const response = await fetch(`${baseUrl}${slug}`).then(resp => resp.json())
const response = await fetch(`${'https://api.devcon.org'}${slug}`).then(resp => resp.json())

let data = response

Expand Down
29 changes: 15 additions & 14 deletions lib/cms/filenameToUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
*/

export const filenameToUrl = {
index: '/',
dips: '/dips',
past_events: '/past-events',
road_to_devcon: '/road-to-devcon',
faq: '/faq',
programming: '/programming',
tickets: '/tickets',
about: '/about',
supporters: '/supporters',
speaker_applications: '/speaker-applications',
city_guide: '/city-guide',
devcon_week: '/devcon-week',
sea_local: '/sea-local',
} as { [key: string]: string }
index: "/",
dips: "/dips",
past_events: "/past-events",
road_to_devcon: "/road-to-devcon",
faq: "/faq",
programming: "/programming",
tickets: "/tickets",
about: "/about",
supporters: "/supporters",
speaker_applications: "/speaker-applications",
city_guide: "/city-guide",
devcon_week: "/devcon-week",
sea_local: "/sea-local",
experiences: "/experiences",
} as { [key: string]: string };
155 changes: 101 additions & 54 deletions lib/components/ai/overlay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import Image from "next/image";
import Link from "next/link";
// import Link from "next/link";
import Link from "lib/components/link";
import DevaHead from "./deva.png";
import { Button } from "lib/components/button";
import CloseIcon from "../../assets/icons/cross.svg";
Expand Down Expand Up @@ -263,68 +264,114 @@ const DevaBot = ({
? "DevAI responded"
: "You asked"}
</span> */}
<Markdown
<div
className={cn("markdown p-3 py-2 w-auto", {
"mr-4 bg-[#F0F2FF] rounded-tl-xl rounded-tr-xl rounded-br-xl text-left self-start":
isAssistantReply,
"ml-4 bg-[#7D52F4] text-white rounded-tl-xl rounded-tr-xl rounded-bl-xl self-end":
!isAssistantReply,
})}
>
{
message.text.split(
"System: The current date is:"
)[0]
}
</Markdown>

{message.files.length > 0 && (
<div className="flex flex-col text-sm opacity-50 ">
<p className="mt-1">References</p>
<div className="flex gap-2 flex-wrap">
{(() => {
const referencesTracker = {} as any;

return message.files.map(
({ file, fileUrl }: any, index: number) => {
if (recommendationMode) {
const sessionId = file.filename
.split("session_")[1]
.split(".json")[0];

if (!sessionId) return null;

const session = sessions.find(
(session: any) =>
session.id === sessionId
);

return (
<div key={index}>{session.title}</div>
);
}

if (fileUrl) {
if (referencesTracker[file.fileUrl])
return null;

referencesTracker[file.fileUrl] = true;
return (
<Link href={fileUrl} key={index}>
https://devcon.org{fileUrl}
</Link>
);
} else {
return (
<div key={index}>{file.filename}</div>
);
<Markdown className={cn("markdown")}>
{
message.text.split(
"System: The current date is:"
)[0]
}
</Markdown>

{message.files.length > 0 && (
<div className="flex flex-col text-sm">
<p className="mt-1 mb-2 font-bold">
References
</p>
<div className="flex gap-2 flex-wrap">
{(() => {
const referencesTracker = {} as any;

return message.files.map(
(
{ file, fileUrl }: any,
index: number
) => {
// Show if AI-context was the source of the answer, but don't show it in production (meaningless to end user)
if (
process.env.NODE_ENV !==
"development" &&
file.filename === "ai_context.txt"
)
return (
<React.Fragment
key={index}
></React.Fragment>
);

const sessionId =
file &&
file.filename &&
file.filename.startsWith(
"session_"
) &&
file.filename.endsWith(".json") &&
file.filename
.split("session_")[1]
.split(".json")[0];

if (sessionId) {
const session = sessions.find(
(session: any) =>
session.id === sessionId
);

if (session) {
return (
<Link
href={`/sessions/${session.id}`}
className="p-2 bg-[#303030] rounded-md !text-white text-xs flex flex-col gap-1 hover:bg-[#232323] transition-all duration-300 w-full"
key={index}
>
<p className="">
{session.title}
</p>
<p>{session.type}</p>
<p className="opacity-70">
{session.speakers
.map(
(speaker: any) =>
speaker.name
)
.join(", ")}
</p>
</Link>
);
}
}

if (fileUrl) {
if (referencesTracker[file.fileUrl])
return null;

referencesTracker[file.fileUrl] =
true;
return (
<Link href={fileUrl} key={index}>
https://devcon.org{fileUrl}
</Link>
);
} else {
return (
<div key={index}>
{file.filename}
</div>
);
}
}
}
);
})()}
);
})()}
</div>
</div>
</div>
)}
)}
</div>
</div>
);
})}
Expand Down

0 comments on commit 46af35a

Please sign in to comment.