File size: 833 Bytes
85a1961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
### Example: `sqlchat` (use like openai pypi package) <a name="example-sqlchat"></a>

```python
# Import sqlchat
import sqlchat

# sqlchat.Completion.create
# sqlchat.StreamCompletion.create

[...]

```

#### Example Chatbot
```python
messages = []

while True:
    user = input('you: ')

    sqlchat_cmpl = sqlchat.Completion.create(
        prompt   = user,
        messages = messages
    )

    print('gpt:', sqlchat_cmpl.completion.choices[0].text)
    
    messages.extend([
        {'role': 'user', 'content': user }, 
        {'role': 'assistant', 'content': sqlchat_cmpl.completion.choices[0].text}
    ])
```

#### Streaming Response:

```python
for response in sqlchat.StreamCompletion.create(
    prompt   = 'write python code to reverse a string',
    messages = []):

    print(response.completion.choices[0].text)
```