Skip to content

Commit

Permalink
Merge pull request #266 from aurelio-labs/anup/splitter-fix
Browse files Browse the repository at this point in the history
fix: video splitter -> type error
  • Loading branch information
jamescalam authored May 2, 2024
2 parents 29762f0 + dafd97d commit 4de9294
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
43 changes: 26 additions & 17 deletions docs/00-introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"d:\\Program_Installation\\anaconda\\envs\\rag\\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\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"from semantic_router import Route\n",
"\n",
Expand All @@ -91,7 +100,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -118,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -146,14 +155,14 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-04-19 18:34:06 INFO semantic_router.utils.logger local\u001b[0m\n"
"\u001b[32m2024-05-02 12:38:34 INFO semantic_router.utils.logger local\u001b[0m\n"
]
}
],
Expand All @@ -172,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -181,7 +190,7 @@
"RouteChoice(name='politics', function_call=None, similarity_score=None)"
]
},
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -192,7 +201,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -201,7 +210,7 @@
"RouteChoice(name='chitchat', function_call=None, similarity_score=None)"
]
},
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -219,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -228,7 +237,7 @@
"RouteChoice(name=None, function_call=None, similarity_score=None)"
]
},
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -246,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -256,7 +265,7 @@
" RouteChoice(name='chitchat', function_call=None, similarity_score=0.8356239688161808)]"
]
},
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -267,7 +276,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -276,7 +285,7 @@
"[]"
]
},
"execution_count": 12,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -309,7 +318,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 0 additions & 2 deletions semantic_router/encoders/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def __call__(self, docs: List[str], truncate: bool = True) -> List[List[float]]:
if truncate:
# check if any document exceeds token limit and truncate if so
for i in range(len(docs)):
logger.info(f"Document {i+1} length: {len(docs[i])}")
docs[i] = self._truncate(docs[i])
logger.info(f"Document {i+1} trunc length: {len(docs[i])}")

# Exponential backoff
for j in range(1, 7):
Expand Down
7 changes: 3 additions & 4 deletions semantic_router/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from enum import Enum
from typing import List, Optional

from typing import List, Optional, Union, Any
from pydantic.v1 import BaseModel


Expand Down Expand Up @@ -52,15 +51,15 @@ def __str__(self):


class DocumentSplit(BaseModel):
docs: List[str]
docs: List[Union[str, Any]]
is_triggered: bool = False
triggered_score: Optional[float] = None
token_count: Optional[int] = None
metadata: Optional[dict] = None

@property
def content(self) -> str:
return " ".join(self.docs)
return " ".join([doc if isinstance(doc, str) else "" for doc in self.docs])


class Metric(Enum):
Expand Down

0 comments on commit 4de9294

Please sign in to comment.