Skip to content

Commit

Permalink
Merge pull request #72 from atlantabitdevs/ai-reorg
Browse files Browse the repository at this point in the history
Mega Cleanup and Fix PR
  • Loading branch information
Stephen DeLorme authored Sep 3, 2023
2 parents e2f362d + 9b16bdf commit e157796
Show file tree
Hide file tree
Showing 23 changed files with 206 additions and 1,279 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ next-env.d.ts
ai/build
ai/node_modules
.env
ai/src/types/*.ts
ai/src/types/*.js
ai/src/meetup.ts

.contentlayer
90 changes: 53 additions & 37 deletions ai/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import * as dotenv from 'dotenv';
import * as dotenv from 'dotenv'

import { Configuration, OpenAIApi } from 'openai';
import { ScrapedDataResults, SummaryResults } from './types';
import { auto, mapLimit } from 'async';
import { Configuration, OpenAIApi } from 'openai'
import { ScrapedDataResults, SummaryResults } from './types'
import { auto, mapLimit } from 'async'

import getScrapedData from './get_scraped_data';
import writeSummary from './write_summary';
import getScrapedData from './get_scraped_data'
import writeSummary from './write_summary'
import { meetup } from './meetup'

dotenv.config();
dotenv.config()

const model = 'gpt-3.5-turbo-16k';
const model = 'gpt-3.5-turbo-16k'

type Tasks = {
initAi: {
openai: OpenAIApi;
};
openai: OpenAIApi
}
getScrapedData: {
results: ScrapedDataResults[];
summaryPath: string;
};
summarize: SummaryResults;
};
results: ScrapedDataResults[]
summaryPath: string
}
summarize: SummaryResults
}

const main = async () => {
try {
return await auto<Tasks>({
initAi: async () => {
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
})

const openai = new OpenAIApi(configuration);
const openai = new OpenAIApi(configuration)

return { openai };
return { openai }
},

getScrapedData: [
'initAi',
async ({}) => {
const { results, summaryPath } = await getScrapedData({});
const { results, summaryPath } = await getScrapedData({})

return { results, summaryPath };
return { results, summaryPath }
},
],

Expand All @@ -54,45 +55,60 @@ const main = async () => {
initAi.openai.createChatCompletion({
model,
messages: [
{
role: 'system',
content: meetup.ai[0].system,
},
{
role: 'user',
content: `Can you summarize the text after the asterisk for me? Use no more than 160 words. Split into paragraphs where appropriate. Do not mention the asterisk. * \n ${summary.text}`,
content: `${meetup.ai[0].promptTemplate} ${summary.text}`,
},
],
}),
initAi.openai.createChatCompletion({
model,
messages: [
{
role: 'system',
content: meetup.ai[1].system,
},
{
role: 'user',
content: `Can you summarize the text after the asterisk for me? Use no more than 100 words. Split into paragraphs where appropriate. Write it for a reader that may not be familiar with the technical jargon in the original text. Assume the reader is 15. Do not mention the asterisk. * ${summary.text} `,
content: `${meetup.ai[1].promptTemplate} ${summary.text}`,
},
],
}),
]);
const chatCompletion = aiCompletion[0].data.choices[0].message?.content || 'No summary generated';
const chatCompletionEli15 = aiCompletion[1].data.choices[0].message?.content || 'No summary generated';
])
const chatCompletion =
aiCompletion[0].data.choices[0].message?.content ||
'No summary generated'
const chatCompletionEli15 =
aiCompletion[1].data.choices[0].message?.content ||
'No summary generated'
return {
summary: chatCompletion,
summaryeli15: chatCompletionEli15,
title: summary.title,
link: summary.link,
} as SummaryResults;
} as SummaryResults
} catch (err: any) {
console.error(`Summarization failed for ${summary.title} \n`);
console.log(err.response.data);
console.error(`Summarization failed for ${summary.title} \n`)
console.log(err.response.data)
}
};
const results = (await mapLimit(getScrapedData.results, 3, aiResults)).filter(
(result): result is SummaryResults => result !== undefined
);
await writeSummary({ path: getScrapedData.summaryPath, data: results });
}
const results = (
await mapLimit(getScrapedData.results, 3, aiResults)
).filter((result): result is SummaryResults => result !== undefined)
await writeSummary({
path: getScrapedData.summaryPath,
data: results,
})
},
],
});
})
} catch (err: any) {
throw err.message;
throw err.message
}
};
}

main();
main()
Empty file added ai/src/types/.gitkeep
Empty file.
26 changes: 14 additions & 12 deletions ai/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": ["es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es6"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
Expand All @@ -25,8 +27,8 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "src", /* Specify the root folder within your source files. */
"module": "commonjs" /* Specify what module code is generated. */,
"rootDir": "src" /* Specify the root folder within your source files. */,
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
Expand All @@ -39,12 +41,12 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
"resolveJsonModule": true, /* Enable importing .json files. */
"resolveJsonModule": true /* Enable importing .json files. */,
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

