Skip to content

Commit 91ca920

Browse files
authored
Merge pull request #26 from ksadov/new-apis
Upgrade OpenAI API and add Together AI and llama.cpp as inference providers
2 parents 0fd6604 + f01dcc4 commit 91ca920

8 files changed

Lines changed: 241 additions & 142 deletions

File tree

README.md

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
This is an experimental tree-based writing interface for GPT-3. The code is actively being developed and thus
2+
This is an experimental tree-based writing interface for GPT-3. The code is actively being developed and thus
33
unstable and poorly documented.
44

55
# Features
@@ -8,33 +8,33 @@ unstable and poorly documented.
88
* Linear story view
99
* Tree nav bar
1010
* Edit mode
11-
12-
11+
12+
1313
* Tree view
1414
* Explore tree visually with mouse
1515
* Expand and collapse nodes
1616
* Change tree topology
1717
* Edit nodes in place
18-
19-
18+
19+
2020
* Navigation
2121
* Hotkeys
2222
* Bookmarks
2323
* Chapters
24-
* 'Visited' state
25-
24+
* 'Visited' state
25+
2626

2727
* Generation
2828
* Generate N children with GPT-3
29-
* Modify generation settings
29+
* Modify generation settings
3030
* Change hidden memory on a node-by-node basis
31-
31+
3232

3333
* File I/O
34-
* Open/save trees as JSON files
34+
* Open/save trees as JSON files
3535
* Work with trees in multiple tabs
3636
* Combine trees
37-
37+
3838

3939
# Demo
4040

@@ -57,7 +57,7 @@ ooo what features! wow so cool
5757
3. [Optional] Write ground truth continuation in the gray entry box at the bottom of the block multiverse interface. Blocks in ground truth trajectory will be colored black.
5858
4. Set model and [params](https://generative.ink/meta/block-multiverse/#generation-parameters) in top bar.
5959
5. Click `Propagate` to propagate plot the block multiverse
60-
6. Click on any of the blocks to zoom ("[renormalize](https://generative.ink/meta/block-multiverse/#renormalization)") to that block
60+
6. Click on any of the blocks to zoom ("[renormalize](https://generative.ink/meta/block-multiverse/#renormalization)") to that block
6161
7. Click `Propagate` again to plot future block multiverse starting from a renormalized frame
6262
8. Click `Reset zoom` to reset zoom level to initial position
6363
9. Click `Clear` to clear the block multiverse plot. Do this before generating a new block multiverse.
@@ -152,7 +152,7 @@ Click to split node: `Control-alt-click`
152152
Goto node by id: `Control-shift-g`
153153

154154

155-
### Organization
155+
### Organization
156156

157157
Toggle bookmark: `b`, `Control-b`
158158

@@ -246,16 +246,16 @@ Reset zoom: `Control-0`
246246

247247
# Instructions
248248

249-
## Python
249+
## Linux
250250

251251
0. Make sure you have tkinter installed
252252

253253
```sudo apt-get install python3-tk```
254254
1. Setup your python env (should be >= 3.9.13)
255-
256-
```python3 -m venv env```
255+
256+
```python3 -m venv env```
257257
```source env/bin/activate```
258-
1. Install requirements
258+
1. Install requirements
259259

260260
```pip install -r requirements.txt```
261261
2. [Optional] Set environmental variables for `OPENAI_API_KEY`, `GOOSEAI_API_KEY`, `AI21_API_KEY` (you can also use the settings options)
@@ -265,14 +265,43 @@ Reset zoom: `Control-0`
265265
4. Load a json tree
266266
5. Read :)
267267

268+
## Mac
269+
1. `conda create -n pyloom python=3.10`
270+
2. `conda activate pyloom`
271+
3. `pip install -r requirements-mac.txt`
272+
4. set the OPENAI_API_KEY env variable
273+
5. `python main.py`
274+
268275
## Docker
269276

270277
(Only tested on Linux.)
271278

272279
0. [Optional] Edit the Makefile with your API keys (you can also use the settings options)
273280
1. Run the make targets
274-
281+
275282
```make build```
276283
```make run```
277284
2. Load a json tree
278285
3. Read :)
286+
287+
# Local Inference with llama-cpp-python
288+
[llama.cpp](https://github.com/ggerganov/llama.cpp) lets you run models locally, and is especially useful for running models on Mac. [https://github.com/abetlen/llama-cpp-python] provides nice installation and a convenient API.
289+
290+
## Setup
291+
1. `conda create -n llama-cpp-local python=3.10; conda activate llama-cpp-local`
292+
2. Set your preferred backend before installing `llama-cpp-python`, as per [these instructions](https://github.com/abetlen/llama-cpp-python?tab=readme-ov-file#supported-backends). For instance, to infer on MPS: `CMAKE_ARGS="-DLLAMA_METAL=on"`
293+
3. `pip install 'llama-cpp-python[server]'`
294+
4. `pip install huggingface-hub`
295+
5. Now you can run the server with whatever .gguf model you desire from Huggingface, i.e: `python3 -m llama_cpp.server --hf_model_repo_id NousResearch/Meta-Llama-3-8B-GGUF --model 'Meta-Llama-3-8B-Q4_5_M.gguf' --port 8009`
296+
297+
## Inference
298+
1. `conda activate llama-cpp-local` and start your llama-cpp-python server.
299+
2. In a new terminal window, activate your `pyloom` environment and run `main.py`
300+
2. Enter configurations for your local model in Settings > Model config > Add model. By default, the llama-cpp-port-8009 model uses the following settings:
301+
```
302+
{
303+
'model': 'Meta-Llama-3-8B-Q4_5_M',
304+
'type': 'llama-cpp',
305+
'api_base': 'http://localhost:8009/v1',
306+
},
307+
```

components/modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ def __init__(self, callbacks, state):
19231923
self.add_path_button = None
19241924
self.reset_zoom_button = None
19251925
self.save_image_button = None
1926-
self.model_list = ["ada", "ada", "babbage", "curie", "davinci", "text-davinci-002", "text-davinci-003", "code-davinci-002", "gpt-neo-1-3b", "gpt-neo-2-7b", "gpt-j-6b", "gpt-neo-20b"]
1926+
self.model_list = ["davinci-002", 'llama-cpp-port-8009', "gpt-neo-1-3b", "gpt-neo-2-7b", "gpt-j-6b", "gpt-neo-20b"]
19271927

19281928
self.ground_truth_textbox = None
19291929
Module.__init__(self, 'wavefunction', callbacks, state)
@@ -1979,7 +1979,7 @@ def build(self, parent):
19791979

19801980
def set_config(self):
19811981
current_model = self.state.generation_settings['model']
1982-
self.model.set(current_model if current_model in self.model_list else "ada")
1982+
self.model.set(current_model if current_model in self.model_list else 'davinci-002')
19831983
self.max_depth.set(3)
19841984
self.threshold.set(0.1)
19851985

0 commit comments

Comments
 (0)