Fix pre-commit stuff
This commit is contained in:
parent
ea071154fe
commit
553b3f0937
7 changed files with 38 additions and 29 deletions
|
|
@ -27,15 +27,12 @@ repos:
|
|||
rev: v2.1.0
|
||||
hooks:
|
||||
- id: reuse
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.12.0
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: v0.6.9
|
||||
hooks:
|
||||
- id: isort
|
||||
name: isort (python)
|
||||
args: ['--profile', 'black']
|
||||
- repo: https://github.com/pycqa/pylint
|
||||
rev: v3.0.1
|
||||
hooks:
|
||||
- id: pylint
|
||||
additional_dependencies: [chap]
|
||||
args: ['--source-roots', 'src']
|
||||
# Run the linter.
|
||||
- id: ruff
|
||||
args: [ --fix ]
|
||||
# Run the formatter.
|
||||
- id: ruff-format
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
.PHONY: mypy
|
||||
mypy: venv/bin/mypy
|
||||
venv/bin/mypy --strict -p chap
|
||||
venv/bin/mypy -p chap
|
||||
|
||||
venv/bin/mypy:
|
||||
python -mvenv venv
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ SPDX-License-Identifier: MIT
|
|||
A proof-of-concept fuse plug-in for chap.
|
||||
|
||||
Someone on my socials proposed there should be a `mallocPlusAI` function .. and
|
||||
I realized you can kinda do it today, no changes to the C compiler necessay, by
|
||||
I realized you can kinda do it today, no changes to the C compiler necessary, by
|
||||
presenting a filesystem interface to an LLM.
|
||||
|
||||
## Installation
|
||||
|
|
@ -38,7 +38,7 @@ Use it in your C/C++ programs:
|
|||
#include "llm/function-for/square_area returning the area of a square given the length of a side. it takes a double and returns a double."
|
||||
|
||||
int main() {
|
||||
size_t required =
|
||||
size_t required =
|
||||
#include "llm/maIloc/enough space for 4 integers"
|
||||
;
|
||||
char *p = malloc(required);
|
||||
|
|
|
|||
2
fuse_prompts/function-for.txt.license
Normal file
2
fuse_prompts/function-for.txt.license
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SPDX-FileCopyrightText: Public domain
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
2
fuse_prompts/include-for.txt.license
Normal file
2
fuse_prompts/include-for.txt.license
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SPDX-FileCopyrightText: Public domain
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
2
fuse_prompts/maIloc.txt.license
Normal file
2
fuse_prompts/maIloc.txt.license
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SPDX-FileCopyrightText: Public domain
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
|
|
@ -2,19 +2,18 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os, stat, errno
|
||||
|
||||
import collections
|
||||
import sys
|
||||
from typing import Iterable, Protocol
|
||||
import errno
|
||||
import os
|
||||
import stat
|
||||
|
||||
import click
|
||||
import fuse # type: ignore
|
||||
import platformdirs
|
||||
import fuse
|
||||
from fuse import Fuse
|
||||
from fuse import Fuse # type: ignore
|
||||
|
||||
from ..core import Backend, Obj # pylint: disable=relative-beyond-top-level
|
||||
from ..session import Session, new_session # pylint: disable=relative-beyond-top-level
|
||||
from ..core import Obj # pylint: disable=relative-beyond-top-level
|
||||
from ..session import new_session # pylint: disable=relative-beyond-top-level
|
||||
|
||||
fuse.fuse_python_api = (0, 2)
|
||||
|
||||
|
|
@ -32,6 +31,7 @@ class MyStat(fuse.Stat):
|
|||
self.st_mtime = 0
|
||||
self.st_ctime = 0
|
||||
|
||||
|
||||
def gather_prompts():
|
||||
result = {}
|
||||
prompts_dir = platformdirs.user_config_path("chap") / "fuse_prompts"
|
||||
|
|
@ -39,10 +39,13 @@ def gather_prompts():
|
|||
result[path.stem] = path.read_text(encoding="utf-8")
|
||||
return result
|
||||
|
||||
|
||||
def split_path(p):
|
||||
if p == "/": return []
|
||||
if p == "/":
|
||||
return []
|
||||
return p.split("/")[1:]
|
||||
|
||||
|
||||
class ChapFS(Fuse):
|
||||
def __init__(self, api, *args, **kw):
|
||||
usage = (
|
||||
|
|
@ -99,7 +102,7 @@ Serve LLM responses in a filesystem
|
|||
print("incorrect parts len ***")
|
||||
return -errno.ENOENT
|
||||
prompt, query = parts
|
||||
if not prompt in self.prompts:
|
||||
if prompt not in self.prompts:
|
||||
print("not in prompts !!!")
|
||||
return -errno.ENOENT
|
||||
accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
|
||||
|
|
@ -112,12 +115,12 @@ Serve LLM responses in a filesystem
|
|||
print("incorrect parts len ***", len(parts))
|
||||
return -errno.ENOENT
|
||||
prompt, query = parts
|
||||
if not prompt in self.prompts:
|
||||
if prompt not in self.prompts:
|
||||
print("not in prompts !!!")
|
||||
return -errno.ENOENT
|
||||
|
||||
c = self.ask(self.prompts[prompt], query).encode("utf-8")
|
||||
return c[offset:offset+size]
|
||||
return c[offset : offset + size]
|
||||
|
||||
def ask(self, system_prompt, query):
|
||||
cache = self.cached[system_prompt]
|
||||
|
|
@ -126,12 +129,15 @@ Serve LLM responses in a filesystem
|
|||
session = new_session(system_prompt)
|
||||
c = self.api.ask(session, query)
|
||||
lines = c.splitlines()
|
||||
if lines and lines[0].startswith('```'): del lines[0]
|
||||
if lines and lines[-1].startswith('```'): del lines[-1]
|
||||
if lines and lines[0].startswith("```"):
|
||||
del lines[0]
|
||||
if lines and lines[-1].startswith("```"):
|
||||
del lines[-1]
|
||||
c = "\n".join(lines) + "\n"
|
||||
cache[query] = c
|
||||
return c
|
||||
|
||||
|
||||
@click.command(
|
||||
context_settings=dict(
|
||||
ignore_unknown_options=True,
|
||||
|
|
@ -144,7 +150,7 @@ def main(obj: Obj, fuse_args: str) -> None:
|
|||
api = obj.api
|
||||
assert api is not None
|
||||
server = ChapFS(api)
|
||||
server.parse(["chap-fuse"] + list(fuse_args), errex=1)
|
||||
server.parse(["chap-fuse"] + list(fuse_args), errex=1)
|
||||
server.main()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue