File size: 2,887 Bytes
b219d99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aed88a2
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import requests, json, time

BASE = 'http://127.0.0.1:7860/api/v1/chat/completions'

headers = {'Content-Type': 'application/json'}

print('Non-streaming example')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Who is the president of France today?',
    'stream': False,
    'max_tokens': 64,
    'temperature': 0.2,
    'include_usage': True,
}
try:
    r = requests.post(BASE, json=payload, timeout=120)
    print('Status', r.status_code)
    try:
        print(json.dumps(r.json(), indent=2))
    except Exception:
        print('Non-JSON response:', r.text[:1000])
except Exception as e:
    print('Error in non-stream request:', e)

print('\nTools: calc example')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Calculate 2+3*4 and explain the result.',
    'stream': False,
    'tools': [{'name': 'calc', 'args': {'expression': '2+3*4'}}],
    'include_usage': True,
}
try:
    r = requests.post(BASE, json=payload, timeout=120)
    print('Status', r.status_code)
    try:
        print(json.dumps(r.json(), indent=2))
    except Exception:
        print('Non-JSON response:', r.text[:1000])
except Exception as e:
    print('Error in calc tool request:', e)

print('\nTools: web_search example')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Who is the current president of France?',
    'stream': False,
    'web_search': True,
    'search_top_k': 2,
    'include_usage': True,
}
try:
    r = requests.post(BASE, json=payload, timeout=120)
    print('Status', r.status_code)
    try:
        print(json.dumps(r.json(), indent=2))
    except Exception:
        print('Non-JSON response:', r.text[:1000])
except Exception as e:
    print('Error in web_search request:', e)

print('\nStreaming example (short)')
payload = {
    'model': 'rwkv-latest:thinking',
    'messages': [{'role': 'user', 'content': 'Explain Newton\'s first law in one sentence.'}],
    'stream': True,
    'max_tokens': 64,
    'temperature': 0.2,
}

try:
    r = requests.post(BASE, json=payload, headers=headers, stream=True, timeout=120)
    print('Status', r.status_code)
    if r.status_code == 200:
        for line in r.iter_lines(decode_unicode=True):
            if not line:
                continue
            print('SSE:', line)
            if line.strip().endswith('[DONE]'):
                break
except Exception as e:
    print('Error in streaming request:', e)

print('\nDone tests')

print('\nChecking model listing endpoint')
try:
    r = requests.get('http://127.0.0.1:7860/api/v1/models', timeout=10)
    print('Models endpoint status', r.status_code)
    try:
        print(json.dumps(r.json(), indent=2))
    except Exception:
        print('Models endpoint returned non-JSON:', r.text[:200])
except Exception as e:
    print('Error calling models endpoint:', e)