Skip to content
Snippets Groups Projects
Unverified Commit a75c2ce8 authored by James Briggs's avatar James Briggs
Browse files

lint

parent 57f024c9
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/07-ollama-local-execution.ipynb) [![Open nbviewer](https://raw.githubusercontent.com/pinecone-io/examples/master/assets/nbviewer-shield.svg)](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/07-ollama-local-execution.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/aurelio-labs/semantic-router/blob/main/docs/07-ollama-local-execution.ipynb) [![Open nbviewer](https://raw.githubusercontent.com/pinecone-io/examples/master/assets/nbviewer-shield.svg)](https://nbviewer.org/github/aurelio-labs/semantic-router/blob/main/docs/07-ollama-local-execution.ipynb)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Local Dynamic Routes - With Ollama # Local Dynamic Routes - With Ollama
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Fully local Semantic Router with Ollama and HuggingFace Encoder ## Fully local Semantic Router with Ollama and HuggingFace Encoder
There are many reasons users might choose to roll their own LLMs rather than use a third-party service. Whether it's due to cost, privacy or compliance, Semantic Router supports the use of "local" LLMs through `llama.cpp`. There are many reasons users might choose to roll their own LLMs rather than use a third-party service. Whether it's due to cost, privacy or compliance, Semantic Router supports the use of "local" LLMs through `llama.cpp`.
Below is an example of using semantic router which leverages Ollama in order to utilize the **OpenHermes** LLM. Below is an example of using semantic router which leverages Ollama in order to utilize the **OpenHermes** LLM.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We need `pillow`, `torch` and `transformers` for the HuggingFace encoders. We need `pillow`, `torch` and `transformers` for the HuggingFace encoders.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Installing the Library and Dependencies ## Installing the Library and Dependencies
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
!pip install semantic_router[local]==0.0.23 \ !pip install semantic_router[local]==0.0.23 \
pillow torch transformers pillow torch transformers
``` ```
%% Output %% Output
Requirement already satisfied: semantic_router[local]==0.0.23 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (0.0.23) Requirement already satisfied: semantic_router[local]==0.0.23 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (0.0.23)
Requirement already satisfied: pillow in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (10.2.0) Requirement already satisfied: pillow in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (10.2.0)
Requirement already satisfied: torch in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (2.2.0) Requirement already satisfied: torch in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (2.2.0)
Requirement already satisfied: transformers in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (4.38.0) Requirement already satisfied: transformers in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (4.38.0)
Requirement already satisfied: black<24.0.0,>=23.12.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (23.12.1) Requirement already satisfied: black<24.0.0,>=23.12.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (23.12.1)
Requirement already satisfied: cohere<5.0,>=4.32 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (4.47) Requirement already satisfied: cohere<5.0,>=4.32 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (4.47)
Requirement already satisfied: colorama<0.5.0,>=0.4.6 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.4.6) Requirement already satisfied: colorama<0.5.0,>=0.4.6 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.4.6)
Requirement already satisfied: colorlog<7.0.0,>=6.8.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (6.8.2) Requirement already satisfied: colorlog<7.0.0,>=6.8.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (6.8.2)
Requirement already satisfied: llama-cpp-python<0.3.0,>=0.2.28 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.2.45) Requirement already satisfied: llama-cpp-python<0.3.0,>=0.2.28 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.2.45)
Requirement already satisfied: mistralai<0.0.13,>=0.0.12 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.0.12) Requirement already satisfied: mistralai<0.0.13,>=0.0.12 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (0.0.12)
Requirement already satisfied: numpy<2.0.0,>=1.25.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (1.26.4) Requirement already satisfied: numpy<2.0.0,>=1.25.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (1.26.4)
Requirement already satisfied: openai<2.0.0,>=1.10.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (1.12.0) Requirement already satisfied: openai<2.0.0,>=1.10.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (1.12.0)
Requirement already satisfied: pydantic<3.0.0,>=2.5.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (2.6.1) Requirement already satisfied: pydantic<3.0.0,>=2.5.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (2.6.1)
Requirement already satisfied: pyyaml<7.0.0,>=6.0.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (6.0.1) Requirement already satisfied: pyyaml<7.0.0,>=6.0.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from semantic_router[local]==0.0.23) (6.0.1)
Requirement already satisfied: filelock in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.13.1) Requirement already satisfied: filelock in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (4.9.0) Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (4.9.0)
Requirement already satisfied: sympy in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (1.12) Requirement already satisfied: sympy in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (1.12)
Requirement already satisfied: networkx in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.2.1) Requirement already satisfied: networkx in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.1.3) Requirement already satisfied: jinja2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (2024.2.0) Requirement already satisfied: fsspec in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from torch) (2024.2.0)
Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.20.3) Requirement already satisfied: huggingface-hub<1.0,>=0.19.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.20.3)
Requirement already satisfied: packaging>=20.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (23.2) Requirement already satisfied: packaging>=20.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (23.2)
Requirement already satisfied: regex!=2019.12.17 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (2023.12.25) Requirement already satisfied: regex!=2019.12.17 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (2023.12.25)
Requirement already satisfied: requests in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (2.31.0) Requirement already satisfied: requests in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (2.31.0)
Requirement already satisfied: tokenizers<0.19,>=0.14 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.15.2) Requirement already satisfied: tokenizers<0.19,>=0.14 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.15.2)
Requirement already satisfied: safetensors>=0.4.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.4.2) Requirement already satisfied: safetensors>=0.4.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (0.4.2)
Requirement already satisfied: tqdm>=4.27 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (4.66.2) Requirement already satisfied: tqdm>=4.27 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from transformers) (4.66.2)
Requirement already satisfied: click>=8.0.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (8.1.7) Requirement already satisfied: click>=8.0.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (8.1.7)
Requirement already satisfied: mypy-extensions>=0.4.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (1.0.0) Requirement already satisfied: mypy-extensions>=0.4.3 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (1.0.0)
Requirement already satisfied: pathspec>=0.9.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (0.12.1) Requirement already satisfied: pathspec>=0.9.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (0.12.1)
Requirement already satisfied: platformdirs>=2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (4.2.0) Requirement already satisfied: platformdirs>=2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from black<24.0.0,>=23.12.1->semantic_router[local]==0.0.23) (4.2.0)
Requirement already satisfied: aiohttp<4.0,>=3.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.9.3) Requirement already satisfied: aiohttp<4.0,>=3.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.9.3)
Requirement already satisfied: backoff<3.0,>=2.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1) Requirement already satisfied: backoff<3.0,>=2.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1)
Requirement already satisfied: fastavro<2.0,>=1.8 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4) Requirement already satisfied: fastavro<2.0,>=1.8 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4)
Requirement already satisfied: importlib_metadata<7.0,>=6.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.11.0) Requirement already satisfied: importlib_metadata<7.0,>=6.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.11.0)
Requirement already satisfied: urllib3<3,>=1.26 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1) Requirement already satisfied: urllib3<3,>=1.26 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (2.2.1)
Requirement already satisfied: diskcache>=5.6.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from llama-cpp-python<0.3.0,>=0.2.28->semantic_router[local]==0.0.23) (5.6.3) Requirement already satisfied: diskcache>=5.6.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from llama-cpp-python<0.3.0,>=0.2.28->semantic_router[local]==0.0.23) (5.6.3)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from jinja2->torch) (2.1.5) Requirement already satisfied: MarkupSafe>=2.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from jinja2->torch) (2.1.5)
Requirement already satisfied: httpx<0.26.0,>=0.25.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.25.2) Requirement already satisfied: httpx<0.26.0,>=0.25.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.25.2)
Requirement already satisfied: orjson<4.0.0,>=3.9.10 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (3.9.14) Requirement already satisfied: orjson<4.0.0,>=3.9.10 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (3.9.14)
Requirement already satisfied: anyio<5,>=3.5.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (4.2.0) Requirement already satisfied: anyio<5,>=3.5.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (4.2.0)
Requirement already satisfied: distro<2,>=1.7.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.9.0) Requirement already satisfied: distro<2,>=1.7.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.9.0)
Requirement already satisfied: sniffio in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.3.0) Requirement already satisfied: sniffio in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from openai<2.0.0,>=1.10.0->semantic_router[local]==0.0.23) (1.3.0)
Requirement already satisfied: annotated-types>=0.4.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (0.6.0) Requirement already satisfied: annotated-types>=0.4.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (0.6.0)
Requirement already satisfied: pydantic-core==2.16.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (2.16.2) Requirement already satisfied: pydantic-core==2.16.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from pydantic<3.0.0,>=2.5.3->semantic_router[local]==0.0.23) (2.16.2)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (3.3.2) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (3.6) Requirement already satisfied: idna<4,>=2.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (3.6)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (2024.2.2) Requirement already satisfied: certifi>=2017.4.17 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from requests->transformers) (2024.2.2)
Requirement already satisfied: mpmath>=0.19 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from sympy->torch) (1.3.0) Requirement already satisfied: mpmath>=0.19 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from sympy->torch) (1.3.0)
Requirement already satisfied: aiosignal>=1.1.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.3.1) Requirement already satisfied: aiosignal>=1.1.2 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (23.2.0) Requirement already satisfied: attrs>=17.3.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (23.2.0)
Requirement already satisfied: frozenlist>=1.1.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.4.1) Requirement already satisfied: frozenlist>=1.1.1 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.4.1)
Requirement already satisfied: multidict<7.0,>=4.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.0.5) Requirement already satisfied: multidict<7.0,>=4.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (6.0.5)
Requirement already satisfied: yarl<2.0,>=1.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4) Requirement already satisfied: yarl<2.0,>=1.0 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from aiohttp<4.0,>=3.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (1.9.4)
Requirement already satisfied: httpcore==1.* in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (1.0.3) Requirement already satisfied: httpcore==1.* in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (1.0.3)
Requirement already satisfied: h11<0.15,>=0.13 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from httpcore==1.*->httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.14.0) Requirement already satisfied: h11<0.15,>=0.13 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from httpcore==1.*->httpx<0.26.0,>=0.25.2->mistralai<0.0.13,>=0.0.12->semantic_router[local]==0.0.23) (0.14.0)
Requirement already satisfied: zipp>=0.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from importlib_metadata<7.0,>=6.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.17.0) Requirement already satisfied: zipp>=0.5 in c:\users\siraj\documents\personal\work\aurelio\20240123 semantic router\venvs\semantic_router\lib\site-packages (from importlib_metadata<7.0,>=6.0->cohere<5.0,>=4.32->semantic_router[local]==0.0.23) (3.17.0)
[notice] A new release of pip is available: 23.1.2 -> 24.0 [notice] A new release of pip is available: 23.1.2 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip [notice] To update, run: python.exe -m pip install --upgrade pip
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from semantic_router.encoders import HuggingFaceEncoder from semantic_router.encoders import HuggingFaceEncoder
encoder = HuggingFaceEncoder() encoder = HuggingFaceEncoder()
``` ```
%% Output %% Output
c:\Users\Siraj\Documents\Personal\Work\Aurelio\20240123 Semantic Router\venvs\semantic_router\Lib\site-packages\tqdm\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html c:\Users\Siraj\Documents\Personal\Work\Aurelio\20240123 Semantic Router\venvs\semantic_router\Lib\site-packages\tqdm\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm from .autonotebook import tqdm as notebook_tqdm
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Define Static Routes ## Define Static Routes
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from semantic_router import Route from semantic_router import Route
# we could use this as a guide for our chatbot to avoid political conversations # we could use this as a guide for our chatbot to avoid political conversations
politics = Route( politics = Route(
name="politics", name="politics",
utterances=[ utterances=[
"isn't politics the best thing ever", "isn't politics the best thing ever",
"why don't you tell me about your political opinions", "why don't you tell me about your political opinions",
"don't you just love the president" "don't you just hate the president", "don't you just love the president" "don't you just hate the president",
"they're going to destroy this country!", "they're going to destroy this country!",
"they will save the country!", "they will save the country!",
], ],
) )
# this could be used as an indicator to our chatbot to switch to a more # this could be used as an indicator to our chatbot to switch to a more
# conversational prompt # conversational prompt
chitchat = Route( chitchat = Route(
name="chitchat", name="chitchat",
utterances=[ utterances=[
"how's the weather today?", "how's the weather today?",
"how are things going?", "how are things going?",
"lovely weather today", "lovely weather today",
"the weather is horrendous", "the weather is horrendous",
"let's go to the chippy", "let's go to the chippy",
], ],
) )
# we place both of our decisions together into single list # we place both of our decisions together into single list
routes = [politics, chitchat] routes = [politics, chitchat]
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Define Route Layer with Ollama ## Define Route Layer with Ollama
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from semantic_router.layer import RouteLayer from semantic_router.layer import RouteLayer
from semantic_router.llms.ollama import OllamaLLM from semantic_router.llms.ollama import OllamaLLM
llm = OllamaLLM(llm_name="openhermes") # Change llm_name if you want to use a different LLM with dynamic routes. llm = OllamaLLM(
rl = RouteLayer(encoder = encoder, routes=routes, llm=llm) llm_name="openhermes"
) # Change llm_name if you want to use a different LLM with dynamic routes.
rl = RouteLayer(encoder=encoder, routes=routes, llm=llm)
``` ```
%% Output %% Output
2024-02-22 10:59:54 INFO semantic_router.utils.logger local 2024-02-22 10:59:54 INFO semantic_router.utils.logger local
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Test Static Routes ## Test Static Routes
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
rl("don't you love politics?").name rl("don't you love politics?").name
``` ```
%% Output %% Output
'politics' 'politics'
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
rl("how's the weather today?").name rl("how's the weather today?").name
``` ```
%% Output %% Output
'chitchat' 'chitchat'
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
rl("I'm interested in learning about llama 2").name rl("I'm interested in learning about llama 2").name
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Test Dynamic Routes ## Test Dynamic Routes
Dynamic routes work by associating a function with a route. If the input utterance is similar enough to the utterances of the route, such that route is chosen by the semantic router, then this triggers a secondary process: Dynamic routes work by associating a function with a route. If the input utterance is similar enough to the utterances of the route, such that route is chosen by the semantic router, then this triggers a secondary process:
The LLM we specified in the `RouteLayer` (we specified Ollama, which isn't strictly an LLM, but which defaults to using the `OpenHermes` LLM), is then usde to take a `function_schema`, and the input utterance, and extract values from the input utterance which can be used as arguments for `function` described by the the `funcion_schema`. The returned values can then be used in the `function` to obtain an output. The LLM we specified in the `RouteLayer` (we specified Ollama, which isn't strictly an LLM, but which defaults to using the `OpenHermes` LLM), is then usde to take a `function_schema`, and the input utterance, and extract values from the input utterance which can be used as arguments for `function` described by the the `funcion_schema`. The returned values can then be used in the `function` to obtain an output.
So, in short, it's a way of generating `function` inputs from an utterance, if that utterance matches the route utterances closely enough. So, in short, it's a way of generating `function` inputs from an utterance, if that utterance matches the route utterances closely enough.
In the below example the utterance **"what is the time in new york city?"** is used to trigger the "get_time" route, which has the `function_schema` of a likewise named `get_time()` function associated with it. Then Ollama is used to run `OpenHermes` locally, which extracts the correctly formatted IANA timezone (`"America/New York"`), based on this utterance and information we provide it about the `function` in the `function_schema`. The returned stirng "America/New York" can then be used directly in the `get_time()` function to return the actual time in New York city. In the below example the utterance **"what is the time in new york city?"** is used to trigger the "get_time" route, which has the `function_schema` of a likewise named `get_time()` function associated with it. Then Ollama is used to run `OpenHermes` locally, which extracts the correctly formatted IANA timezone (`"America/New York"`), based on this utterance and information we provide it about the `function` in the `function_schema`. The returned stirng "America/New York" can then be used directly in the `get_time()` function to return the actual time in New York city.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from datetime import datetime from datetime import datetime
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
def get_time(timezone: str) -> str: def get_time(timezone: str) -> str:
""" """
Finds the current time in a specific timezone. Finds the current time in a specific timezone.
:param timezone: The timezone to find the current time in, should :param timezone: The timezone to find the current time in, should
be a valid timezone from the IANA Time Zone Database like be a valid timezone from the IANA Time Zone Database like
"America/New_York" or "Europe/London". Do NOT put the place "America/New_York" or "Europe/London". Do NOT put the place
name itself like "rome", or "new york", you must provide name itself like "rome", or "new york", you must provide
the IANA format. the IANA format.
:type timezone: str :type timezone: str
:return: The current time in the specified timezone. :return: The current time in the specified timezone.
""" """
now = datetime.now(ZoneInfo(timezone)) now = datetime.now(ZoneInfo(timezone))
return now.strftime("%H:%M") return now.strftime("%H:%M")
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
get_time("America/New_York") get_time("America/New_York")
``` ```
%% Output %% Output
'01:59' '01:59'
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from semantic_router.utils.function_call import get_schema from semantic_router.utils.function_call import get_schema
schema = get_schema(get_time) schema = get_schema(get_time)
schema schema
``` ```
%% Output %% Output
{'name': 'get_time', {'name': 'get_time',
'description': 'Finds the current time in a specific timezone.\n\n:param timezone: The timezone to find the current time in, should\n be a valid timezone from the IANA Time Zone Database like\n "America/New_York" or "Europe/London". Do NOT put the place\n name itself like "rome", or "new york", you must provide\n the IANA format.\n:type timezone: str\n:return: The current time in the specified timezone.\n ', 'description': 'Finds the current time in a specific timezone.\n\n:param timezone: The timezone to find the current time in, should\n be a valid timezone from the IANA Time Zone Database like\n "America/New_York" or "Europe/London". Do NOT put the place\n name itself like "rome", or "new york", you must provide\n the IANA format.\n:type timezone: str\n:return: The current time in the specified timezone.\n ',
'signature': '(timezone: str) -> str', 'signature': '(timezone: str) -> str',
'output': "<class 'str'>"} 'output': "<class 'str'>"}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
time_route = Route( time_route = Route(
name="get_time", name="get_time",
utterances=[ utterances=[
"what is the time in new york city?", "what is the time in new york city?",
"what is the time in london?", "what is the time in london?",
"I live in Rome, what time is it?", "I live in Rome, what time is it?",
], ],
function_schema=schema, function_schema=schema,
) )
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
rl.add(time_route) rl.add(time_route)
``` ```
%% Output %% Output
2024-02-22 10:59:55 INFO semantic_router.utils.logger Adding `get_time` route 2024-02-22 10:59:55 INFO semantic_router.utils.logger Adding `get_time` route
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
out = rl("what is the time in new york city?") out = rl("what is the time in new york city?")
print(out) print(out)
``` ```
%% Output %% Output
2024-02-22 11:01:29 INFO semantic_router.utils.logger Extracting function input... 2024-02-22 11:01:29 INFO semantic_router.utils.logger Extracting function input...
2024-02-22 11:01:32 INFO semantic_router.utils.logger LLM output: { 2024-02-22 11:01:32 INFO semantic_router.utils.logger LLM output: {
"timezone": "America/New_York" "timezone": "America/New_York"
} }
2024-02-22 11:01:32 INFO semantic_router.utils.logger Function inputs: {'timezone': 'America/New_York'} 2024-02-22 11:01:32 INFO semantic_router.utils.logger Function inputs: {'timezone': 'America/New_York'}
name='get_time' function_call={'timezone': 'America/New_York'} similarity_score=None trigger=None name='get_time' function_call={'timezone': 'America/New_York'} similarity_score=None trigger=None
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
get_time(**out.function_call) get_time(**out.function_call)
``` ```
%% Output %% Output
'02:01' '02:01'
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
text = ''' text = """
In a recent surge of social media discussions on Weibo, Chinese netizens have been engaging in conversations about the struggles and challenges of earning money. The online debate sparked a wave of opinions and perspectives on the relationship between hard work, high pay, and finding contentment. Among the tweets, several users pontificated that one should avoid earning "too much hard-earned money." In a recent surge of social media discussions on Weibo, Chinese netizens have been engaging in conversations about the struggles and challenges of earning money. The online debate sparked a wave of opinions and perspectives on the relationship between hard work, high pay, and finding contentment. Among the tweets, several users pontificated that one should avoid earning "too much hard-earned money."
The tweets and discussions revolve around the idea that working too hard for one's income can have a detrimental effect on one's life, both physically and mentally. Some users advocate for finding opportunities that align with one's strengths and passions, rather than simply focusing on high-paying jobs that may require excessive hours and intense labor. The tweets and discussions revolve around the idea that working too hard for one's income can have a detrimental effect on one's life, both physically and mentally. Some users advocate for finding opportunities that align with one's strengths and passions, rather than simply focusing on high-paying jobs that may require excessive hours and intense labor.
One Weibo user pontificates, "Don't earn that much hard-earned money," a sentiment echoed by others with tweets such as, "Why is it that when earning money, that process always has to be so tough?" This question is followed by a comparison between two types of people - those who are used to earning money the hard way and those who seem to effortlessly obtain wealth. While the former group is depicted as having been taught to suffer from a young age, the latter is shown as being able to focus solely on their natural talents and thriving in their niche advantageously. One Weibo user pontificates, "Don't earn that much hard-earned money," a sentiment echoed by others with tweets such as, "Why is it that when earning money, that process always has to be so tough?" This question is followed by a comparison between two types of people - those who are used to earning money the hard way and those who seem to effortlessly obtain wealth. While the former group is depicted as having been taught to suffer from a young age, the latter is shown as being able to focus solely on their natural talents and thriving in their niche advantageously.
Discussions on the platform draw attention to a variety of issues that those who earn money the hard way might face. For example, they are described as likely having to work overtime, forgo time off for illness or rest, and maintain an unyielding dedication to their occupation, which often results in a never-ending cycle of work without any perceived progression in their lives. Discussions on the platform draw attention to a variety of issues that those who earn money the hard way might face. For example, they are described as likely having to work overtime, forgo time off for illness or rest, and maintain an unyielding dedication to their occupation, which often results in a never-ending cycle of work without any perceived progression in their lives.
Another tweet that captures this sentiment reads, "Drowning in more work and poverty despite trying harder and harder," pointing to a sense of despair and dissatisfaction that comes with work that is both disproportionately demanding and inadequately rewarding. Critics also note how the pursuit of hard-earned money could potentially create physical and mental health risks due to the unrelenting pressure and stress that these jobs might impose. Another tweet that captures this sentiment reads, "Drowning in more work and poverty despite trying harder and harder," pointing to a sense of despair and dissatisfaction that comes with work that is both disproportionately demanding and inadequately rewarding. Critics also note how the pursuit of hard-earned money could potentially create physical and mental health risks due to the unrelenting pressure and stress that these jobs might impose.
Conversely, those in favor of earning money with less difficulty contend that it's crucial to harness one's strengths and passions to create opportunities that yield financial success without the need for excessive labor. The debate revolves around the concept that people should seek out ways to work smarter, not harder, especially if it means a healthier and more fulfilling lifestyle. Conversely, those in favor of earning money with less difficulty contend that it's crucial to harness one's strengths and passions to create opportunities that yield financial success without the need for excessive labor. The debate revolves around the concept that people should seek out ways to work smarter, not harder, especially if it means a healthier and more fulfilling lifestyle.
In fact, the notion of a "vicious cycle," often attributed to those chasing hard-earned money, is juxtaposed with an idealized image of someone operating in their zone of excellence. Confidently focused on their strengths, such individuals are depicted as enjoying a more relaxed and less stressful work environment, one in which they can thrive without the need for never-ending overtime or self-sacrifice. In fact, the notion of a "vicious cycle," often attributed to those chasing hard-earned money, is juxtaposed with an idealized image of someone operating in their zone of excellence. Confidently focused on their strengths, such individuals are depicted as enjoying a more relaxed and less stressful work environment, one in which they can thrive without the need for never-ending overtime or self-sacrifice.
Some tweets even extend this sentiment to the broader socio-economic context, observing how wealth is not merely derived from manual labor or high-paying positions requiring extraordinary work hours. The tweets emphasize the importance of cultivating an entrepreneurial spirit and a penchant for innovative thinking, especially in the modern digital age. Some tweets even extend this sentiment to the broader socio-economic context, observing how wealth is not merely derived from manual labor or high-paying positions requiring extraordinary work hours. The tweets emphasize the importance of cultivating an entrepreneurial spirit and a penchant for innovative thinking, especially in the modern digital age.
One user writes, "Too hard-earned money isn't worth it. Learn how to make money using your brain, not your body," while another suggests, "Love will flow towards those who are not lacking in love, and money will flow towards those who are not lacking in money!" One user writes, "Too hard-earned money isn't worth it. Learn how to make money using your brain, not your body," while another suggests, "Love will flow towards those who are not lacking in love, and money will flow towards those who are not lacking in money!"
While some of the discussions take a somewhat passive-aggressive view, others acknowledge that financial security and comfort might not always be possible for everyone. In a more realistic tone, a user remarks, "If life were so easy that diligence led to wealth, then the world's richest person would be the best worker bee. But that's not the case." This acknowledgment underscores the complexities of the economy and the role that factors like luck, connections, and a rapidly evolving job market can play in financial success. While some of the discussions take a somewhat passive-aggressive view, others acknowledge that financial security and comfort might not always be possible for everyone. In a more realistic tone, a user remarks, "If life were so easy that diligence led to wealth, then the world's richest person would be the best worker bee. But that's not the case." This acknowledgment underscores the complexities of the economy and the role that factors like luck, connections, and a rapidly evolving job market can play in financial success.
Some users are quick to criticize the notion that earning money the hard way should be avoided, with one tweet expressing, "The person who advises you to avoid hard-earned money is likely a scammer who profits off providing emotional value in exchange for exploitation." Others argue that while it's essential to find enjoyment and fulfillment in one's work, it's crucial not to shun or belittle those who choose to work in physically demanding or high-paying industries. Some users are quick to criticize the notion that earning money the hard way should be avoided, with one tweet expressing, "The person who advises you to avoid hard-earned money is likely a scammer who profits off providing emotional value in exchange for exploitation." Others argue that while it's essential to find enjoyment and fulfillment in one's work, it's crucial not to shun or belittle those who choose to work in physically demanding or high-paying industries.
Overall, the Weibo discussions offer a fascinating insight into the complexities of the modern Chinese labor market and the work-life balance that people strive to achieve. As in many countries, striking the right balance between work and play is an ongoing challenge for many Chinese citizens. However, the conversations on Weibo signal an increasing awareness of the importance of finding meaningful, fulfilling, and financially rewarding work that doesn't necessitate excessive sacrifice or sufferance. Overall, the Weibo discussions offer a fascinating insight into the complexities of the modern Chinese labor market and the work-life balance that people strive to achieve. As in many countries, striking the right balance between work and play is an ongoing challenge for many Chinese citizens. However, the conversations on Weibo signal an increasing awareness of the importance of finding meaningful, fulfilling, and financially rewarding work that doesn't necessitate excessive sacrifice or sufferance.
In the end, as one user succinctly puts it, "Make sure you're earning your money in a way that brings you joy and satisfaction. That's the only way to ensure that your life doesn't become a never-ending cycle of hard work without any tangible progress." In the end, as one user succinctly puts it, "Make sure you're earning your money in a way that brings you joy and satisfaction. That's the only way to ensure that your life doesn't become a never-ending cycle of hard work without any tangible progress."
In this context, social media discussions focusing on the trials and tribulations of earning money serve not only as an outlet for venting frustrations but also as a means of promoting dialogue and shared understanding about the challenges faced by workers across all industries. These virtual conversations sparked by tweets and in-depth discussions likely resonate with a wide swath of Chinese citizens struggling to navigate the complexities of balancing a career that pays well with one that brings them joy, fulfillment, and a sense of purpose. In this context, social media discussions focusing on the trials and tribulations of earning money serve not only as an outlet for venting frustrations but also as a means of promoting dialogue and shared understanding about the challenges faced by workers across all industries. These virtual conversations sparked by tweets and in-depth discussions likely resonate with a wide swath of Chinese citizens struggling to navigate the complexities of balancing a career that pays well with one that brings them joy, fulfillment, and a sense of purpose.
As the discussions on Weibo continue to evolve and unfold, it is evident that the discourse around work, money, and life satisfaction holds the potential to inspire meaningful change and shift societal attitudes towards a more holistic, balanced, and humane understanding of success and prosperity. As the discussions on Weibo continue to evolve and unfold, it is evident that the discourse around work, money, and life satisfaction holds the potential to inspire meaningful change and shift societal attitudes towards a more holistic, balanced, and humane understanding of success and prosperity.
--- ---
Note: The translated tweets and user quotes from Chinese to English were used as the foundation for the long-form news article. The author tried to maintain the integrity of the original content in the translation while adapting it to fit a journalistic format. No inaccuracies were introduced during translation, and the opinion-based nature of the original content was preserved while maintaining objectivity. Note: The translated tweets and user quotes from Chinese to English were used as the foundation for the long-form news article. The author tried to maintain the integrity of the original content in the translation while adapting it to fit a journalistic format. No inaccuracies were introduced during translation, and the opinion-based nature of the original content was preserved while maintaining objectivity.
Heart count: 0/2 Heart count: 0/2
Note: The author did not include any Chinese characters in the final response. Note: The author did not include any Chinese characters in the final response.
Collapse Collapse
''' """
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import os import os
from getpass import getpass from getpass import getpass
from semantic_router.splitters import RollingWindowSplitter from semantic_router.splitters import RollingWindowSplitter
from semantic_router.encoders import OpenAIEncoder from semantic_router.encoders import OpenAIEncoder
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API key: ") os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") or getpass(
"Enter your OpenAI API key: "
)
splitter = RollingWindowSplitter( splitter = RollingWindowSplitter(
encoder=OpenAIEncoder(), encoder=OpenAIEncoder(),
min_split_tokens=50, min_split_tokens=50,
max_split_tokens=300, max_split_tokens=300,
window_size=5, # sentences window_size=5, # sentences
plot_splits=True plot_splits=True,
) )
``` ```
%% Output %% Output
/Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html /Users/jamesbriggs/opt/anaconda3/envs/decision-layer/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm from .autonotebook import tqdm as notebook_tqdm
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
splits = splitter([text]) splits = splitter([text])
``` ```
%% Output %% Output
2024-02-23 08:44:26 WARNING semantic_router.utils.logger Single document exceeds the maximum token limit of 300. Splitting to sentences before semantically splitting. 2024-02-23 08:44:26 WARNING semantic_router.utils.logger Single document exceeds the maximum token limit of 300. Splitting to sentences before semantically splitting.
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Trying threshold: 0.8881277932028191 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Trying threshold: 0.8881277932028191
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Median tokens per split: 24.0 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Median tokens per split: 24.0
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Adjusting high to 0.8781277932028191 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 0: Adjusting high to 0.8781277932028191
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Trying threshold: 0.8687934834140205 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Trying threshold: 0.8687934834140205
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Median tokens per split: 34.5 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Median tokens per split: 34.5
2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Adjusting high to 0.8587934834140205 2024-02-23 08:44:26 INFO semantic_router.utils.logger Iteration 1: Adjusting high to 0.8587934834140205
2024-02-23 08:44:26 INFO semantic_router.utils.logger Final optimal threshold: 0.8687934834140205 2024-02-23 08:44:26 INFO semantic_router.utils.logger Final optimal threshold: 0.8687934834140205
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 218 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 218 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 262 tokens due to exceeding token limit of 300. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 262 tokens due to exceeding token limit of 300.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 137 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 137 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 249 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 249 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 117 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 117 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 171 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 171 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 72 tokens due to threshold 0.8687934834140205. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Split finalized with 72 tokens due to threshold 0.8687934834140205.
2024-02-23 08:44:27 INFO semantic_router.utils.logger Final split added with 23 tokens due to remaining documents. 2024-02-23 08:44:27 INFO semantic_router.utils.logger Final split added with 23 tokens due to remaining documents.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
splitter.print(splits) splitter.print(splits)
``` ```
%% Output %% Output
Split 1, tokens 218, triggered by: 0.85 Split 1, tokens 218, triggered by: 0.85
In a recent surge of social media discussions on Weibo, Chinese netizens have been engaging in conversations about the struggles and challenges of earning money. The online debate sparked a wave of opinions and perspectives on the relationship between hard work, high pay, and finding contentment. Among the tweets, several users pontificated that one should avoid earning "too much hard-earned money." The tweets and discussions revolve around the idea that working too hard for one's income can have a detrimental effect on one's life, both physically and mentally. Some users advocate for finding opportunities that align with one's strengths and passions, rather than simply focusing on high-paying jobs that may require excessive hours and intense labor. One Weibo user pontificates, "Don't earn that much hard-earned money," a sentiment echoed by others with tweets such as, "Why is it that when earning money, that process always has to be so tough?" This question is followed by a comparison between two types of people - those who are used to earning money the hard way and those who seem to effortlessly obtain wealth. In a recent surge of social media discussions on Weibo, Chinese netizens have been engaging in conversations about the struggles and challenges of earning money. The online debate sparked a wave of opinions and perspectives on the relationship between hard work, high pay, and finding contentment. Among the tweets, several users pontificated that one should avoid earning "too much hard-earned money." The tweets and discussions revolve around the idea that working too hard for one's income can have a detrimental effect on one's life, both physically and mentally. Some users advocate for finding opportunities that align with one's strengths and passions, rather than simply focusing on high-paying jobs that may require excessive hours and intense labor. One Weibo user pontificates, "Don't earn that much hard-earned money," a sentiment echoed by others with tweets such as, "Why is it that when earning money, that process always has to be so tough?" This question is followed by a comparison between two types of people - those who are used to earning money the hard way and those who seem to effortlessly obtain wealth.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 2, tokens 262, triggered by: token limit Split 2, tokens 262, triggered by: token limit
While the former group is depicted as having been taught to suffer from a young age, the latter is shown as being able to focus solely on their natural talents and thriving in their niche advantageously. Discussions on the platform draw attention to a variety of issues that those who earn money the hard way might face. For example, they are described as likely having to work overtime, forgo time off for illness or rest, and maintain an unyielding dedication to their occupation, which often results in a never-ending cycle of work without any perceived progression in their lives. Another tweet that captures this sentiment reads, "Drowning in more work and poverty despite trying harder and harder," pointing to a sense of despair and dissatisfaction that comes with work that is both disproportionately demanding and inadequately rewarding. Critics also note how the pursuit of hard-earned money could potentially create physical and mental health risks due to the unrelenting pressure and stress that these jobs might impose. Conversely, those in favor of earning money with less difficulty contend that it's crucial to harness one's strengths and passions to create opportunities that yield financial success without the need for excessive labor. The debate revolves around the concept that people should seek out ways to work smarter, not harder, especially if it means a healthier and more fulfilling lifestyle. While the former group is depicted as having been taught to suffer from a young age, the latter is shown as being able to focus solely on their natural talents and thriving in their niche advantageously. Discussions on the platform draw attention to a variety of issues that those who earn money the hard way might face. For example, they are described as likely having to work overtime, forgo time off for illness or rest, and maintain an unyielding dedication to their occupation, which often results in a never-ending cycle of work without any perceived progression in their lives. Another tweet that captures this sentiment reads, "Drowning in more work and poverty despite trying harder and harder," pointing to a sense of despair and dissatisfaction that comes with work that is both disproportionately demanding and inadequately rewarding. Critics also note how the pursuit of hard-earned money could potentially create physical and mental health risks due to the unrelenting pressure and stress that these jobs might impose. Conversely, those in favor of earning money with less difficulty contend that it's crucial to harness one's strengths and passions to create opportunities that yield financial success without the need for excessive labor. The debate revolves around the concept that people should seek out ways to work smarter, not harder, especially if it means a healthier and more fulfilling lifestyle.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 3, tokens 137, triggered by: 0.85 Split 3, tokens 137, triggered by: 0.85
In fact, the notion of a "vicious cycle," often attributed to those chasing hard-earned money, is juxtaposed with an idealized image of someone operating in their zone of excellence. Confidently focused on their strengths, such individuals are depicted as enjoying a more relaxed and less stressful work environment, one in which they can thrive without the need for never-ending overtime or self-sacrifice. Some tweets even extend this sentiment to the broader socio-economic context, observing how wealth is not merely derived from manual labor or high-paying positions requiring extraordinary work hours. The tweets emphasize the importance of cultivating an entrepreneurial spirit and a penchant for innovative thinking, especially in the modern digital age. In fact, the notion of a "vicious cycle," often attributed to those chasing hard-earned money, is juxtaposed with an idealized image of someone operating in their zone of excellence. Confidently focused on their strengths, such individuals are depicted as enjoying a more relaxed and less stressful work environment, one in which they can thrive without the need for never-ending overtime or self-sacrifice. Some tweets even extend this sentiment to the broader socio-economic context, observing how wealth is not merely derived from manual labor or high-paying positions requiring extraordinary work hours. The tweets emphasize the importance of cultivating an entrepreneurial spirit and a penchant for innovative thinking, especially in the modern digital age.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 4, tokens 249, triggered by: 0.86 Split 4, tokens 249, triggered by: 0.86
One user writes, "Too hard-earned money isn't worth it. Learn how to make money using your brain, not your body," while another suggests, "Love will flow towards those who are not lacking in love, and money will flow towards those who are not lacking in money!" While some of the discussions take a somewhat passive-aggressive view, others acknowledge that financial security and comfort might not always be possible for everyone. In a more realistic tone, a user remarks, "If life were so easy that diligence led to wealth, then the world's richest person would be the best worker bee. But that's not the case." This acknowledgment underscores the complexities of the economy and the role that factors like luck, connections, and a rapidly evolving job market can play in financial success. Some users are quick to criticize the notion that earning money the hard way should be avoided, with one tweet expressing, "The person who advises you to avoid hard-earned money is likely a scammer who profits off providing emotional value in exchange for exploitation." Others argue that while it's essential to find enjoyment and fulfillment in one's work, it's crucial not to shun or belittle those who choose to work in physically demanding or high-paying industries. One user writes, "Too hard-earned money isn't worth it. Learn how to make money using your brain, not your body," while another suggests, "Love will flow towards those who are not lacking in love, and money will flow towards those who are not lacking in money!" While some of the discussions take a somewhat passive-aggressive view, others acknowledge that financial security and comfort might not always be possible for everyone. In a more realistic tone, a user remarks, "If life were so easy that diligence led to wealth, then the world's richest person would be the best worker bee. But that's not the case." This acknowledgment underscores the complexities of the economy and the role that factors like luck, connections, and a rapidly evolving job market can play in financial success. Some users are quick to criticize the notion that earning money the hard way should be avoided, with one tweet expressing, "The person who advises you to avoid hard-earned money is likely a scammer who profits off providing emotional value in exchange for exploitation." Others argue that while it's essential to find enjoyment and fulfillment in one's work, it's crucial not to shun or belittle those who choose to work in physically demanding or high-paying industries.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 5, tokens 117, triggered by: 0.87 Split 5, tokens 117, triggered by: 0.87
Overall, the Weibo discussions offer a fascinating insight into the complexities of the modern Chinese labor market and the work-life balance that people strive to achieve. As in many countries, striking the right balance between work and play is an ongoing challenge for many Chinese citizens. However, the conversations on Weibo signal an increasing awareness of the importance of finding meaningful, fulfilling, and financially rewarding work that doesn't necessitate excessive sacrifice or sufferance. In the end, as one user succinctly puts it, "Make sure you're earning your money in a way that brings you joy and satisfaction. Overall, the Weibo discussions offer a fascinating insight into the complexities of the modern Chinese labor market and the work-life balance that people strive to achieve. As in many countries, striking the right balance between work and play is an ongoing challenge for many Chinese citizens. However, the conversations on Weibo signal an increasing awareness of the importance of finding meaningful, fulfilling, and financially rewarding work that doesn't necessitate excessive sacrifice or sufferance. In the end, as one user succinctly puts it, "Make sure you're earning your money in a way that brings you joy and satisfaction.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 6, tokens 171, triggered by: 0.82 Split 6, tokens 171, triggered by: 0.82
That's the only way to ensure that your life doesn't become a never-ending cycle of hard work without any tangible progress." In this context, social media discussions focusing on the trials and tribulations of earning money serve not only as an outlet for venting frustrations but also as a means of promoting dialogue and shared understanding about the challenges faced by workers across all industries. These virtual conversations sparked by tweets and in-depth discussions likely resonate with a wide swath of Chinese citizens struggling to navigate the complexities of balancing a career that pays well with one that brings them joy, fulfillment, and a sense of purpose. As the discussions on Weibo continue to evolve and unfold, it is evident that the discourse around work, money, and life satisfaction holds the potential to inspire meaningful change and shift societal attitudes towards a more holistic, balanced, and humane understanding of success and prosperity. That's the only way to ensure that your life doesn't become a never-ending cycle of hard work without any tangible progress." In this context, social media discussions focusing on the trials and tribulations of earning money serve not only as an outlet for venting frustrations but also as a means of promoting dialogue and shared understanding about the challenges faced by workers across all industries. These virtual conversations sparked by tweets and in-depth discussions likely resonate with a wide swath of Chinese citizens struggling to navigate the complexities of balancing a career that pays well with one that brings them joy, fulfillment, and a sense of purpose. As the discussions on Weibo continue to evolve and unfold, it is evident that the discourse around work, money, and life satisfaction holds the potential to inspire meaningful change and shift societal attitudes towards a more holistic, balanced, and humane understanding of success and prosperity.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 7, tokens 72, triggered by: 0.80 Split 7, tokens 72, triggered by: 0.80
--- Note: The translated tweets and user quotes from Chinese to English were used as the foundation for the long-form news article. The author tried to maintain the integrity of the original content in the translation while adapting it to fit a journalistic format. No inaccuracies were introduced during translation, and the opinion-based nature of the original content was preserved while maintaining objectivity. --- Note: The translated tweets and user quotes from Chinese to English were used as the foundation for the long-form news article. The author tried to maintain the integrity of the original content in the translation while adapting it to fit a journalistic format. No inaccuracies were introduced during translation, and the opinion-based nature of the original content was preserved while maintaining objectivity.
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
Split 8, tokens 23, triggered by: final split Split 8, tokens 23, triggered by: final split
Heart count: 0/2 Note: The author did not include any Chinese characters in the final response. Collapse Heart count: 0/2 Note: The author did not include any Chinese characters in the final response. Collapse
---------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment