• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Full stack voice chatbot

🦭 Gdańsk AI 🦭

Gdańsk AI is a full stack AI voice chatbot (speech-to-text, LLM, text-to-speech) with integrations to Auth0, OpenAI, Google Cloud API and Stripe - Web App, API and AI

Gdańsk AI

Web API

It uses Stripe to provide payments infrastructure, so users can buy bibs - the API tokens. Auth0 is used to provide authentication and authorization. You can use them for free - Auth0 has a free tier up to 7000 users per month. Stripe only charges fees from purchases, so you have no ongoing costs from any of them.

If you want to use these services, you have to set up your Stripe and Auth0 accounts and put API keys into .env in web-api/ directory.

Node.js, TypeScript and Express are used here

.env

.env_example shows which values you have to set

CHATBOT_API_KEY={whatever you decide; this value is reused among ai-api, web-api and web in this project}
OPEN_AI_API_KEY={go to platform.openai.com, generate and copy-paste api key here}
# Google Cloud API
type=service_account
project_id={project id}
private_key_id=
private_key={multiline private key with structure like this:-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n}
client_email={project name}@{project id}.iam.gserviceaccount.com
client_id=
auth_uri=https://accounts.google.com/o/oauth2/auth
token_uri=https://oauth2.googleapis.com/token
auth_provider_x509_cert_url=https://www.googleapis.com/oauth2/v1/certs
client_x509_cert_url=https://www.googleapis.com/robot/v1/metadata/x509/{project-name}%40{project-id}.iam.gserviceaccount.com
universe_domain=googleapis.com

# Stripe
STRIPE_SECRET_KEY={sk_...}
STRIPE_PUBLISHABLE_KEY={pk_...}
TOKENS_PRICE_ID={price_some characters here - you need to create a price in Stripe for tokens first and then copy-paste it here}
# TOKENS_PER_TRANSACTION defines how many interactions user can make with AI per single bibs purchase
TOKENS_PER_TRANSACTION=5

# Auth0
AUTH0_ISSUER_BASE_URL='https://{tenant-name}.us.auth0.com'
AUTH0_DOMAIN='{tenant-name}.us.auth0.com'
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_AUDIENCE="https://{tenant-name}.us.auth0.com/api/v2/"
AUTH0_SCOPE="openid profile email offline_access"
CLIENT_URL={url pointing to where web is deployed}
AI_API_URL={url pointing to where ai api is deployed}

Run

  • go to web-api directory
  • npm install or npm ci
  • npm run build
  • npm run start or npm run dev to run it with hot-reload

Web

It works in Google Chrome currently. You can press Gdańsk AI logo to record audio, then press it once again to send it to Web API. After a successful response, a received audio is played to you.

Next.js used here with Vercel's template

.env

.env_example shows which values you have to set

CHATBOT_API_KEY={whatever you decide; this value is reused among ai-api, web-api and web in this project}
CHATBOT_API_URL={url to where api is deployed}


NEXT_PUBLIC_API_URL={url pointing to where api is deployed}
API_URL={url to where api is deployed}

# Auth0
NEXT_PUBLIC_AUTH0_ISSUER_BASE_URL="https://{tenant-name}.us.auth0.com"
NEXT_PUBLIC_AUTH0_CLIENT_ID=
AUTH0_SECRET=
AUTH0_BASE_URL={url pointing to where web is deployed}
AUTH0_ISSUER_BASE_URL='https://{tenant-name}.us.auth0.com'
AUTH0_DOMAIN='{tenant-name}.us.auth0.com'
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_AUDIENCE="https://{tenant-name}.us.auth0.com/api/v2/"
AUTH0_SCOPE="openid profile email offline_access"
CLIENT_URL={url pointing to where web is deployed}

Run

  • go to web directory
  • npm install or npm ci
  • npm run build
  • install Stripe cli
  • stripe listen --forward-to http://localhost:3000/webhook (adjust the port from 3000 if you've changed it) - we need this to invoke /webhook endpoint on bibs purchases
  • npm run start

Troubleshooting

  • you might neet to remove/comment out screen_hint: "signup", in signup.ts

AI API

OpenAI and Google Cloud API are used here to provide speech-to-text (Whisper-1), LLM (gpt-3.5-turbo) and text-to-speech (Google Cloud TextToSpeechClient) services.

