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

feat(insights): generate trends using GenAI #24463

Merged
merged 51 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
40450cd
Fix HedgehogBuddy wave animation
Twixes Aug 8, 2024
69b4f96
Add LemonInput large size
Twixes Aug 8, 2024
35d8601
Improve CommandBar input sizing
Twixes Aug 8, 2024
c6deb45
Add new Max scene
Twixes Aug 8, 2024
77671a0
Add mock chat event stream endpoint
Twixes Aug 8, 2024
ffbcb82
feat: assistant
skoob13 Aug 8, 2024
878e2d2
UI 0.2
Twixes Aug 8, 2024
6a05cba
feat: assistant
skoob13 Aug 9, 2024
1d45bca
Merge branch 'hedgehogslity' of github.com:PostHog/posthog into hedge…
skoob13 Aug 9, 2024
fbd036c
fix: field
skoob13 Aug 9, 2024
2a20f06
fix: query param
skoob13 Aug 9, 2024
7a72c12
feat: insights
skoob13 Aug 9, 2024
1b78624
Make popover transition slower
Twixes Aug 9, 2024
3070783
Clippify Max
Twixes Aug 9, 2024
10926b6
feat: query btn
skoob13 Aug 9, 2024
573376c
Merge branch 'hedgehogslity' of github.com:PostHog/posthog into hedge…
skoob13 Aug 9, 2024
584f529
Add loading state
Twixes Aug 9, 2024
f06733c
Merge branch 'master' of github.com:PostHog/posthog into hedgehogslity
skoob13 Aug 19, 2024
90d435d
Revert "Make popover transition slower"
Twixes Aug 21, 2024
ec3bcb0
Revert "Clippify Max"
Twixes Aug 21, 2024
9fa2db5
Flag the new scene
Twixes Aug 21, 2024
5e16bab
Merge branch 'hedgehogslity' of github.com:PostHog/posthog into hedge…
skoob13 Aug 26, 2024
f56a1ec
Merge branch 'master' of github.com:PostHog/posthog into hedgehogslity
skoob13 Aug 26, 2024
cc7ca4e
chore: re-organize prompts
skoob13 Aug 27, 2024
8980800
feat: generate schema
skoob13 Aug 28, 2024
80053e4
Merge branch 'master' of github.com:PostHog/posthog into hedgehogslity
skoob13 Aug 28, 2024
a18e7fd
fix: schema of properties
skoob13 Aug 28, 2024
c913cb9
feat: groups prompt
skoob13 Aug 28, 2024
74fef4f
feat: cohorts
skoob13 Aug 28, 2024
eae8e06
feat: langchain experiments
skoob13 Aug 29, 2024
7251877
feat: streaming
skoob13 Aug 30, 2024
cd3ed63
chore: remove hardcoded data
skoob13 Aug 30, 2024
8a96138
Merge branch 'master' of github.com:PostHog/posthog into hedgehogslity
skoob13 Aug 30, 2024
a6e5bf4
chore: deps
skoob13 Aug 30, 2024
3b882a5
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 30, 2024
a851239
fix: deps
skoob13 Sep 2, 2024
1b32df5
fix: slightly tweak prompts
skoob13 Sep 2, 2024
44d28f0
fix: improve validation
skoob13 Sep 2, 2024
6e7b85f
feat: max message count
skoob13 Sep 2, 2024
f91c42d
chore: move to ee
skoob13 Sep 2, 2024
a21d845
chore: basic error handling
skoob13 Sep 2, 2024
d7a7ad6
fix: capture schema validation error
skoob13 Sep 2, 2024
9a3f000
Merge branch 'hedgehogslity' of github.com:PostHog/posthog into hedge…
skoob13 Sep 2, 2024
a50ba89
Merge branch 'master' of github.com:PostHog/posthog into hedgehogslity
skoob13 Sep 2, 2024
d96b6b2
Update query snapshots
github-actions[bot] Sep 2, 2024
8abecf6
fix: ci
skoob13 Sep 2, 2024
7c265ff
Merge branch 'hedgehogslity' of github.com:PostHog/posthog into hedge…
skoob13 Sep 2, 2024
c2089a6
fix: styling
skoob13 Sep 2, 2024
7887938
fix: set correct model
skoob13 Sep 2, 2024
5784e83
Update posthog/api/query.py
Twixes Sep 4, 2024
d3cc358
Merge branch 'master' into hedgehogslity
Twixes Sep 4, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/rust-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
- name: Container image digest
id: digest
run: |
echo ${{ steps.docker_build.outputs.digest }}
echo "${{matrix.image}}_digest=${{ steps.docker_build.outputs.digest }}" >> $GITHUB_OUTPUT
echo ${{ steps.docker_build.outputs.digest }}
echo "${{matrix.image}}_digest=${{ steps.docker_build.outputs.digest }}" >> $GITHUB_OUTPUT

deploy:
name: Deploy capture-replay
Expand Down
Empty file added ee/hogai/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions ee/hogai/generate_trends_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from typing import Literal, Optional

from langchain_core.output_parsers.openai_tools import PydanticToolsParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field

from ee.hogai.system_prompt import trends_system_prompt
from ee.hogai.team_prompt import TeamPrompt
from ee.hogai.trends_function import TrendsFunction
from posthog.models.team.team import Team
from posthog.schema import ExperimentalAITrendsQuery


class output_insight_schema(BaseModel):
reasoning_steps: Optional[list[str]] = None
answer: ExperimentalAITrendsQuery


class ChatMessage(BaseModel):
role: Literal["user", "assistant"]
content: str = Field(..., max_length=2500)


class Conversation(BaseModel):
messages: list[ChatMessage] = Field(..., max_length=20)
session_id: str


class GenerateTrendsAgent:
_team: Team

def __init__(self, team: Team):
self._team = team

def bootstrap(self, messages: list[ChatMessage], user_prompt: str | None = None):
llm = ChatOpenAI(model="gpt-4o-2024-08-06", stream_usage=True).bind_tools(
[TrendsFunction().generate_function()], tool_choice="output_insight_schema"
)
user_prompt = (
user_prompt
or "Answer to my question:\n<question>{{question}}</question>\n" + TeamPrompt(self._team).generate_prompt()
)

prompts = ChatPromptTemplate.from_messages(
[
("system", trends_system_prompt),
("user", user_prompt),
*[(message.role, message.content) for message in messages[1:]],
],
template_format="mustache",
)

chain = prompts | llm | PydanticToolsParser(tools=[output_insight_schema]) # type: ignore
return chain
Loading
Loading