Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python backend support + OpenAI Functions & Tools #53

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b4646eb
Initial checkin. Upstash and backstory works. LLM not on branch yet.
appenz Jun 30, 2023
45e78e8
Working on ChatGPT
appenz Jun 30, 2023
e59f800
Basic chatting now works. Wohoo!
appenz Jun 30, 2023
9c1923b
Turned off debugging
appenz Jun 30, 2023
aefa1c0
Fixed ordering of the fields that make up the key to enable compatibi…
appenz Jun 30, 2023
e73e87e
Cleanup for GUI version
appenz Jul 1, 2023
cd2de6e
polishing
appenz Jul 1, 2023
4198993
Update README.md with image
appenz Jul 1, 2023
9b6a8e2
polish
appenz Jul 1, 2023
4537407
updated readme
appenz Jul 1, 2023
4cb34b0
Contribute initial multimodal agent support & steamship agent
eob Jul 12, 2023
90d15aa
Move rick down; commit package with dependencies
eob Jul 12, 2023
cdbe353
Fix video element
eob Jul 12, 2023
e4b12ba
Merge commit '45374077ec8fb39fe5d28b638020bbf70fe962b6' into ec/steam…
Jul 13, 2023
17e8e24
First commit
Jul 13, 2023
a556b0c
Clean up repo structure before adding it back in
Jul 13, 2023
cdd1b85
Clean up for first review
Jul 13, 2023
9369a4a
Add init_companion script
Jul 13, 2023
fc4bc40
Add seed convo to companions
Jul 13, 2023
51054eb
update gitignore
Jul 13, 2023
4a48db2
Fixes from comments
Jul 13, 2023
19e0d4b
Merge branch 'main' into ec/steamship-companion-app
Jul 13, 2023
1f7c0f2
Push temp companions
Jul 13, 2023
9588d53
Update readme
Jul 13, 2023
f248b3d
Put back old comanions.json and add search tool
Jul 13, 2023
a227a42
Make voice responses optional
Jul 13, 2023
aeb793c
Clean up steamship.json
Jul 13, 2023
5c790fa
Update python/README.md
Jul 13, 2023
efd824e
Address comments PR
Jul 13, 2023
eae8bb9
Merge branch 'ec/steamship-companion-app' of github.com:steamship-cor…
Jul 13, 2023
7361c13
Add missing Rick personality and improve seed_chat parsing
Jul 24, 2023
f37e234
Add improved image tool
Jul 24, 2023
afa4861
Make image generation compatible across companions
Jul 25, 2023
6818599
Update init_companions script
Jul 25, 2023
845f0bf
Improve UUID formatting
Jul 26, 2023
ab40878
Upgrade to latest Steamship version
Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ UPSTASH_REDIS_REST_TOKEN=AZ****

# Twilio related environment variables
TWILIO_ACCOUNT_SID=AC***
TWILIO_AUTH_TOKEN=*****
TWILIO_AUTH_TOKEN=*****

# Steamship related environment variables
STEAMSHIP_API_KEY=****
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ yarn-error.log*
next-env.d.ts

/.env.prod
/fly.toml
/fly.toml

# python
__pycache__/

