-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzigcmd
More file actions
executable file
·42 lines (34 loc) · 1.22 KB
/
zigcmd
File metadata and controls
executable file
·42 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env python
import fire
from ziggy import llm, database, agent, server
from ziggy.llm import DEFAULT_MODEL, DEFAULT_EMBED
# get model type
def get_model_loader(loader):
if loader == 'huggingface':
return llm.HuggingfaceModel
elif loader == 'llama.cpp':
return llm.LlamaCppModel
else:
raise Exception(f'Unknown model loader: {loader}')
# retrieval augmented generation
def rag(
path='.', pattern='*', model=DEFAULT_MODEL, embed=DEFAULT_EMBED, loader_type='huggingface',
prompt_type='llama', context=2048, onnx=False, delim='\n\n', minlen=1, maxlen=None,
host='127.0.0.1', port=8000, max_chunks=10
):
# load generation model
loader = get_model_loader(loader_type)
mod = loader(model, prompt_type=prompt_type, context=context)
# load embedding model
emb = llm.HuggingfaceEmbedding(embed, onnx=onnx)
# create database
db = database.FilesystemDatabase(
path=path, pattern=pattern, embed=emb, delim=delim, minlen=minlen, maxlen=maxlen
)
# create agent
ag = agent.ContextAgent(mod, emb, db)
# spin up server
server.serve(ag, host=host, port=port, max_chunks=max_chunks)
# main interface
if __name__ == '__main__':
fire.Fire(rag)