Expand All @@ -55,7 +57,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "build", /* Specify an output folder for all emitted files. */
"outDir": "build" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand All @@ -77,13 +79,13 @@
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
Expand All @@ -104,6 +106,6 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
9 changes: 3 additions & 6 deletions app/[contentType]/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import getJsonFile, { ParsedData } from '@/lib/get-json'

import { ArrowTopRightOnSquareIcon } from '@heroicons/react/24/outline'
import { FC } from 'react'
import Image from 'next/image'
import { Mdx } from '@/components/MDX-components'
import { allDocs } from 'contentlayer/generated'
import socraticDiscussion from 'public/socratic-discussion-default.jpg'

const contentType = 'events'

Expand Down Expand Up @@ -35,6 +33,9 @@ async function getDocFromParams(params: Args) {
const page = async ({ params }: PageProps) => {
const { post, data } = await getDocFromParams(params)

if (params.contentType === contentType && data === undefined)
console.log(`No summary generated for ${params.slug}`)

if (!post) {
return <div>404 sorry you poor bitdev</div>
}
Expand Down Expand Up @@ -95,10 +96,6 @@ const page = async ({ params }: PageProps) => {
<div className="w-full h-8"></div>
)}

{params.contentType === contentType && data === undefined ? (
<div>{`No summary generated for ${params.slug}`}</div>
) : null}

<Mdx
code={post.body.code}
slug={params.slug}
Expand Down
6 changes: 3 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { IBM_Plex_Serif, Inter } from 'next/font/google'
import Header from '@/components/Header/Header'
import type { Metadata } from 'next'
import { ThemeProvider } from './theme-provider'
import { metaupdata } from '@/metaupdata'
import { meetup } from '@/meetup'
import { switchThemeDuration } from '@/lib/utils'

const {
city: { name, position },
description,
} = metaupdata
} = meetup
const inter = Inter({ subsets: ['latin'] })
const ibmPlexSerif = IBM_Plex_Serif({
weight: ['400', '600'],
Expand All @@ -35,7 +35,7 @@ export default function RootLayout({
return (
<html lang="en">
<head>
<meta property="og:image" content={metaupdata.image} />
<meta property="og:image" content={meetup.image} />
<meta property="og:image:type" content="image/jpg" />
<meta property="og:image:width" content="1920" />
<meta property="og:image:height" content="1080" />
Expand Down
4 changes: 2 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Image from 'next/image'
import Link from 'next/link'
import MeetupName from '@/components/MeetupName'
import PostPreview from '@/components/PostPreview'
import { metaupdata } from '@/metaupdata'
import { meetup } from '@/meetup'

export default function Home({}) {
const eventsContentData = getSortedMarkdownContent(ContentType.Events)
Expand All @@ -23,7 +23,7 @@ export default function Home({}) {
<div className="border-b-gray-300 border-b py-10 md:py-20 flex flex-col gap-4 md:gap-10">
<div className="w-40 h-40 md:w-[200px] md:h-[200px] rounded-full overflow-hidden">
<Image
src={metaupdata.image}
src={meetup.image}
alt=""
width="400"
height="200"
Expand Down
4 changes: 2 additions & 2 deletions components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './Header.css'
import MeetupName from '../MeetupName'
import { ThemeSwitcher } from '../ThemeSwitcher'
import { metaupdata } from '@/metaupdata'
import { meetup } from '@/meetup'

const Header = () => {
return (
Expand All @@ -13,7 +13,7 @@ const Header = () => {
</h1>
<nav>
<ul className="flex flex-row gap-4 font-semibold items-center">
{metaupdata.mainNav.map((item) => (
{meetup.mainNav.map((item) => (
<li key={item.text} className="">
<a href={item.link} className="no-underline">
{item.text}
Expand Down
4 changes: 2 additions & 2 deletions components/MDX-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function Mdx({ code, slug, jsonData, page = false }: MdxProps) {
children?: any
'data-no-summary'?: string
}) => {
if (noSummary || page) {
if (noSummary || jsonData === undefined || page) {
return (
<a
className={cn(
Expand Down Expand Up @@ -71,7 +71,7 @@ export function Mdx({ code, slug, jsonData, page = false }: MdxProps) {
),
p: ({ className, ...props }: { className?: any }) => (
<p
className={cn('leading-7 [&:not(:first-child)]:mt-6', className)}
className={cn('leading-7 [&:not(:first-child)]:my-6', className)}
{...props}
/>
),
Expand Down
4 changes: 2 additions & 2 deletions components/MeetupName.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { metaupdata } from '@/metaupdata'
import { meetup } from '@/meetup'

const {
city: { name, position },
} = metaupdata
} = meetup

export default function MeetupName() {
return (
Expand Down
1 change: 0 additions & 1 deletion components/SummaryLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type Props = {
}

export default function SummaryLink(props: Props) {
// TODO: Fetch the summary from the JSON file corresponding to this link using the props.slug
// TODO: Figure out how to prevent this from being housed in a <p> tag when rendered, I want to use more semantic HTML inside this component

const entry = props.data?.summary.find((item) => item.title == props.title)
Expand Down
35 changes: 0 additions & 35 deletions content/events/2023-08-03.md

This file was deleted.

Loading

0 comments on commit e157796

Please sign in to comment.