Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ models:
description: Intermediate model for Learn AI RecommendationBot, SyllabusBot and
VideoGPTBot
columns:
- name: djangocheckpoint_id
description: int, foreign key to chatbots_djangocheckpoint
tests:
- not_null
- name: checkpoint_id
description: str, unique identifier for the chatbots checkpoint.
tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ with chatsession as (
)

select
djangocheckpoint.checkpoint_id
djangocheckpoint.djangocheckpoint_id
, djangocheckpoint.checkpoint_id
, djangocheckpoint.chatsession_thread_id
, chatsession.chatsession_agent
, chatsession.chatsession_title
Expand Down
44 changes: 10 additions & 34 deletions src/ol_dbt/models/reporting/chatbot_usage_report.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
with chatbot as (
select * from (
select
*
, row_number() over (
partition by chatsession_thread_id
order by checkpoint_step desc
) as row_num
from {{ ref("int__learn_ai__chatbot") }}
)
where row_num = 1
)

, chatbot_flatten as (
--- this is to address the recent change in langchain where messages are not written into checkpoint_metadata
-- anymore. Instead we need to extract messages from checkpoint
select
chatbot.chatsession_agent
, chatbot.chatsession_object_id
, chatbot.chatsession_thread_id
, chatbot.chatsession_created_on
, t.idx as message_index
, case
when json_extract_scalar(t.element, '$.kwargs.type') = 'human'
then json_extract_scalar(t.element, '$.kwargs.content')
end as human_message
, case
when json_extract_scalar(t.element, '$.kwargs.type') = 'ai'
then json_extract_scalar(t.element, '$.kwargs.content')
end as agent_message
from chatbot
cross join
unnest(cast(json_extract(chatbot.checkpoint_json, '$.channel_values.messages') as array<json>))
with ordinality as t(element, idx) -- noqa: PRS
*
, row_number() over (
partition by chatsession_thread_id
order by djangocheckpoint_id
) as message_index
from (
select * from {{ ref("int__learn_ai__chatbot") }}
where coalesce(agent_message, '') != '' or human_message is not null
)
)

, tutorbot as (
Expand Down Expand Up @@ -92,8 +69,7 @@ select
, agent_message as ai_message
, chatsession_created_on as created_on
, message_index
from chatbot_flatten
where coalesce(agent_message, '') != '' or human_message is not null
from chatbot

union all

Expand Down