File size: 1,430 Bytes
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
from fastapi.testclient import TestClient
from app import app
import json

client = TestClient(app)

print('Non-streaming test')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Who is the president of France today?',
    'stream': False,
    'max_tokens': 64,
    'temperature': 0.2,
    'include_usage': True,
}
res = client.post('/api/v1/chat/completions', json=payload)
print('Status', res.status_code)
try:
    print(json.dumps(res.json(), indent=2))
except Exception as e:
    print('Response not JSON or parse failed', e)

print('\nTools calc test')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Calculate 2+3*4 and explain the result.',
    'stream': False,
    'tools': [{'name': 'calc', 'args': {'expression': '2+3*4'}}],
}
res = client.post('/api/v1/chat/completions', json=payload)
print('Status', res.status_code)
try:
    print(json.dumps(res.json(), indent=2))
except Exception as e:
    print('Response not JSON or parse failed', e)

print('\nTools web_search test')
payload = {
    'model': 'rwkv-latest',
    'prompt': 'Who is the current president of France?',
    'stream': False,
    'web_search': True,
    'search_top_k': 2,
}
res = client.post('/api/v1/chat/completions', json=payload)
print('Status', res.status_code)
try:
    print(json.dumps(res.json(), indent=2))
except Exception as e:
    print('Response not JSON or parse failed', e)