Skip to content

Commit

Permalink
new implementation of: llama/llama_cli_ctypes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mtasic85 committed Jul 10, 2024
1 parent d5ab026 commit 8b8eeaf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
# C extensions
*.so
*.o
*.a

# Distribution / packaging
.Python
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ python -B examples/demo_cffi.py
python -B examples/demo_ctypes.py
python -m http.server -d examples/demo_pyonide -b "0.0.0.0" 5000
```

```bash
make -j llama-cli-shared llama-cli-static GGML_NO_OPENMP=1 GGML_NO_LLAMAFILE=1
```
21 changes: 11 additions & 10 deletions llama/llama_cli_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@

current_module_path = os.path.abspath(__file__)
current_module_dir = os.path.dirname(current_module_path)
libllama_cli_path = os.path.join(current_module_dir, 'libllama-cli.so')
libllama_cli_path = os.path.join(current_module_dir, 'llama-cli.so')

lib = CDLL(libllama_cli_path)

lib.llama_cli_main.argtypes = [c_int, POINTER(c_char_p)]
lib.llama_cli_main.restype = c_int
# lib.llama_cli_main.argtypes = [c_int, POINTER(c_char_p)]
# lib.llama_cli_main.restype = c_int

lib.llama_get_metadata_as_json.argtypes = [c_int, POINTER(c_char_p)]
lib.llama_get_metadata_as_json.restype = c_void_p
# lib.llama_get_metadata_as_json.argtypes = [c_int, POINTER(c_char_p)]
# lib.llama_get_metadata_as_json.restype = c_void_p

lib.llama_free_metadata_as_json.argtypes = [c_void_p]
lib.llama_free_metadata_as_json.restype = None
# lib.llama_free_metadata_as_json.argtypes = [c_void_p]
# lib.llama_free_metadata_as_json.restype = None

FPRINTF_FUNC = CFUNCTYPE(c_int, c_void_p, c_char_p, c_char_p)
FFLUSH_FUNC = CFUNCTYPE(c_int, c_void_p)
# FPRINTF_FUNC = CFUNCTYPE(c_int, c_void_p, c_char_p, c_char_p)
# FFLUSH_FUNC = CFUNCTYPE(c_int, c_void_p)


'''
def fprintf_func(file_obj, fmt, arg, queue=None, callback=None, metadata=None):
content = arg.decode('utf-8')
Expand All @@ -58,7 +59,7 @@ def fprintf_func(file_obj, fmt, arg, queue=None, callback=None, metadata=None):
def fflush_func(file_obj):
return 0

'''

def _llama_cli_main(argc, argv, queue=None, callback=None, metadata=None):
r = lib.llama_cli_main(argc, argv)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 8b8eeaf

Please sign in to comment.