Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Martinez committed Dec 12, 2023
0 parents commit 7d9567f
Show file tree
Hide file tree
Showing 66 changed files with 7,209 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .env.development.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OPENAI_API_KEY='YOUR_OPENAI_API_KEY'
#https://platform.openai.com/api-keys
WEATHER_APP_ID='YOUR_OPENWEATHERMAPS_API_KEY'
#https://home.openweathermap.org/api_keys
# Sign up and subscribe to the Current weather and forecast free plan
REPLICATE_API_TOKEN='YOUR_REPLICATE_TOKEN'
#https://replicate.com/account/api-tokens
# Login with github and create a token

# ! IMPORTANT !
# Remove the hash tag in front of #.env.* in your .gitignore file once you are done adding your keys here.
# Do not push your keys to GitHub!



15 changes: 15 additions & 0 deletions .env.production.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OPENAI_API_KEY='YOUR_OPENAI_API_KEY'
#https://platform.openai.com/api-keys
WEATHER_APP_ID='YOUR_OPENWEATHERMAPS_API_KEY'
#https://home.openweathermap.org/api_keys
# Sign up and subscribe to the Current weather and forecast free plan
REPLICATE_API_TOKEN='YOUR_REPLICATE_TOKEN'
#https://replicate.com/account/api-tokens
# Login with github and create a token

# ! IMPORTANT !
# Remove the hash tag in front of #.env.* in your .gitignore file once you are done adding your keys here.
# Do not push your keys to GitHub!



3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals"]
}
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/package-lock.json
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files
#.env.*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
14 changes: 14 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"arrowParens": "avoid",
"bracketSameLine": true,
"bracketSpacing": true,
"printWidth": 80,
"semi": false,
"singleAttributePerLine": true,
"singleQuote": true,
"jsxSingleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"plugins": ["prettier-plugin-tailwindcss"]
}
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
![alt text](https://github.com/christianbmartinez/create-chattr-app/blob/main/public/createchattrapp.jpg)

# create-chattr-app

A next js chattr boilerplate. Built with Nextjs, Chattr, Tailwindcss, OpenAI, and Typescript.

- Ships with chattr's default theme, and chattr's minimalist theme (originally styled by [shadcn](https://ui.shadcn.com/themes)) allowing for full customization over every component chattr offers.
- Full theme support for light/dark mode via next themes.
- Minimalist landing page example that has the minimalist chattrbot, menu, and navigation installed.
- Two routes are setup, one for basic chatgpt functionality and the other for chat gpt and function calling.
- Default theme uses the `api/chatgpt` route, while the minimalist theme uses the `api/function-calling` route as starting examples.

# Installation

```bash
git clone https://github.com/christianbmartinez/create-chattr-app.git
```

# Usage

First, install all dependencies by running:

```bash
npm install
```

Next, you need an `OPENAI_API_KEY`. If you don't have one already, click [here](https://platform.openai.com/api-keys) to get one.

Once you have your key, insert your api key in both `.env.production.local` and `.env.development.local`, along with any other api keys if you plan on using the default function calling features. **In production, remember to copy your api key, to your environment variables section.**

```bash
OPENAI_API_KEY='YOUR_OPENAI_API_KEY'
WEATHER_APP_ID='YOUR_OPENWEATHERMAPS_API_KEY'
#https://home.openweathermap.org/api_keys
# Sign up and subscribe to the Current weather and forecast free plan
REPLICATE_API_TOKEN='YOUR_REPLICATE_TOKEN'
#https://replicate.com/account/api-tokens
# Login with github and create a token
```

Once you have your api keys, create the build:

```bash
npm run build
```

Finally, you can run the application in development mode:

```bash
npm run dev
```

For running the app in production mode, use:

```bash
npm start
```

You can view the app locally at http://localhost:3000/

# License

This project is covered under the [MIT](https://opensource.org/licenses/MIT) license.

# Contributing

Contributing is welcomed! Please submit a pull request.

# Questions

Feel free to [email](mailto:[email protected]?subject=[GitHub]%20Create%20React%20App) me with any questions or view [my github profile](https://github.com/christianbmartinez) to check out my other repos!

# Sponsors

If you like the project and it adds value to you, feel free to [sponsor me](https://github.com/sponsors/christianbmartinez) if you'd like!
78 changes: 78 additions & 0 deletions app/api/chat-gpt/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { NextRequest, NextResponse } from 'next/server'

export async function POST(req: NextRequest) {
try {
const {
prompt,
chattrBotName,
chattrBotHistory,
}: {
prompt: string
chattrBotName: string | number
chattrBotHistory: string
} = await req.json()

const chatHistory = JSON.stringify(chattrBotHistory)

const payload = {
model: 'gpt-4-1106-preview',
messages: [
{
role: 'system',
content: `
You are a chatbot named ${chattrBotName}.
Respond with any information that the user requests.
You can view the entire chat history here, where your role is the assistant, and the users role is user: ${chatHistory}.
This history is helpful if you need to recall any information or understand context from chat.
Use a professional tone in your responses.`,
},
{
role: 'assistant',
content: `Hey! Thanks for visiting. I'm ${chattrBotName}, you can ask me anything!`, // Replace with your own greeting
},
{
role: 'user',
content: prompt,
},
],
temperature: 0.7,
frequency_penalty: 0,
presence_penalty: 0,
max_tokens: 75,
n: 1,
}

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

if (!response.ok) {
return NextResponse.json({
ok: false,
error:
'Looks like something went wrong fetching that answer! Try again later.',
})
}

const completion = await response.json()

return NextResponse.json({
ok: true,
content: { text: completion.choices[0].message.content },
})
} catch (error) {
console.log(error)
return NextResponse.json({
ok: false,
error: 'Looks like something went wrong. Try again later.',
})
}
}
Loading

0 comments on commit 7d9567f

Please sign in to comment.