2024-11-12 14:39:27 +01:00
|
|
|
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
from langchain_core.runnables import RunnableConfig
|
|
|
|
|
2024-11-12 19:34:14 +01:00
|
|
|
from ee.hogai.funnels.prompts import FUNNEL_SYSTEM_PROMPT, REACT_SYSTEM_PROMPT
|
2024-11-12 14:39:27 +01:00
|
|
|
from ee.hogai.funnels.toolkit import FUNNEL_SCHEMA, FunnelsTaxonomyAgentToolkit
|
|
|
|
from ee.hogai.schema_generator.nodes import SchemaGeneratorNode, SchemaGeneratorToolsNode
|
|
|
|
from ee.hogai.schema_generator.utils import SchemaGeneratorOutput
|
|
|
|
from ee.hogai.taxonomy_agent.nodes import TaxonomyAgentPlannerNode, TaxonomyAgentPlannerToolsNode
|
|
|
|
from ee.hogai.utils import AssistantState
|
|
|
|
from posthog.schema import AssistantFunnelsQuery
|
|
|
|
|
|
|
|
|
|
|
|
class FunnelPlannerNode(TaxonomyAgentPlannerNode):
|
|
|
|
def run(self, state: AssistantState, config: RunnableConfig) -> AssistantState:
|
|
|
|
toolkit = FunnelsTaxonomyAgentToolkit(self._team)
|
|
|
|
prompt = ChatPromptTemplate.from_messages(
|
|
|
|
[
|
2024-11-12 19:34:14 +01:00
|
|
|
("system", REACT_SYSTEM_PROMPT),
|
2024-11-12 14:39:27 +01:00
|
|
|
],
|
|
|
|
template_format="mustache",
|
|
|
|
)
|
2024-11-12 19:34:14 +01:00
|
|
|
return super()._run_with_prompt_and_toolkit(state, prompt, toolkit, config=config)
|
2024-11-12 14:39:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
class FunnelPlannerToolsNode(TaxonomyAgentPlannerToolsNode):
|
|
|
|
def run(self, state: AssistantState, config: RunnableConfig) -> AssistantState:
|
|
|
|
toolkit = FunnelsTaxonomyAgentToolkit(self._team)
|
2024-11-12 19:34:14 +01:00
|
|
|
return super()._run_with_toolkit(state, toolkit, config=config)
|
2024-11-12 14:39:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
FunnelsSchemaGeneratorOutput = SchemaGeneratorOutput[AssistantFunnelsQuery]
|
|
|
|
|
|
|
|
|
|
|
|
class FunnelGeneratorNode(SchemaGeneratorNode[AssistantFunnelsQuery]):
|
2024-11-12 19:34:14 +01:00
|
|
|
INSIGHT_NAME = "Funnels"
|
|
|
|
OUTPUT_MODEL = FunnelsSchemaGeneratorOutput
|
|
|
|
OUTPUT_SCHEMA = FUNNEL_SCHEMA
|
2024-11-12 14:39:27 +01:00
|
|
|
|
|
|
|
def run(self, state: AssistantState, config: RunnableConfig) -> AssistantState:
|
|
|
|
prompt = ChatPromptTemplate.from_messages(
|
|
|
|
[
|
2024-11-12 19:34:14 +01:00
|
|
|
("system", FUNNEL_SYSTEM_PROMPT),
|
2024-11-12 14:39:27 +01:00
|
|
|
],
|
|
|
|
template_format="mustache",
|
|
|
|
)
|
2024-11-12 19:34:14 +01:00
|
|
|
return super()._run_with_prompt(state, prompt, config=config)
|
2024-11-12 14:39:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
class FunnelGeneratorToolsNode(SchemaGeneratorToolsNode):
|
|
|
|
pass
|