File size: 1,103 Bytes
ea0d3c0
4c7cb3d
 
 
 
 
 
 
 
a1b2cdc
4c7cb3d
dbc3c4a
4c7cb3d
 
 
 
 
1d97b1b
 
 
4c7cb3d
f219d72
3b01ff0
4c7cb3d
 
c3afaf7
f219d72
c3afaf7
1d97b1b
4c7cb3d
3b01ff0
 
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

from typing import Iterator



model_id = 'xuqinyang/baichuan-13b-chat-ggml-int4'

from huggingface_hub import snapshot_download

snapshot_download(model_id, local_dir="./")
from llama_cpp import Llama
llm = Llama(model_path="./ggml-model-q4_0.bin", n_ctx=4096,seed=-1,n_threads=4)

def run(message: str,
        chat_history: list[tuple[str, str]],
        system_prompt: str,
        max_new_tokens: int = 1024,
        temperature: float = 0.3,
        top_p: float = 0.85,
        top_k: int = 5) -> Iterator[str]:
    history = []
    print(chat_history)
    result=""
    for i in chat_history:
        history.append({"role": "user", "content": i[0]})
        history.append({"role": "assistant", "content": i[1]})
    print(history)
    history.append({"role": "user", "content": message})
    for response in llm.create_chat_completion(history,stream=True,max_tokens=-1,temperature=temperature,top_k=top_k,top_p=top_p,repeat_penalty=1.1):
        if "content" in response["choices"][0]["delta"]:
            result = result + response["choices"][0]["delta"]["content"]
            yield result