File size: 2,362 Bytes
84fadff
 
 
4d32a09
84fadff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80889ba
84fadff
 
 
 
 
4d32a09
84fadff
80889ba
84fadff
80889ba
84fadff
 
 
 
 
 
 
 
 
 
 
 
4d32a09
84fadff
 
 
80889ba
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr
import requests
import json

def http_bot(prompt, history, system_prompt, endpoint_url):
    # Initialize the formatted_chat string with the system prompt
    formatted_chat = f"{system_prompt}\n"
    
    # Append previous history if available
    if history:
        for user_text, assistant_text in history:
            formatted_chat += f"USER: {user_text}\nASSISTANT: {assistant_text}\n"

    # Add the current prompt and assistant placeholder
    formatted_chat += f"USER: {prompt}\nASSISTANT: "
    print(formatted_chat)

    headers = {"User-Agent": "vLLM Client"}
    pload = {
        "prompt": formatted_chat,
        "stream": True,
        "max_tokens": 3000,
    }
    

    response = requests.post(endpoint_url,
                             headers=headers,
                             json=pload,
                             stream=True)
 
    for chunk in response.iter_lines(chunk_size=8192,
                                     decode_unicode=False,
                                     delimiter=b"\0"):
        if chunk:
            data = json.loads(chunk.decode("utf-8"))
            output = data["text"][0]
        
            yield output[len(formatted_chat):]




with gr.Blocks(theme=gr.themes.Soft(), title="DanskGPT") as demo:
    gr.Markdown("# DanskGPT")
    gr.Markdown("Et dansk alternativ til ChatGPT der kører lokalt.")
    system_prompt = gr.Textbox(value="Du er en hjælpsom dansk AI-assistent. Dit job er at svare på brugerens forespørgsel. Hvis du ikke kender svaret, skal du sige det i stedet for at videregive falsk information.",
                                label="System besked")
    endpoint_url = gr.Textbox(label="Endpoint url", value="https://tgmzp270z5de7f-8000.proxy.runpod.net/generate", render=False)


    gr.ChatInterface(
        http_bot,
        additional_inputs=[system_prompt, endpoint_url],
        clear_btn=None,
        undo_btn=None,
        retry_btn=None,
        submit_btn="Send",
        
    )

    gr.Markdown("Version 1 - chatmodel trænet på data op til 31-06-2023.")
    gr.Markdown("Lavet af Mads Henrichsen - Kontakt: [email protected]")
    gr.Markdown("Bemærk: DanskGPT producerer ikke nødvendigvis sandfærdig information - der er en ny model på vej der er meget bedre til dette.")

demo.queue(concurrency_count=100).launch(share=True)