alpaka 0.1.13__tar.gz

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.
alpaka-0.1.13/PKG-INFO ADDED
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.1
2
+ Name: alpaka
3
+ Version: 0.1.13
4
+ Summary:
5
+ Author: jhnnsrs
6
+ Author-email: jhnnsrs@gmail.com
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
13
+ Requires-Dist: koil (>=1.0.0)
14
+ Requires-Dist: ollama (>=0.3.3,<0.4.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # alpaka
18
+
19
+ [![codecov](https://codecov.io/gh/jhnnsrs/akuire/branch/master/graph/badge.svg?token=UGXEA2THBV)](https://codecov.io/gh/jhnnsrs/akuire)
20
+ [![PyPI version](https://badge.fury.io/py/akuire.svg)](https://pypi.org/project/akuire/)
21
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://pypi.org/project/akuire/)
22
+ ![Maintainer](https://img.shields.io/badge/maintainer-jhnnsrs-blue)
23
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/akuire.svg)](https://pypi.python.org/pypi/akuire/)
24
+ [![PyPI status](https://img.shields.io/pypi/status/akuire.svg)](https://pypi.python.org/pypi/akuire/)
25
+
26
+ Alpaka is the arkitekt compüability layer around ollama and allows your arkitekt apps to connect to an ollama server
27
+
28
+
29
+
30
+
@@ -0,0 +1,13 @@
1
+ # alpaka
2
+
3
+ [![codecov](https://codecov.io/gh/jhnnsrs/akuire/branch/master/graph/badge.svg?token=UGXEA2THBV)](https://codecov.io/gh/jhnnsrs/akuire)
4
+ [![PyPI version](https://badge.fury.io/py/akuire.svg)](https://pypi.org/project/akuire/)
5
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://pypi.org/project/akuire/)
6
+ ![Maintainer](https://img.shields.io/badge/maintainer-jhnnsrs-blue)
7
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/akuire.svg)](https://pypi.python.org/pypi/akuire/)
8
+ [![PyPI status](https://img.shields.io/pypi/status/akuire.svg)](https://pypi.python.org/pypi/akuire/)
9
+
10
+ Alpaka is the arkitekt compüability layer around ollama and allows your arkitekt apps to connect to an ollama server
11
+
12
+
13
+
@@ -0,0 +1,45 @@
1
+ from alpaka.alpaka import Alpaka
2
+ from herre_next import Herre
3
+ from fakts_next import Fakts
4
+ from typing import Optional
5
+
6
+ from arkitekt_next.base_models import Manifest
7
+
8
+ from arkitekt_next.service_registry import (
9
+ Params,
10
+ )
11
+ from arkitekt_next.base_models import Requirement
12
+
13
+
14
+ class ArkitektAlpaka(Alpaka):
15
+ endpoint_url: str = "fake_url"
16
+ fakts: Fakts
17
+ herre: Herre
18
+
19
+ async def aconnect(self, *args, **kwargs):
20
+ endpoint_url = await self.fakts.get("alpaka.endpoint_url")
21
+ self.endpoint_url = endpoint_url
22
+ await super().aconnect(*args, **kwargs)
23
+
24
+ class Config:
25
+ arbitrary_types_allowed = True
26
+
27
+
28
+ def init_services(service_builder_registry):
29
+ def build_arkitekt_next_alpaka(
30
+ fakts: Fakts, herre: Herre, params: Params, manifest: Manifest
31
+ ):
32
+ return ArkitektAlpaka(
33
+ fakts=fakts,
34
+ herre=herre,
35
+ )
36
+
37
+ service_builder_registry.register(
38
+ "alpaka",
39
+ build_arkitekt_next_alpaka,
40
+ Requirement(
41
+ key="alpaka",
42
+ service="io.ollama.ollama",
43
+ description="An instance of Ollama to chat with",
44
+ ),
45
+ )
@@ -0,0 +1,2 @@
1
+ from .alpaka import Alpaka
2
+ from .funcs import chat, achat
@@ -0,0 +1,41 @@
1
+ from typing import TypeVar
2
+ from koil.composition.base import KoiledModel
3
+ from alpaka.vars import current_alpaka
4
+ import asyncio
5
+ from ollama import AsyncClient
6
+
7
+
8
+ T = TypeVar("T")
9
+
10
+
11
+ class Alpaka(KoiledModel):
12
+ endpoint_url: str
13
+ _client: AsyncClient = None
14
+
15
+ async def aconnect(self, **kwargs):
16
+ self._client = AsyncClient(self.endpoint_url)
17
+
18
+ async def chat(self, *args, **kwargs):
19
+ if not self._client:
20
+ await self.aconnect()
21
+
22
+ return await self._client.chat(*args, **kwargs)
23
+
24
+ async def pull(self, *args, **kwargs):
25
+ if not self._client:
26
+ await self.aconnect()
27
+
28
+ return await self._client.pull(*args, **kwargs)
29
+
30
+ async def __aenter__(self: T) -> T:
31
+ current_alpaka.set(self)
32
+ return await super().__aenter__()
33
+
34
+ async def __aexit__(self, exc_type, exc_value, traceback):
35
+ await super().__aexit__(exc_type, exc_value, traceback)
36
+ if self._client:
37
+ print("Closing client???", self._client)
38
+ current_alpaka.set(None)
39
+
40
+ class Config:
41
+ arbitrary_types_allowed = True
@@ -0,0 +1,21 @@
1
+ from .vars import get_current_alpaka
2
+ from koil import unkoil
3
+
4
+
5
+ async def achat(*args, **kwargs):
6
+ alpaka = get_current_alpaka()
7
+ return await alpaka.chat(*args, **kwargs)
8
+
9
+
10
+ def chat(*args, **kwargs):
11
+ return unkoil(achat, *args, **kwargs)
12
+
13
+
14
+ async def apull(*args, **kwargs):
15
+ alpaka = get_current_alpaka()
16
+ print(args, kwargs)
17
+ return await alpaka.pull(*args, **kwargs)
18
+
19
+
20
+ def pull(*args, **kwargs):
21
+ return unkoil(apull, *args, **kwargs)
@@ -0,0 +1,12 @@
1
+ from contextvars import ContextVar
2
+
3
+
4
+ current_alpaka = ContextVar("current_alpaka", default=None)
5
+
6
+
7
+ def get_current_alpaka():
8
+ return current_alpaka.get()
9
+
10
+
11
+ def set_current_alpaka(value):
12
+ current_alpaka.set(value)
@@ -0,0 +1,31 @@
1
+ [tool.poetry]
2
+ name = "alpaka"
3
+ version = "0.1.13"
4
+ description = ""
5
+ authors = ["jhnnsrs <jhnnsrs@gmail.com>"]
6
+ readme = "README.md"
7
+ packages = [{ include = "alpaka" }]
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.10"
11
+ aiohttp = "^3.9.5"
12
+ koil = ">=1.0.0"
13
+ ollama = "^0.3.3"
14
+
15
+
16
+ [tool.poetry.group.dev.dependencies]
17
+ pytest-aiohttp = "^1.0.5"
18
+ pytest-cov = "^5.0.0"
19
+
20
+ [tool.poetry.scripts]
21
+ akuire = "akuire.__main__:main"
22
+
23
+ [tool.pytest.ini_options]
24
+ markers = [
25
+ "composition: test composition",
26
+ "external: test external",
27
+ ]
28
+
29
+ [build-system]
30
+ requires = ["poetry-core"]
31
+ build-backend = "poetry.core.masonry.api"