langchain-zunno 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ """
2
+ LangChain Zunno Integration
3
+
4
+ A LangChain integration for Zunno LLM and Embeddings.
5
+ """
6
+
7
+ from .llm import ZunnoLLM, create_zunno_llm
8
+ from .embeddings import ZunnoLLMEmbeddings, create_zunno_embeddings
9
+
10
+ __version__ = "0.1.0"
11
+ __author__ = "Amit Kumar"
12
+ __email__ = "amit@zunno.ai"
13
+
14
+ __all__ = [
15
+ "ZunnoLLM",
16
+ "ZunnoLLMEmbeddings",
17
+ "create_zunno_llm",
18
+ "create_zunno_embeddings",
19
+ ]
@@ -0,0 +1,115 @@
1
+ """
2
+ LangChain Embeddings integration for Zunno.
3
+ """
4
+
5
+ from typing import List
6
+ from langchain.embeddings.base import Embeddings
7
+ import requests
8
+
9
+
10
+ class ZunnoLLMEmbeddings(Embeddings):
11
+ """Zunno Embeddings wrapper for LangChain."""
12
+
13
+ model_name: str
14
+ base_url: str = "http://15.206.124.44/v1/text-embeddings"
15
+ timeout: int = 300
16
+
17
+ def __init__(self, model_name: str, base_url: str = None, timeout: int = 300):
18
+ super().__init__()
19
+ self.model_name = model_name
20
+ if base_url:
21
+ self.base_url = base_url
22
+ self.timeout = timeout
23
+
24
+ def embed_documents(self, texts: List[str]) -> List[List[float]]:
25
+ """Embed a list of documents."""
26
+ embeddings = []
27
+ for text in texts:
28
+ embedding = self.embed_query(text)
29
+ embeddings.append(embedding)
30
+ return embeddings
31
+
32
+ def embed_query(self, text: str) -> List[float]:
33
+ """Embed a single query."""
34
+ try:
35
+ payload = {
36
+ "model_name": self.model_name,
37
+ "text": text,
38
+ "options": {
39
+ "normalize": True
40
+ }
41
+ }
42
+
43
+ response = requests.post(
44
+ self.base_url,
45
+ json=payload,
46
+ timeout=self.timeout
47
+ )
48
+
49
+ if response.status_code != 200:
50
+ raise Exception(f"Zunno embeddings API error: {response.text}")
51
+
52
+ data = response.json()
53
+ embeddings = data.get("embeddings", [])
54
+
55
+ if not embeddings:
56
+ raise Exception("No embeddings returned from API")
57
+
58
+ return embeddings
59
+
60
+ except Exception as e:
61
+ raise Exception(f"Error getting text embeddings: {e}")
62
+
63
+ async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
64
+ """Async embed a list of documents."""
65
+ embeddings = []
66
+ for text in texts:
67
+ embedding = await self.aembed_query(text)
68
+ embeddings.append(embedding)
69
+ return embeddings
70
+
71
+ async def aembed_query(self, text: str) -> List[float]:
72
+ """Async embed a single query."""
73
+ try:
74
+ import httpx
75
+
76
+ async with httpx.AsyncClient(timeout=self.timeout) as client:
77
+ payload = {
78
+ "model_name": self.model_name,
79
+ "text": text,
80
+ "options": {
81
+ "normalize": True
82
+ }
83
+ }
84
+
85
+ response = await client.post(
86
+ self.base_url,
87
+ json=payload
88
+ )
89
+
90
+ if response.status_code != 200:
91
+ raise Exception(f"Zunno embeddings API error: {response.text}")
92
+
93
+ data = response.json()
94
+ embeddings = data.get("embeddings", [])
95
+
96
+ if not embeddings:
97
+ raise Exception("No embeddings returned from API")
98
+
99
+ return embeddings
100
+
101
+ except Exception as e:
102
+ raise Exception(f"Error getting text embeddings: {e}")
103
+
104
+
105
+ def create_zunno_embeddings(
106
+ model_name: str,
107
+ base_url: str = "http://15.206.124.44/v1/text-embeddings",
108
+ timeout: int = 300
109
+ ) -> ZunnoLLMEmbeddings:
110
+ """Create a Zunno Embeddings instance."""
111
+ return ZunnoLLMEmbeddings(
112
+ model_name=model_name,
113
+ base_url=base_url,
114
+ timeout=timeout
115
+ )
langchain_zunno/llm.py ADDED
@@ -0,0 +1,130 @@
1
+ """
2
+ LangChain LLM integration for Zunno.
3
+ """
4
+
5
+ from typing import Any, List, Optional, Dict
6
+ from langchain.llms.base import LLM
7
+ from langchain.callbacks.manager import CallbackManagerForLLMRun
8
+ import requests
9
+
10
+
11
+ class ZunnoLLM(LLM):
12
+ """Zunno LLM wrapper for LangChain."""
13
+
14
+ model_name: str
15
+ base_url: str = "http://15.206.124.44/v1/prompt-response"
16
+ temperature: float = 0.7
17
+ max_tokens: Optional[int] = None
18
+ timeout: int = 300
19
+
20
+ @property
21
+ def _llm_type(self) -> str:
22
+ """Return type of LLM."""
23
+ return "zunno"
24
+
25
+ @property
26
+ def _identifying_params(self) -> Dict[str, Any]:
27
+ """Get the identifying parameters."""
28
+ return {
29
+ "model_name": self.model_name,
30
+ "temperature": self.temperature,
31
+ "max_tokens": self.max_tokens,
32
+ "base_url": self.base_url,
33
+ }
34
+
35
+ def _call(
36
+ self,
37
+ prompt: str,
38
+ stop: Optional[List[str]] = None,
39
+ run_manager: Optional[CallbackManagerForLLMRun] = None,
40
+ **kwargs: Any,
41
+ ) -> str:
42
+ """Call the Zunno API."""
43
+ try:
44
+ payload = {
45
+ "model_name": self.model_name,
46
+ "prompt": prompt,
47
+ "stream": False,
48
+ "options": {
49
+ "temperature": self.temperature,
50
+ }
51
+ }
52
+
53
+ if self.max_tokens:
54
+ payload["options"]["num_predict"] = self.max_tokens
55
+
56
+ if stop:
57
+ payload["options"]["stop"] = stop
58
+
59
+ response = requests.post(
60
+ self.base_url,
61
+ json=payload,
62
+ timeout=self.timeout
63
+ )
64
+
65
+ if response.status_code != 200:
66
+ raise Exception(f"Zunno API error: {response.text}")
67
+
68
+ data = response.json()
69
+ return data.get("response", "")
70
+
71
+ except Exception as e:
72
+ raise Exception(f"Error calling Zunno LLM: {e}")
73
+
74
+ async def _acall(
75
+ self,
76
+ prompt: str,
77
+ stop: Optional[List[str]] = None,
78
+ run_manager: Optional[CallbackManagerForLLMRun] = None,
79
+ **kwargs: Any,
80
+ ) -> str:
81
+ """Async call to the Zunno API."""
82
+ try:
83
+ import httpx
84
+
85
+ async with httpx.AsyncClient(timeout=self.timeout) as client:
86
+ payload = {
87
+ "model_name": self.model_name,
88
+ "prompt": prompt,
89
+ "stream": False,
90
+ "options": {
91
+ "temperature": self.temperature,
92
+ }
93
+ }
94
+
95
+ if self.max_tokens:
96
+ payload["options"]["num_predict"] = self.max_tokens
97
+
98
+ if stop:
99
+ payload["options"]["stop"] = stop
100
+
101
+ response = await client.post(
102
+ self.base_url,
103
+ json=payload
104
+ )
105
+
106
+ if response.status_code != 200:
107
+ raise Exception(f"Zunno API error: {response.text}")
108
+
109
+ data = response.json()
110
+ return data.get("response", "")
111
+
112
+ except Exception as e:
113
+ raise Exception(f"Error calling Zunno LLM: {e}")
114
+
115
+
116
+ def create_zunno_llm(
117
+ model_name: str,
118
+ temperature: float = 0.7,
119
+ max_tokens: Optional[int] = None,
120
+ base_url: str = "http://15.206.124.44/v1/prompt-response",
121
+ timeout: int = 300
122
+ ) -> ZunnoLLM:
123
+ """Create a Zunno LLM instance."""
124
+ return ZunnoLLM(
125
+ model_name=model_name,
126
+ temperature=temperature,
127
+ max_tokens=max_tokens,
128
+ base_url=base_url,
129
+ timeout=timeout
130
+ )
@@ -1,9 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-zunno
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: LangChain integration for Zunno LLM and Embeddings
5
- Home-page: https://github.com/zunno/langchain-zunno
6
- Author: Amit Kumar
7
5
  Author-email: Amit Kumar <amit@zunno.ai>
