{"id":20313741,"url":"https://github.com/posthog/max-ai","last_synced_at":"2025-04-11T17:16:28.347Z","repository":{"id":148758614,"uuid":"620475224","full_name":"PostHog/max-ai","owner":"PostHog","description":"Max bot deploy","archived":false,"fork":false,"pushed_at":"2023-10-16T16:57:59.000Z","size":978,"stargazers_count":63,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T13:11:24.022Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PostHog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-28T18:54:43.000Z","updated_at":"2025-03-19T01:04:43.000Z","dependencies_parsed_at":"2023-10-17T01:23:22.687Z","dependency_job_id":null,"html_url":"https://github.com/PostHog/max-ai","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fmax-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fmax-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fmax-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PostHog%2Fmax-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PostHog","download_url":"https://codeload.github.com/PostHog/max-ai/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248447598,"owners_count":21105140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T18:12:33.843Z","updated_at":"2025-04-11T17:16:28.323Z","avatar_url":"https://github.com/PostHog.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MaxAI \n\u003cimg src='./image/MaxAI.png' alt='MaxAI' width=250 height=250 /\u003e\n\nMaxAI is our `trusty PostHog support AI` deployed on our Slack, app, and website.\n\nMaxAI was born in Aruba at a PostHog team offsite for a hackathon on a warm spring day in 2023.\n\n## How it works\n\nHow Max works is surprisingly simple.\n\n### Tooling\n- [Weaviate](https://weaviate.io/) - Vector database that allows us to pull relevant context to embed in our prompts to GPT\n- [Haystack](https://haystack.deepset.ai/) by deepset - Allows us to hook together pipelines of these tools to service user prompts\n- [OpenAI](https://platform.openai.com/docs/guides/chat/introduction) - Provides us the base language model in `gpt-3.5-turbo` that we augment to create our AI\n\n### Embedding time\n\n```mermaid\nflowchart TD\n    A[Github]\n    B[Docs]\n    C[Squeak]\n    A --\u003e|Calculate Embed Vectors|D[Weaviate]\n    B --\u003e|Calculate Embed Vectors|D\n    C --\u003e|Calculate Embed Vectors|D\n```\n\n#### Embedding Docs\n\n- Grab and parse all of the markdown from our docs and website\n- Use [OpenAI Embedings](https://platform.openai.com/docs/guides/embeddings) to create a vector representation of each markdown section.\n- Use [Weaviate](https://weaviate.io/) Vector database to store the vector representations of each markdown section.\n\n#### Embedding Github content\n\n- Grab and parse all Github Issues\n- Use [OpenAI Embedings](https://platform.openai.com/docs/guides/embeddings) to create a vector representation of each description and comment section.\n- Use [Weaviate](https://weaviate.io/) Vector database to store the vector representations of each description and comment section.\n\n\n#### Embedding [Squeak](https://squeak.posthog.com/) content\n\n- Grab and parse all Squeak Questions \n- Use [OpenAI Embedings](https://platform.openai.com/docs/guides/embeddings) to create a vector representation of each question thread.\n- Use [Weaviate](https://weaviate.io/) Vector database to store the vector representations of each question thread.\n\n### Inference time\n\n```mermaid\nflowchart TD\n    A[User Question] --\u003e|Embed| I(Question Vector)\n    I --\u003e|Query Weaviate|J[Most Similar Docs]\n    J --\u003e|Collect Prompt Params| C{Prompt Context}\n    C --\u003e D[Limitations]\n    C --\u003e E[Personality]\n    C --\u003e F[Context Docs]\n    F --\u003e G[String Prompt]\n    E --\u003e G\n    D --\u003e G\n    G --\u003e|Query OpenAI|H[AI Response]\n```\n\n- Take the conversation context from thread that Max is in including the most recent request.\n- Query [Weaviate](https://weaviate.io/) Vector database for the most similar markdown section.\n- Build a prompt that we will use for [chatgpt-3.5-turbo](https://platform.openai.com/docs/guides/chat). The prompt is engineered to build Max's personality and add a few guardrails for how Max should respond as well as adding a bit of personality. To do this we:\n  - Ask Max to only reference PostHog products if possible\n  - Build up Max's personality by informing that Max is the trusty PostHog support AI\n  - Bake in context that is useful for some conversations with max\n    - Pagerduty current oncalls\n    - Places to go if Max does not have the answer\n  - Most importantly - we embed the markdown section that we found in the prompt so that Max can respond with a relevant answer to the question.\n- Use [chatgpt-3.5-turbo](https://platform.openai.com/docs/guides/chat) to generate a response to the prompt.\n- Finally we send these messages to wherever Max is having a conversation. \n\nIt's important to note that we are building these pipelines with [Haystack](https://haystack.deepset.ai/) by deepset. This coordinates the steps of inferencing listed above. It's amazing.\n\n## Developers guide\n\n### Quickstart\n\n#### Configure `.env` file\nThis is used to set defaults for local development. \n```toml\nSLACK_BOT_TOKEN=\u003cyour slack bot token\u003e\nSLACK_SIGNING_SECRET=\u003cyour slack signing secret\u003e\nOPENAI_TOKEN=\u003cyour openai token\u003e\nPOSTHOG_API_KEY=\u003cyour posthog api key\u003e\nPOSTHOG_HOST=https://null.posthog.com\nPD_API_KEY=\u003cyour pagerduty api key\u003e\nWEAVIATE_HOST=http://127.0.0.1\nWEAVIATE_PORT=8080\n```\n\n#### Create Virtual Environment\n```bash\npython3.10 -m venv venv\nsource venv/bin/activate\n```\n\n#### Install dependencies\n```bash\npip install -r requirements-dev.txt\npip install -r requirements.txt\n```\n\n#### Start Weaviate\n```bash\ndocker compose up weaviate\n```\n\n#### Seed Weaviate\n```bash\npython seed.py\n```\n\n#### Start MaxAI\n```bash\nuvicorn main:app --reload\n```\n\n#### Run a test chat\n```bash\ncurl --location '127.0.0.1:8000/chat' \\\n--header 'Content-Type: application/json' \\\n--data '[\n    {\n        \"role\": \"assistant\",\n        \"content\": \"Hey! I'\\''m Max AI, your helpful hedgehog assistant.\"\n    },\n    {\n        \"role\": \"user\",\n        \"content\": \"Does PostHog use clickhouse under the hood??\"\n    }\n]'\n```\n\n## 🕯️ A poem from Max to his evil twin Hoge 📖\n```\nAh, hoge! Sweet word upon my tongue,\nSo blissful, yet so quick to come undone.\nA fleeting joy, that doth my heart entice,\nOh how I long to see your data slice!\nIn PostHog's code, thy value doth reside,\nA beacon that ne'er shall falter nor hide.\nThou art a treasure, O hoge divine,\nThe secret sauce to make my metrics shine.\nThough you may seem but a lowly label,\nThou bringeth\n```\n\n## Disclaimer! \n\n**Max may display inaccurate or offensive information that doesn’t represent PostHog's views.**\n\nThis is the case with LLMs in the current state. We try our best here to have a system prompt that keeps Max on topic.\nFeel free to question and chat with Max but do keep in mind that this is experimental.\n\nA few things we've seen ourselves in testing:\n- Totally believable but totally incorrect URLs\n- Often times entertaining hallucinations about our products\n- Hallucinations about the history and founding of PostHog\n- Just plain wrong responses\n\nIf you do see something concerning @metion someone from PostHog and we'll catalogue it.\nWe are working on tooling to do this in an automated fashion so stay tuned!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fmax-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthog%2Fmax-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthog%2Fmax-ai/lists"}