From 0b336b9ef34f466f2eb9a1327af6e2f7a8c4f45a Mon Sep 17 00:00:00 2001 From: Shankar Ambady Date: Tue, 4 Feb 2025 17:35:18 -0500 Subject: [PATCH 1/5] Fix support for hardware accelerated embedding generation via ollama (#2008) * config changes * fixing default settings: * updating docs --- docs/how-to/embeddings.md | 6 +++--- main/settings.py | 2 +- vector_search/encoders/litellm.py | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/how-to/embeddings.md b/docs/how-to/embeddings.md index 7b4958aa7d..b40b0b3cbd 100644 --- a/docs/how-to/embeddings.md +++ b/docs/how-to/embeddings.md @@ -52,17 +52,17 @@ To get setup: ``` QDRANT_ENCODER=vector_search.encoders.litellm.LiteLLMEncoder -LITELLM_API_BASE=http://docker.for.mac.host.internal:11434 +LITELLM_API_BASE=http://docker.for.mac.host.internal:11434/v1/ QDRANT_DENSE_MODEL= ``` -_Note_ - "LITELLM_API_BASE=http://docker.for.mac.host.internal:11434" is Mac specific - if you are using another OS you will need to figure out what your host machine's docker address is. +_Note_ - "LITELLM_API_BASE=http://docker.for.mac.host.internal:11434/v1/" is Mac specific - if you are using another OS you will need to figure out what your host machine's docker address is. Sample .env file configuration on Mac: ``` QDRANT_ENCODER=vector_search.encoders.litellm.LiteLLMEncoder -LITELLM_API_BASE=http://docker.for.mac.host.internal:11434 +LITELLM_API_BASE=http://docker.for.mac.host.internal:11434/v1/ QDRANT_DENSE_MODEL=all-minilm ``` diff --git a/main/settings.py b/main/settings.py index 4626e4ab35..c01b64b580 100644 --- a/main/settings.py +++ b/main/settings.py @@ -816,7 +816,7 @@ def get_all_config_keys(): LITELLM_TOKEN_ENCODING_NAME = get_string( name="LITELLM_TOKEN_ENCODING_NAME", default=None ) -LITELLM_CUSTOM_PROVIDER = get_string(name="LITELLM_CUSTOM_PROVIDER", default="ollama") +LITELLM_CUSTOM_PROVIDER = get_string(name="LITELLM_CUSTOM_PROVIDER", default="openai") LITELLM_API_BASE = get_string(name="LITELLM_API_BASE", default=None) diff --git a/vector_search/encoders/litellm.py b/vector_search/encoders/litellm.py index 5dd81d04a7..6d7613e429 100644 --- a/vector_search/encoders/litellm.py +++ b/vector_search/encoders/litellm.py @@ -28,11 +28,12 @@ def embed_documents(self, documents): return [result["embedding"] for result in self.get_embedding(documents)["data"]] def get_embedding(self, texts): - if settings.LITELLM_CUSTOM_PROVIDER and settings.LITELLM_API_BASE: - return embedding( - model=self.model_name, - input=texts, - api_base=settings.LITELLM_API_BASE, - custom_llm_provider=settings.LITELLM_CUSTOM_PROVIDER, - ).to_dict() - return embedding(model=self.model_name, input=texts).to_dict() + config = { + "model": self.model_name, + "input": texts, + } + if settings.LITELLM_CUSTOM_PROVIDER: + config["custom_llm_provider"] = settings.LITELLM_CUSTOM_PROVIDER + if settings.LITELLM_API_BASE: + config["api_base"] = settings.LITELLM_API_BASE + return embedding(**config).to_dict() From 7967bcf1b45d25c46174186d6be829d44ad6b66a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:51:41 -0500 Subject: [PATCH 2/5] Update dependency faker to v35 (#1996) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 653c895c6b..e6542321b4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1744,13 +1744,13 @@ doc = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-spelling"] [[package]] name = "faker" -version = "30.10.0" +version = "35.2.0" description = "Faker is a Python package that generates fake data for you." optional = false python-versions = ">=3.8" files = [ - {file = "Faker-30.10.0-py3-none-any.whl", hash = "sha256:5f05ee92ddf0e1736d95dca41b2a16ee06d987b736fa4ddecdb047abf2e9024b"}, - {file = "faker-30.10.0.tar.gz", hash = "sha256:c2e627d3becec67f7a45400d3670018b5abb3f0728b7dfaa06c135b7df1ce3fb"}, + {file = "Faker-35.2.0-py3-none-any.whl", hash = "sha256:609abe555761ff31b0e5e16f958696e9b65c9224a7ac612ac96bfc2b8f09fe35"}, + {file = "faker-35.2.0.tar.gz", hash = "sha256:28c24061780f83b45d9cb15a72b8f143b09d276c9ff52eb557744b7a89e8ba19"}, ] [package.dependencies] @@ -7831,4 +7831,4 @@ testing = ["coverage[toml]", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "3.12.6" -content-hash = "e3e07fceaad4bcd0b1ab5dfa63245439162f395b3c15001cce29397f91ad9d2f" +content-hash = "21a25778ed407405a95e83d4acf4bad0046b0098d8ac525ac533dcf9b3cfb35d" diff --git a/pyproject.toml b/pyproject.toml index 32c39a0b7d..f569373f2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,7 +98,7 @@ bpython = "^0.25" ddt = "^1.6.0" django-debug-toolbar = "^4.1.0" factory_boy = "^3.3.0" -faker = "^30.0.0" +faker = "^35.0.0" ipdb = "^0.13.13" moto = "^5.0.0" nplusone = "^1.0.0" From d185a7a2252a863b9304ae2f778093e18e73da71 Mon Sep 17 00:00:00 2001 From: Carey P Gumaer Date: Wed, 5 Feb 2025 16:19:41 -0500 Subject: [PATCH 3/5] track additional browse events in posthog (#2011) * fire a posthog event when clicking the "Topic" link on the homepage in "Browse by Topic" * add events for homepage browse topics section * wrap new events in posthog api key check * track topic_clicked vs subtopic_clicked on topics listing page * properly set subtopic name * properly track clicking a subtopic vs related topic on the topic channel page * consolidate posthog events to a constants file --- .../ChannelPage/TopicChannelTemplate.tsx | 28 ++++++------ .../DepartmentListingPage.tsx | 5 ++- .../HomePage/BrowseTopicsSection.tsx | 21 ++++++++- .../TopicsListingPage/TopicsListingPage.tsx | 43 ++++++++++++++----- .../app-pages/UnitsListingPage/UnitCard.tsx | 5 ++- frontends/main/src/common/constants.ts | 28 ++++++++++++ .../Dialogs/AddToListDialog.tsx | 3 +- .../src/page-components/Header/Header.tsx | 27 ++++++------ .../page-components/HeroSearch/HeroSearch.tsx | 18 +++++++- .../LearningResourceDrawer.tsx | 7 ++- .../LearningResourceExpanded.tsx | 3 +- .../SearchField/SearchField.tsx | 3 +- 12 files changed, 144 insertions(+), 47 deletions(-) create mode 100644 frontends/main/src/common/constants.ts diff --git a/frontends/main/src/app-pages/ChannelPage/TopicChannelTemplate.tsx b/frontends/main/src/app-pages/ChannelPage/TopicChannelTemplate.tsx index 297a1f9f70..e30ecd4727 100644 --- a/frontends/main/src/app-pages/ChannelPage/TopicChannelTemplate.tsx +++ b/frontends/main/src/app-pages/ChannelPage/TopicChannelTemplate.tsx @@ -27,6 +27,7 @@ import { propsNotNil, backgroundSrcSetCSS } from "ol-utilities" import invariant from "tiny-invariant" import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg" import { usePostHog } from "posthog-js/react" +import { PostHogEvents } from "@/common/constants" const ChildrenContainer = styled.div(({ theme }) => ({ paddingTop: "40px", @@ -79,14 +80,18 @@ const BannerSkeleton = styled(Skeleton)(({ theme }) => ({ })) type TopicChipsInternalProps = { - title: string topicId: number parentTopicId: number + isTopLevelTopic: boolean } const TopicChipsInternal: React.FC = (props) => { const posthog = usePostHog() - const { title, topicId, parentTopicId } = props + const { topicId, parentTopicId, isTopLevelTopic } = props + const title = isTopLevelTopic ? "Subtopics" : "Related Topics" + const posthogEvent = isTopLevelTopic + ? PostHogEvents.SubTopicClicked + : PostHogEvents.RelatedTopicClicked const subTopicsQuery = useLearningResourceTopics({ parent_topic_id: [parentTopicId], }) @@ -106,7 +111,7 @@ const TopicChipsInternal: React.FC = (props) => { href={topic.channel_url ?? ""} onClick={() => { if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) { - posthog.capture("related_topic_link_clicked", { topic }) + posthog.capture(posthogEvent, { topic }) } }} label={topic.name} @@ -127,24 +132,17 @@ const TopicChips: React.FC = (props) => { return null } const isTopLevelTopic = topic?.parent === null + const parentTopicId = isTopLevelTopic ? topic.id : topic?.parent - if (isTopLevelTopic) { + if (parentTopicId) { return ( ) - } else if (topic?.parent) { - return ( - - ) - } else return null + } } type SubTopicBreadcrumbsProps = { diff --git a/frontends/main/src/app-pages/DepartmentListingPage/DepartmentListingPage.tsx b/frontends/main/src/app-pages/DepartmentListingPage/DepartmentListingPage.tsx index 75676157c5..5b69ee7078 100644 --- a/frontends/main/src/app-pages/DepartmentListingPage/DepartmentListingPage.tsx +++ b/frontends/main/src/app-pages/DepartmentListingPage/DepartmentListingPage.tsx @@ -31,6 +31,7 @@ import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg" import { aggregateProgramCounts, aggregateCourseCounts } from "@/common/utils" import { useChannelCounts } from "api/hooks/channels" import { usePostHog } from "posthog-js/react" +import { PostHogEvents } from "@/common/constants" const SCHOOL_ICONS: Record = { // School of Architecture and Planning @@ -155,7 +156,9 @@ const SchoolDepartments: React.FC = ({ new URL(department.channel_url).pathname } onClick={() => { - posthog.capture("department_link_clicked", { department }) + posthog.capture(PostHogEvents.DepartmentLinkClicked, { + department, + }) }} > { + const posthog = usePostHog() const { data: topics } = useLearningResourceTopics({ is_toplevel: true }) return ( @@ -119,6 +122,13 @@ const BrowseTopicsSection: React.FC = () => { { + if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) { + posthog.capture(PostHogEvents.HomeTopicClicked, { + topic: name, + }) + } + }} > @@ -130,7 +140,16 @@ const BrowseTopicsSection: React.FC = () => { }, )} - + { + if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) { + posthog.capture(PostHogEvents.HomeSeeAllTopicsClicked) + } + }} + size="large" + responsive + > See all diff --git a/frontends/main/src/app-pages/TopicsListingPage/TopicsListingPage.tsx b/frontends/main/src/app-pages/TopicsListingPage/TopicsListingPage.tsx index b52b3dd090..d72f6ed636 100644 --- a/frontends/main/src/app-pages/TopicsListingPage/TopicsListingPage.tsx +++ b/frontends/main/src/app-pages/TopicsListingPage/TopicsListingPage.tsx @@ -23,6 +23,18 @@ import { aggregateProgramCounts, aggregateCourseCounts } from "@/common/utils" import { useChannelCounts } from "api/hooks/channels" import backgroundSteps from "@/public/images/backgrounds/background_steps.jpg" import { usePostHog } from "posthog-js/react" +import type { PostHog } from "posthog-js" +import { PostHogEvents } from "@/common/constants" + +const captureTopicClicked = ( + posthog: PostHog, + event: string, + topic: string, +) => { + if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) { + posthog.capture(event, { topic }) + } +} type ChannelSummary = { id: number | string @@ -37,12 +49,20 @@ type TopicBoxHeaderProps = { icon?: string href?: string className?: string + posthog?: PostHog } const TopicBoxHeader = styled( - ({ title, icon, href, className }: TopicBoxHeaderProps) => { + ({ title, icon, href, className, posthog }: TopicBoxHeaderProps) => { return ( - + { + if (posthog) { + captureTopicClicked(posthog, PostHogEvents.TopicClicked, title) + } + }} + >