8
6
  Maintainer-email: Amit Kumar <amit@zunno.ai>
9
7
  License: MIT
@@ -38,10 +36,7 @@ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
38
36
  Requires-Dist: black>=22.0.0; extra == "dev"
39
37
  Requires-Dist: isort>=5.0.0; extra == "dev"
40
38
  Requires-Dist: flake8>=4.0.0; extra == "dev"
41
- Dynamic: author
42
- Dynamic: home-page
43
39
  Dynamic: license-file
44
- Dynamic: requires-python
45
40
 
46
41
  # LangChain Zunno Integration
47
42
 
@@ -0,0 +1,8 @@
1
+ langchain_zunno/__init__.py,sha256=f8gMSVjaRKOQ-wlkVkA_mUhx-aVQQqhMRtEMFX7F7ec,394
2
+ langchain_zunno/embeddings.py,sha256=jGUZyD7wK85xMMEH1KcNdLUcrlAQw7jJhCkXZmidc0A,3632
3
+ langchain_zunno/llm.py,sha256=vJRdnimXg9LmKhwbAFynCShbZb_oTtt5o2wV8NnO-8E,3841
4
+ langchain_zunno-0.1.1.dist-info/licenses/LICENSE,sha256=dfF1ZH0fV045UpyRp_biKmKgCnMzhtoI3LDb38A3BTY,1062
5
+ langchain_zunno-0.1.1.dist-info/METADATA,sha256=kIdJUlH4dJXe55y9wD23KIfq-B28ymDvljtajaFEsV0,5087
6
+ langchain_zunno-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ langchain_zunno-0.1.1.dist-info/top_level.txt,sha256=BLZabFpkl0bwIZYVHVEWL5KgvEUzHWC_KuAsk9tm0t4,16
8
+ langchain_zunno-0.1.1.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ langchain_zunno
@@ -1,5 +0,0 @@
1
- langchain_zunno-0.1.0.dist-info/licenses/LICENSE,sha256=dfF1ZH0fV045UpyRp_biKmKgCnMzhtoI3LDb38A3BTY,1062
2
- langchain_zunno-0.1.0.dist-info/METADATA,sha256=kii1tui8XG2eyCZ6rJFk8DRpCAULR0iUtu48cM1VcAE,5218
3
- langchain_zunno-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
- langchain_zunno-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5
- langchain_zunno-0.1.0.dist-info/RECORD,,
@@ -1 +0,0 @@
1
-