2023-08-07 10:26:09 +02:00
|
|
|
# nova-python
|
|
|
|
🐍 Python library for accessing the Nova API
|
|
|
|
|
|
|
|
## Usage ##
|
2023-08-07 11:39:57 +02:00
|
|
|
Install the module (This requires <a href="https://rustup.rs/">Cargo</a>)
|
|
|
|
```sh
|
|
|
|
$ pip install nova-python
|
|
|
|
```
|
|
|
|
|
2023-08-07 10:26:09 +02:00
|
|
|
Import the module
|
|
|
|
```python
|
|
|
|
from nova_python import Endpoints, Models, NovaClient
|
|
|
|
```
|
|
|
|
|
|
|
|
Create an instance of NovaClient, using your API key
|
|
|
|
|
|
|
|
```python
|
|
|
|
client = NovaClient("YOUR_API_KEY")
|
|
|
|
```
|
|
|
|
|
|
|
|
nova_python currently implements two enums: Endpoints and Models. Those contain:
|
|
|
|
|
2023-08-07 11:39:57 +02:00
|
|
|
**Endpoints**
|
2023-08-07 10:26:09 +02:00
|
|
|
* `Endpoints.CHAT_COMPLETION`
|
2023-08-07 11:39:57 +02:00
|
|
|
* `Endpoints.MODERATION`
|
2023-08-07 10:26:09 +02:00
|
|
|
|
|
|
|
**Models**
|
|
|
|
* `Models.GPT3`
|
2023-08-07 11:39:57 +02:00
|
|
|
* `Models.GPT4`
|
|
|
|
* `Models.MODERATION_LATEST`
|
|
|
|
* `Models.MODERATION_STABLE`
|
2023-08-07 10:26:09 +02:00
|
|
|
|
2023-08-07 11:39:57 +02:00
|
|
|
Now, to make a request, use the `make_request` function. For example:
|
2023-08-07 10:26:09 +02:00
|
|
|
|
|
|
|
```python
|
|
|
|
from nova_python import Endpoints, Models, NovaClient
|
|
|
|
client = NovaClient("YOUR_API_KEY")
|
|
|
|
|
|
|
|
client.make_request(
|
|
|
|
endpoint=Endpoints.CHAT_COMPLETION,
|
|
|
|
model=Models.GPT3,
|
|
|
|
data=[
|
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
|
{"role": "user", "content": "Hello!"}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
2023-08-07 11:39:57 +02:00
|
|
|
or
|
|
|
|
|
|
|
|
```python
|
|
|
|
from nova_python import Endpoints, Models, NovaClient
|
|
|
|
client = NovaClient("YOUR_API_KEY")
|
|
|
|
|
|
|
|
client.make_request(
|
|
|
|
endpoint=Endpoints.MODERATION,
|
|
|
|
model=Models.MODERATION_STABLE,
|
|
|
|
data=[{"input": "I'm going to kill them."}]
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2023-08-07 10:26:09 +02:00
|
|
|
If everything goes to plan, you'll receive a string containing JSON-Data, which you can then use in your project.
|
|
|
|
*Happy prompting!*
|
2023-08-07 13:19:30 +02:00
|
|
|
<br><br>
|
2023-08-07 11:39:57 +02:00
|
|
|
## FAQ ##
|
|
|
|
**Q:** I get an error when installing the package
|
|
|
|
**A:** Make you sure, that you have <a href="https://rustup.rs/">Cargo</a> installed
|
|
|
|
|
2023-08-07 13:19:30 +02:00
|
|
|
**Q**: I keep getting `RuntimeError: error sending request for url (https://api.nova-oss.com/v1/moderations): operation timed out`
|
|
|
|
**A**: Try passing a higher value than 30 as `seconds_until_timeout` to `make_request`
|
|
|
|
|
2023-08-07 10:26:09 +02:00
|
|
|
Made with 🩸 by Leander
|