Python and FastAPI here

.env

.env_example shows which values you have to set

CHATBOT_API_KEY={whatever you decide; this value is reused among ai-api, web-api and web in this project}
OPEN_AI_API_KEY={go to platform.openai.com, generate and copy-paste api key here}
# Google Cloud API start
type=service_account
project_id={project id}
private_key_id=
private_key={multiline private key with structure like this:-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----\n}
client_email={project name}@{project id}.iam.gserviceaccount.com
client_id=
auth_uri=https://accounts.google.com/o/oauth2/auth
token_uri=https://oauth2.googleapis.com/token
auth_provider_x509_cert_url=https://www.googleapis.com/oauth2/v1/certs
client_x509_cert_url=https://www.googleapis.com/robot/v1/metadata/x509/{project-name}%40{project-id}.iam.gserviceaccount.com
universe_domain=googleapis.com
PORT=9000

Run

  • go to ai-api directory
  • python3 app.py, by default it runs on port 9000

Auth0 setup

Create an account, then a new tenant. You will need to set up:

  • Applications

  • APIs

    • Auth0 Management API (System API):
      • Machine To Machine Applications:
        • add both applications listed above and make sure the switch Authorized to the right is turned on for both
        • add all permissions for both of them, by clicking on dropdown to the right and selecting All permissions and saving

Stripe setup

Create an account, turn the test mode unless you want to run it on production and process real payments, go to Developers tab, then API keys. This is where you can find values for STRIPE_SECRET_KEY and STRIPE_PUBLISHABLE_KEY. Now go to Products tab and Add product which represents a single purchase of bibs (one bib - one interaction with AI for a user). Once you create it, copy priceId and put it into .env as TOKENS_PRICE_ID.

OpenAI setup

Create an account, go to platform.openai.com, generate API key, use it in .env files

Google Cloud API setup

Create an account, go to IAM & Admin, then Service Accounts and create a project - you need id of the project to put into .env files. Then you need to generate json with credentials and extract the values from the file to your .env files. Go to Create access credentials page (you can use search engine to find a link). Then Keys -> Add Key -> Create new key -> JSON -> Create. You should get credentials.json with all values you need to .env. Finally, you need to enable text to speech API service and you're ready

Acknowledgements

Thanks to Jeff McJunkin for improving the README by going through the config process from the scratch and filling the gaps in the docs

License

GNU GPL v2

Author

Made in Gdańsk, Poland in 2023 by Jędrzej Paweł Maczan

More Repositories

1

bulma-helpers

🍥 Library with Functional / Atomic CSS classes for Bulma framework
CSS
277
star
2

basic-vue-chat

💬 Easy to use Vue chat
Vue
73
star
3

pff

Examine your Internet connection quality and status in terminal
Rust
16
star
4

text-to-ml

Homebrew AutoML using natural text. Like HuggingGPT + LangChain + type inference
Python
12
star
5

asr-dysarthria

Research on Automatic Speech Recognition for dysarthric speech
Jupyter Notebook
6
star
6

0x6b73746b

🐱 Tree-Walk Interpreter
Rust
4
star
7

spellbook

🪄 Shell and Powershell scripts registry
TypeScript
3
star
8

tinyconv

🌸 Image processing with kernel and convolution
Python
3
star
9

xiexie

🎐 Static site generator
Rust
2
star
10

bpe-tokenizer

Byte-Pair Encoding tokenizer for training large language models on huge datasets
Python
2
star
11

openai-polling

Polling library for OpenAI Threads API
TypeScript
2
star
12

funkcja

🖇️ Log function body and name to browser's console
TypeScript
1
star
13

repeat-sh

🕰️ Repeat any shell command with interval
Shell
1
star
14

mac-addresses-scanner

🔦 Find MAC addresses of devices connected to a network
Python
1
star
15

mlp-classifier

🤗 Multi-Layer Perceptron artificial neural network
Python
1
star
16

deep-learning-pytorch

Deep Learning architectures implemented in PyTorch Lightning
Python
1
star
17

csv-to-ml

🧌 Upload a CSV file and get an ML model
TypeScript
1
star
18

bpe.c

Byte-Pair Encoding tokenizer for training large language models on huge datasets. I don't know C, so most of the code comes from AI :D I hope to learn by rewriting it and making changes, fixes etc
C
1
star