Skip to content

Commit dc581d7

Browse files
author
Judd
committed
move examples related to bindings to scripts folder
1 parent 499c5c3 commit dc581d7

File tree

12 files changed

+65
-289
lines changed

12 files changed

+65
-289
lines changed

bindings/chatllm.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class LibChatLLM:
2323
def __init__(self, lib: str = '') -> None:
2424

2525
if lib == '':
26-
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
27-
lib = os.path.join(this_dir, 'libchatllm.')
28-
if sys.platform == 'win32':
29-
lib = lib + 'dll'
30-
elif sys.platform == 'darwin':
31-
lib = lib + 'dylib'
32-
else:
33-
lib = lib + 'so'
26+
lib = os.path.dirname(os.path.abspath(sys.argv[0]))
27+
lib = os.path.join(lib, 'libchatllm.')
28+
if sys.platform == 'win32':
29+
lib = lib + 'dll'
30+
elif sys.platform == 'darwin':
31+
lib = lib + 'dylib'
32+
else:
33+
lib = lib + 'so'
3434

3535
if sys.platform == 'win32':
3636
self._lib = windll.LoadLibrary(lib)
@@ -327,10 +327,10 @@ def demo_streamer():
327327
for s in streamer.chat(s):
328328
print(s, end='', flush=True)
329329

330-
def demo_simple(params, cls = ChatLLM):
330+
def demo_simple(params, cls = ChatLLM, lib_path: str =''):
331331
global llm
332332
signal.signal(signal.SIGINT, handler)
333-
llm = cls(LibChatLLM(), params)
333+
llm = cls(LibChatLLM(lib_path), params)
334334

335335
while True:
336336
s = input('You > ')

bindings/openai_api.ts

Lines changed: 0 additions & 252 deletions
This file was deleted.

docs/binding.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ For example,
3838

3939
### Web demo
4040

41-
There is also a [Chatbot](../bindings/chatllm_st.py) powered by [Streamlit](https://streamlit.io/):
41+
There is also a [Chatbot](../scripts/chatllm_st.py) powered by [Streamlit](https://streamlit.io/):
4242

4343
![](chatbot_st.png)
4444

@@ -52,7 +52,7 @@ Note: "STOP" function is not implemented yet.
5252

5353
### OpenAI Compatible API
5454

55-
[Here](../bindings/openai_api.py) is a server providing OpenAI Compatible API. Note that most of
55+
[Here](../scripts/openai_api.py) is a server providing OpenAI Compatible API. Note that most of
5656
the parameters are ignored. With this, one can start two servers one for chatting and one for
5757
code completion (a base model supporting fill-in-the-middle is required), and setup a fully functional
5858
local copilot in Visual Studio Code with the help of tools like [twinny](https://github.com/rjmacarthy/twinny).
@@ -98,10 +98,6 @@ bun run chatllm.ts -i -m path/to/model
9898

9999
WARNING: Bun [looks buggy on Linux](https://github.com/oven-sh/bun/issues/10242).
100100

101-
### OpenAI Compatible API
102-
103-
[Here](../bindings/openai_api.ts) is a work in progress.
104-
105101
## Other Languages
106102

107103
`libchatllm` can be utilized by all languages that can call into dynamic libraries. Take C as an example:

docs/fun.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ Before shuffling a model's layers, use `--show` to view basic information about
5353

5454
## Talk to Each Other
5555

56-
[Here](../bindings/crosstask.py) is a simple program to let two LLMs talk to each other. Both are willing to assist each other,
56+
[Here](../scripts/crosstask.py) is a simple program to let two LLMs talk to each other. Both are willing to assist each other,
5757
so the conversation might go to full of "I'm here to assist you" quickly and is not quite fruitful.

docs/tool_calling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Some models support tool calling (function calling, or code interpreter). It would be much easier (and cool) to do tool calling in Python.
44
Demos of tool calling for these models are provided:
55

6-
* [ChatGLM3](../bindings/tool_glm3.py)
7-
* [GLM-4](../bindings/tool_glm4.py)
8-
* [Mistral-Instruct-7B-v0.3](../bindings/tool_mistral.py)
9-
* [QWen v1.5 & v2](../bindings/tool_qwen.py)
6+
* [ChatGLM3](../scripts/tool_glm3.py)
7+
* [GLM-4](../scripts/tool_glm4.py)
8+
* [Mistral-Instruct-7B-v0.3](../scripts/tool_mistral.py)
9+
* [QWen v1.5 & v2](../scripts/tool_qwen.py)
1010

1111
## Precondition
1212

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import streamlit as st
22
import sys
3+
import sys, os
4+
5+
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
6+
PATH_BINDS = os.path.join(this_dir, '..', 'bindings')
7+
sys.path.append(PATH_BINDS)
8+
39
from chatllm import ChatLLM, LibChatLLM, ChatLLMStreamer
410

511
st.title("ChatLLM Chatbot Demo")
612

713
if 'llm' not in st.session_state:
814
args = sys.argv[1:]
9-
st.session_state.llm = ChatLLM(LibChatLLM(), args, False)
15+
st.session_state.llm = ChatLLM(LibChatLLM(PATH_BINDS), args, False)
1016
st.session_state.llm_streamer = ChatLLMStreamer(st.session_state.llm)
1117
st.session_state.banner = st.session_state.llm_streamer.flush_output()
1218

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Let two LLMs talk to each other!
22

3+
import sys, os, signal
4+
5+
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
6+
PATH_BINDS = os.path.join(this_dir, '..', 'bindings')
7+
sys.path.append(PATH_BINDS)
8+
39
from chatllm import ChatLLM, LibChatLLM
4-
import signal, sys
510

611
class ForwardChatLLM(ChatLLM):
712
chunk_acc = ''
@@ -44,8 +49,8 @@ def handler(signal_received, frame):
4449
print(f"usage: python crosstalk.py path/to/model/A path/to/model/B initial_input")
4550
exit(-1)
4651

47-
model_a = ForwardChatLLM(LibChatLLM(), ['-m', args[0], '-i'], True)
48-
model_b = ForwardChatLLM(LibChatLLM(), ['-m', args[1], '-i'], True)
52+
model_a = ForwardChatLLM(LibChatLLM(PATH_BINDS), ['-m', args[0], '-i'], True)
53+
model_b = ForwardChatLLM(LibChatLLM(PATH_BINDS), ['-m', args[1], '-i'], True)
4954

5055
input = args[2]
5156
print('A > ' + input)

0 commit comments

Comments
 (0)