Skip to content

Commit

Permalink
Merge pull request #16 from christianbmartinez/tmp
Browse files Browse the repository at this point in the history
Tmp
  • Loading branch information
cbmongithub authored Dec 10, 2023
2 parents 8d9c578 + 4583471 commit e35e7bd
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 200 deletions.
494 changes: 301 additions & 193 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chattr",
"version": "0.4.1",
"description": "A chatgpt chatbot component library for react and nextjs.",
"description": "A chatgpt chatbot component library for nextjs.",
"scripts": {
"build": "rollup -c && npm publish",
"dev": "rollup -c"
Expand All @@ -26,6 +26,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
Expand All @@ -38,6 +39,7 @@
"prettier-plugin-tailwindcss": "^0.5.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"replicate": "^0.24.0",
"rollup": "^4.3.0",
"rollup-plugin-dts": "^6.1.0",
"tailwindcss": "^3.3.6",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import terser from '@rollup/plugin-terser'
import json from '@rollup/plugin-json'
import typescript from '@rollup/plugin-typescript'
import { dts } from 'rollup-plugin-dts'
import packageJson from './package.json' assert { type: 'json' }
Expand All @@ -27,6 +28,7 @@ export default [
}),
resolve(),
commonjs(),
json(),
typescript({
tsconfig: './tsconfig.json',
}),
Expand Down
6 changes: 3 additions & 3 deletions src/components/default/chattr-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export default function ChattrLoader({
<div className='mb-3 flex justify-start'>
<div className='rounded-chattrRoundedMedium bg-chattrPrimary dark:bg-chattrPrimaryDark px-0.5 py-1.5'>
<div className='flex items-center justify-center px-3 py-2'>
<div className='chattrDot animate-chattrLoader'></div>
<div className='chattrDot animation-delay-200 animate-chattrLoader'></div>
<div className='chattrDot animation-delay-400 animate-chattrLoader'></div>
<div className='chattrDotDefault animate-chattrLoader'></div>
<div className='chattrDotDefault animation-delay-200 animate-chattrLoader'></div>
<div className='chattrDotDefault animation-delay-400 animate-chattrLoader'></div>
</div>
</div>
<p className='flex items-center pl-2 text-sm font-semibold tracking-wide text-zinc-900 dark:text-zinc-100'>
Expand Down
6 changes: 3 additions & 3 deletions src/components/minimalist/chattr-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export default function ChattrLoader() {
<div className='mb-3 flex justify-end'>
<div className='rounded-chattrRoundedLarge bg-chattrBackgroundMuted dark:bg-chattrGrayDark inline-flex px-0.5 py-1.5 shadow'>
<div className='flex items-center justify-center px-3 py-2'>
<div className='chattrDot animate-chattrLoader'></div>
<div className='chattrDot animation-delay-200 animate-chattrLoader'></div>
<div className='chattrDot animation-delay-400 animate-chattrLoader'></div>
<div className='chattrDotMinimalist animate-chattrLoader'></div>
<div className='chattrDotMinimalist animation-delay-200 animate-chattrLoader'></div>
<div className='chattrDotMinimalist animation-delay-400 animate-chattrLoader'></div>
</div>
</div>
</div>
Expand Down
38 changes: 38 additions & 0 deletions src/helpers/create_image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default async function create_image(description: string) {
try {
const payload = {
model: 'dall-e-3',
prompt: description,
n: 1,
size: '1024x1024',
response_format: 'url',
quality: 'hd',
}

const response = await fetch(
'https://api.openai.com/v1/images/generations',
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
},
method: 'POST',
body: JSON.stringify(payload),
}
)

if (!response.ok) {
throw new Error('Image data not available')
}

const image = await response.json()

return {
description: description,
url: `${image.data[0].url}`,
}
} catch (error) {
console.log(error)
throw error
}
}
37 changes: 37 additions & 0 deletions src/helpers/create_video.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Replicate from 'replicate'

export default async function create_video(description: string) {
try {
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
})

const response = await replicate.run(
'anotherjesse/zeroscope-v2-xl:1f0dd155aeff719af56f4a2e516c7f7d4c91a38c7b8e9e81808e7c71bde9b868',
{
input: {
fps: 24,
fast: true,
width: 576,
height: 320,
prompt: description,
num_frames: 24,
guidance_scale: 17.5,
num_inference_steps: 50,
},
}
)

if (!response) {
throw new Error('Video data not available')
}

return {
description: description,
url: response,
}
} catch (error) {
console.log(error)
throw error
}
}
32 changes: 32 additions & 0 deletions src/helpers/get_current_weather.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default async function get_current_weather(
zipcode: string,
state: string
) {
try {
const response = await fetch(
`http://api.openweathermap.org/data/2.5/weather?zip=${zipcode}&appid=${process.env.WEATHER_APP_ID}&units=imperial`
)

if (!response.ok) {
throw new Error('Weather data not available')
}
const city = await response.json()

const celcius = ((city.main.temp - 32) * 5) / 9

return {
temperature: `${city.main.temp}°F`,
celcius: `${Math.round(celcius * 100) / 100}°C`,
location: `${city.name}`,
url: `https://openweathermap.org/img/wn/${city.weather[0].icon}@2x.png`,
description: `${city.weather[0].description}`,
humidity: `${city.main.humidity}%`,
wind: `${city.wind.speed}m/h`,
clouds: `${city.clouds.all}%`,
state: state,
}
} catch (error) {
console.log(error)
throw error
}
}
3 changes: 3 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as create_image } from './create_image'
export { default as create_video } from './create_video'
export { default as get_current_weather } from './get_current_weather'
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
*/

export * from './components'
export * from './helpers'
export * from './hooks'
export * from './types'

0 comments on commit e35e7bd

Please sign in to comment.