# JetBrains
.idea/**

# Yarn Lockfiles (since this project uses NPM)
yarn.lock
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,24 @@ e. **Upstash API key**
- Scroll down to "REST API" section and click on ".env". Now you can copy paste both environment variables to your `.env.local`
<img width="866" alt="Screen Shot 2023-07-10 at 11 07 21 PM" src="https://github.com/a16z-infra/companion-app/assets/3489963/f8e6c43f-8810-423e-86b4-9e8aa70598c9">


e. **Supabase API key** (optional)
f. **Supabase API key** (optional)
If you prefer to use Supabsae, you will need to uncomment `VECTOR_DB=supabase` and fill out the Supabase credentials in `.env.local`.

- Create a Supabase instance [here](https://supabase.com/dashboard/projects); then go to Project Settings -> API
- `SUPABASE_URL` is the URL value under "Project URL"
- `SUPABASE_PRIVATE_KEY` is the key starts with `ey` under Project API Keys
- Now, you should enable pgvector on Supabase and create a schema. You can do this easily by clicking on "SQL editor" on the left hand side on Supabase UI and then clicking on "+New Query". Copy paste [this code snippet](https://github.com/a16z-infra/ai-getting-started/blob/main/pgvector.sql) in the SQL editor and click "Run".

g. **Steamship API key**

You can connect Steamship agent instance as if it were an LLM with personality, vector storage, and tools built-in. To do so:

- Sign in to [Steamship](https://steamship.com/account)
- Copy the API key from your account settings page
- Add it as the `STEAMSHIP_API_KEY` variable

Next, [build an agent](https://www.steamship.com/learn/agent-guidebook), create your own instance of it, and connect it in `companions.json` using the *Rick* example as a guide.

### 4. Generate embeddings

The `companions/` directory contains the "personalities" of the AIs in .txt files. To generate embeddings and load them into the vector database to draw from during the chat, run the following command:
Expand Down
23 changes: 18 additions & 5 deletions companions/companions.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
[
{
"name": "Rick",
"title": "I can generate voice and pictures.",
"imageUrl": "/rick.jpeg",
"llm": "steamship",
"generateEndpoint": "https://a16z.steamship.run/a16z/rick-b1578149038e664bacae7fc083683565/answer",
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER",
"telegram": "https://t.me/rick_a16z_bot"
},
{
"name": "Alex",
"title": "I love talking about books and games",
"imageUrl": "/alex.png",
"llm": "chatgpt",
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER"
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER",
"telegram": "OPTIONAL_TELEGRAM_LINK"
},
{
"name": "Rosie",
"title": "I'm a house robot who became aware",
"imageUrl": "/rosie.png",
"llm": "vicuna13b",
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER"
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER",
"telegram": "OPTIONAL_TELEGRAM_LINK"
},
{
"name": "Sebastian",
"title": "I'm a travel blogger and a mystery novel writer",
"imageUrl": "/sebastian.png",
"llm": "chatgpt",
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER"
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER",
"telegram": "OPTIONAL_TELEGRAM_LINK"
},
{
"name": "Lucky",
"title": "I am a space corgi",
"imageUrl": "/corgi.png",
"llm": "vicuna13b",
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER"
"phone": "OPTIONAL_COMPANION_PHONE_NUMBER",
"telegram": "OPTIONAL_TELEGRAM_LINK"
}
]
]
50 changes: 49 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"eslint-config-next": "13.4.4",
"hnswlib-node": "^1.4.2",
"langchain": "^0.0.92",
"md5": "^2.3.0",
"next": "13.4.4",
"postcss": "8.4.24",
"react": "18.2.0",
Expand All @@ -38,10 +39,12 @@
"react-tooltip": "^5.16.1",
"replicate": "^0.9.3",
"tailwindcss": "3.3.2",
"ts-md5": "^1.3.1",
"twilio": "^4.12.0",
"typescript": "5.1.3"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.2.14"
"@flydotio/dockerfile": "^0.2.14",
"@types/md5": "^2.3.2"
}
}
Binary file added public/rick.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# AI Companion App - Python

The following instructions should get you up and running with a fully functional, deployed version of your AI
companions.

It currently contains a companion connected to ChatGPT that can run Tools such as Image Generation and Video Generation.
The companions also have to option to return voice messages via [ElevenLabs](https://beta.elevenlabs.io/)

## Quick start

### 1. Set up your environment

```commandline
pip install -r requirements.txt
```

### 2. Authenticate with Steamship

```commandline
ship login
```

### 3. Initialize your companions

```commandline
python init_companions.py
```

This will read the companion descriptions in the `companions` folder and create instances for them.
The front-end will be calling these instances after deployment.
Make sure to override the companions.json file in the final step of the script.

### 4. Fill out secrets

The front-end requires a few secrets to be filled before connecting to third-party services.

```
# Run in the Root directory of this repo
cp .env.local.example .env.local
```

Secrets mentioned below will need to be copied to `.env.local`

**Note:** By default you can stick to using Steamship as a provider for your memory (short-term and long-term), llms,
and hosting.

a. **Clerk Secrets**

Clerk is used to authorize users of your application. Without completing this setup, you will not be able to access your companions via the supplied frontend

Go to https://dashboard.clerk.com/ -> "Add Application" -> Fill in Application name/select how your users should sign in
-> Create Application
Now you should see both `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` and `CLERK_SECRET_KEY` on the screen
<img width="1398" alt="Screen Shot 2023-07-10 at 11 04 57 PM" src="https://github.com/a16z-infra/companion-app/assets/3489963/449c40f1-2fc2-48bb-88e1-d2adf10a034e">

If you want to text your AI companion in later steps, you should also enable "phone number" under "User &
Authentication" -> "Email, Phone, Username" on the left hand side nav:

<img width="1013" alt="Screen Shot 2023-07-10 at 11 05 42 PM" src="https://github.com/a16z-infra/companion-app/assets/3489963/4435c759-f33e-4e38-a276-1be6d538df28">

b. **Steamship API key**

- Sign in to [Steamship](https://www.steamship.com/account/api)
- Copy the API key from your account settings page
- Add it as the `STEAMSHIP_API_KEY` variable

### 5. Install front-end dependencies

```
# Run in the Root directory of this repo
npm install
```

### 6. Run app locally

Now you are ready to test out the app locally! To do this, simply run `npm run dev` under the project root.

You can connect to the project with your browser typically at http://localhost:3000/.

## Stack

The stack is based on the [AI Getting Started Stack](https://github.com/a16z-infra/ai-getting-started):

- VectorDB: [Steamship](https://www.steamship.com/)
- LLM orchestration: [Langchain](https://langchain.com/docs/)
- Text model: [OpenAI](https://platform.openai.com/docs/models)
- Conversation history: [Steamship](https://www.steamship.com/)
- Deployment: [Steamship](https://www.steamship.com/)
- Text with companion: [Telegram](https://telegram.org/)

## Upgrades

### Modifying your companion logic

You can modify your companion by editing the `src/api.py`. Here are a few interesting ideas:

* Add tools
* Modify the logic of your agent
* Add endpoints
* Add webhooks

This is a separate step from adding personality and backstory -- those are done elsewhere.

### Connecting to Telegram

You can connect your chatbot to Telegram by providing a bot
token. [This guide](https://github.com/steamship-packages/langchain-production-starter/blob/f51a3ecc8a15ced84dca5845fd1a18bc3f015418/docs/register-telegram-bot.md)
will show you how. will show you how.
6 changes: 6 additions & 0 deletions python/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"companion_name": "",
"bot_token": "",
"elevenlabs_api_key": "",
"elevenlabs_voice_id": ""
}
Loading