-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Martinez
committed
Dec 12, 2023
0 parents
commit 7d9567f
Showing
66 changed files
with
7,209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["next/core-web-vitals"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
[](https://opensource.org/licenses/MIT) | ||
 | ||
|
||
# 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
}) | ||
} | ||
} |
Oops, something went wrong.