Skip to content

Commit a2436cf

Browse files
harini-venkataramanchandrasekharan-zipstackhari-kuriakose
authored
[FEAT] NoOp adapters for load testing (#109)
* Exception handling for Prompt Service * Initial commit for No Op Adapters for Load testing * Update src/unstract/sdk/adapters/embedding/no_op_embedding/src/static/json_schema.json Co-authored-by: Chandrasekharan M <[email protected]> Signed-off-by: harini-venkataraman <[email protected]> * Update src/unstract/sdk/adapters/llm/no_op_llm/src/__init__.py Co-authored-by: Chandrasekharan M <[email protected]> Signed-off-by: harini-venkataraman <[email protected]> * Update readme text Co-authored-by: Chandrasekharan M <[email protected]> Signed-off-by: harini-venkataraman <[email protected]> * Update ReadMe text * Remove sleep for test connections * Adding details for usabilitiy * Changing wait time data type to float * renaming methods * Update src/unstract/sdk/llm.py Co-authored-by: Hari John Kuriakose <[email protected]> Signed-off-by: harini-venkataraman <[email protected]> * Write extracted file * Removing check for NoOp from base * Renames to no-op folders * Version bump for SDK * File renames * Adding sleep for test connection --------- Signed-off-by: harini-venkataraman <[email protected]> Co-authored-by: Chandrasekharan M <[email protected]> Co-authored-by: Hari John Kuriakose <[email protected]>
1 parent 1f5a047 commit a2436cf

26 files changed

+616
-1
lines changed

src/unstract/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.51.0"
1+
__version__ = "0.52.0"
22

33

44
def get_sdk_version():
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unstract NoOp Embedding adapter for load testing
2+
3+
An embedding adapter that does not perform any operation. Waits for the configured time before returning a response. This can be useful to perform tests on the system
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["pdm-backend"]
3+
build-backend = "pdm.backend"
4+
5+
6+
[project]
7+
name = "unstract-no-op-embedding"
8+
version = "0.0.1"
9+
description = "NoOp Embedding"
10+
authors = [
11+
{name = "Zipstack Inc.", email = "[email protected]"},
12+
]
13+
dependencies = [
14+
]
15+
requires-python = ">=3.9"
16+
readme = "README.md"
17+
classifiers = [
18+
"Programming Language :: Python"
19+
]
20+
license = {text = "MIT"}
21+
22+
[tool.pdm.build]
23+
includes = ["src"]
24+
package-dir = "src"
25+
# source-includes = ["tests"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .no_op_embedding import NoOpEmbedding
2+
3+
metadata = {
4+
"name": NoOpEmbedding.__name__,
5+
"version": "1.0.0",
6+
"adapter": NoOpEmbedding,
7+
"description": "NoOp embedding adapter",
8+
"is_active": True,
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Any
2+
3+
from llama_index.core import MockEmbedding
4+
5+
6+
class NoOpCustomEmbedding(MockEmbedding):
7+
8+
embed_dim: int
9+
10+
def __init__(self, embed_dim: int, wait_time: float, **kwargs: Any) -> None:
11+
"""Init params."""
12+
super().__init__(embed_dim=embed_dim, **kwargs, wait_time=wait_time)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import time
3+
from typing import Any
4+
5+
from llama_index.core.embeddings import BaseEmbedding
6+
7+
from unstract.sdk.adapters.embedding.embedding_adapter import EmbeddingAdapter
8+
from unstract.sdk.adapters.embedding.no_op.src.no_op_custom_embedding import (
9+
NoOpCustomEmbedding,
10+
)
11+
12+
13+
class NoOpEmbedding(EmbeddingAdapter):
14+
def __init__(self, settings: dict[str, Any]):
15+
super().__init__("NoOpCustomEmbedding")
16+
self.config = settings
17+
18+
@staticmethod
19+
def get_id() -> str:
20+
return "noOpEmbedding|ff223003-fee8-4079-b288-e86215e6b39a"
21+
22+
@staticmethod
23+
def get_name() -> str:
24+
return "No Op Embedding"
25+
26+
@staticmethod
27+
def get_description() -> str:
28+
return "No Op Embedding"
29+
30+
@staticmethod
31+
def get_icon() -> str:
32+
return "/icons/adapter-icons/noOpEmbedding.png"
33+
34+
@staticmethod
35+
def get_provider() -> str:
36+
return "NoOp"
37+
38+
@staticmethod
39+
def get_json_schema() -> str:
40+
f = open(f"{os.path.dirname(__file__)}/static/json_schema.json")
41+
schema = f.read()
42+
f.close()
43+
return schema
44+
45+
def get_embedding_instance(self) -> BaseEmbedding:
46+
embedding: BaseEmbedding = NoOpCustomEmbedding(
47+
embed_dim=1, wait_time=self.config.get("wait_time")
48+
)
49+
return embedding
50+
51+
def test_connection(self) -> bool:
52+
time.sleep(self.config.get("wait_time"))
53+
return True
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "No-op",
3+
"type": "object",
4+
"required": [
5+
"adapter_name",
6+
"wait_time"
7+
],
8+
"properties": {
9+
"adapter_name": {
10+
"type": "string",
11+
"title": "Name",
12+
"default": "no-op-embedding",
13+
"description": "Provide a unique name for this No Op adapter instance. Example: no-op-instance-1"
14+
},
15+
"wait_time": {
16+
"type": "number",
17+
"title": "Wait time (in seconds)",
18+
"default": "0",
19+
"description": "Provide the time to wait (in seconds) before returning the response"
20+
}
21+
}
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unstract NoOp LLM adapter for load testing
2+
3+
An LLM adapter that does not perform any operation. Waits for the configured time before returning a response. This can be useful to perform tests on the system
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["pdm-backend"]
3+
build-backend = "pdm.backend"
4+
5+
6+
[project]
7+
name = "unstract-no-op-llm"
8+
version = "0.0.1"
9+
description = "noOp LLM"
10+
authors = [
11+
{name = "Zipstack Inc.", email = "[email protected]"},
12+
]
13+
dependencies = [
14+
]
15+
requires-python = ">=3.9"
16+
readme = "README.md"
17+
classifiers = [
18+
"Programming Language :: Python"
19+
]
20+
license = {text = "MIT"}
21+
22+
[tool.pdm.build]
23+
includes = ["src"]
24+
package-dir = "src"
25+
# source-includes = ["tests"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from unstract.sdk.adapters.llm.no_op.src.no_op_llm import NoOpLLM
2+
3+
metadata = {
4+
"name": NoOpLLM.__name__,
5+
"version": "1.0.0",
6+
"adapter": NoOpLLM,
7+
"description": "NoOp LLM adapter",
8+
"is_active": True,
9+
}
10+
11+
__all__ = ["NoOpLLM"]

0 commit comments

Comments
 (0)