File size: 1,361 Bytes
3f7cfab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os

from h2ogpt_client import Client


def create_client(server_url: str = "") -> Client:
    server_url = server_url or os.getenv("H2OGPT_SERVER", "http://0.0.0.0:7860")
    return Client(server_url)


def test_text_completion():
    launch_server()

    client = create_client()
    r = client.text_completion.create("Hello world")
    assert r
    print(r)


async def test_text_completion_async():
    launch_server()

    client = create_client()
    r = await client.text_completion.create_async("Hello world")
    assert r
    print(r)


def test_chat_completion():
    launch_server()

    client = create_client()
    chat_context = client.chat_completion.create()

    chat1 = chat_context.chat("Hey!")
    assert chat1["user"] == "Hey!"
    assert chat1["gpt"]

    chat2 = chat_context.chat("How are you?")
    assert chat2["user"] == "How are you?"
    assert chat2["gpt"]

    chat3 = chat_context.chat("Have a good day")
    assert chat3["user"] == "Have a good day"
    assert chat3["gpt"]

    chat_history = chat_context.chat_history()
    assert chat_history == [chat1, chat2, chat3]
    print(chat_history)


def launch_server():
    from generate import main
    main(base_model='h2oai/h2ogpt-oig-oasst1-512-6_9b', prompt_type='human_bot', chat=False,
         stream_output=False, gradio=True, num_beams=1, block_gradio_exit=False)