Skip to content

Commit

Permalink
The application is able to use external element to return AI tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitardanailov committed Jul 21, 2024
1 parent 510799f commit 356802b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Label from '@/components/SimpleLabel'
import TopicAnalysisTable from '@/components/TopicAnalysisTable'

import {topicAnalysis} from './db'

const Body = () => {
const listStyle = 'list-disc mx-6 mt-0 mb-5'
Expand Down Expand Up @@ -83,6 +86,8 @@ const Body = () => {
performance benefits.
</li>
</ul>

<TopicAnalysisTable topicAnalysis={topicAnalysis} />
</>
)
}
Expand Down
10 changes: 3 additions & 7 deletions apps/website/src/app/articles/2024/06/26/[slug]/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@

import {Slogan} from '@/styled-components'

import TopicAnalysisTable from '@/components/TopicAnalysisTable'
import Body from './Body'
import Article from './Article'

// import Mermaid from './Mermaid'

import {slogan} from './seo'
import {topicAnalysis} from './db'

import Tags from './Tags'

// import diagram from './diagram'

const Content = () => {
return (
<article>
<Tags component="test" />
<Slogan>{slogan}</Slogan>

<Body />
<Article />

<TopicAnalysisTable topicAnalysis={topicAnalysis} />
<Tags component={Article} />
</article>
)
}
Expand Down
14 changes: 6 additions & 8 deletions apps/website/src/app/articles/2024/06/26/[slug]/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import {FC, useEffect, useState} from 'react'
import {createGoogleGenerativeAI} from '@ai-sdk/google'
import {generateText} from 'ai'

import Body from './Body'

export interface Props {
component: string
component: () => JSX.Element
}

const Tags: FC<Props> = ({component}) => {
const [aiTags, setPromtPresponse] = useState<Array<string>>([])

console.log('Body', Body)

useEffect(() => {
if (aiTags.length > 0) return

Expand All @@ -26,15 +22,17 @@ const Tags: FC<Props> = ({component}) => {

generateText({
model,
prompt: `From the following react component: ${Body} please create five tags. Tags should be return as a plain text seperated with with comma`,
prompt: `From the following react component: ${component} please create five tags. Tags should be return as a plain text seperated with with comma`,
}).then(response => {
const tags = response.text.split(',')

setPromtPresponse(tags)
})
}, [aiTags])
}, [aiTags, component])

if (aiTags.length === 0) return

return <>{aiTags.join(',')}</>
return <div className="mt-2 mb-2">Tags: {aiTags.join(',')}</div>
}

export default Tags

0 comments on commit 356802b

Please sign in to comment.