🐍 Python library for accessing the Nova API
Go to file
2023-08-15 13:48:12 +02:00
src did a little refactoring 2023-08-11 19:40:06 +02:00
.gitignore Update cargo.toml 2023-08-07 17:32:07 +02:00
Cargo.toml Removed the extension-module feature 2023-08-15 13:48:12 +02:00
LICENSE Initial commit aka. it's done 2023-08-07 10:26:09 +02:00
pyproject.toml Made timeout longer and added optional seconds_until_timeout argument 2023-08-07 13:19:30 +02:00
README.md Updated Readme 2023-08-08 12:36:59 +02:00

nova-python

🐍 Python library for accessing the Nova API

Usage

Install the module

$ pip install nova-python

Import the module

from nova_python import Endpoints, Models, NovaClient

Create an instance of NovaClient, using your API key

client = NovaClient("YOUR_API_KEY")

nova_python currently implements two enums: Endpoints and Models. Those contain:

Endpoints

  • Endpoints.CHAT_COMPLETION
  • Endpoints.MODERATION

Models

  • Models.GPT3
  • Models.GPT4
  • Models.MODERATION_LATEST
  • Models.MODERATION_STABLE

Now, to make a request, use the make_request function. For example:

from nova_python import Endpoints, Models, NovaClient
client = NovaClient("YOUR_API_KEY")

reponse = client.make_request(
    endpoint=Endpoints.CHAT_COMPLETION,
    model=Models.GPT3,
    data=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ]
)

...

or

from nova_python import Endpoints, Models, NovaClient
client = NovaClient("YOUR_API_KEY")

reponse = client.make_request(
    endpoint=Endpoints.MODERATION,
    model=Models.MODERATION_STABLE,
    data=[{"input": "I'm going to kill them."}]
)

...

If everything goes to plan, you'll receive a string containing JSON-Data, which you can then use in your project.

Note, that when using chat completion, as special ChatResponse-Instance get's returned.
You can access the reponse's json.data, by casting it to a string using the str method, like this:

...

str(reponse)

...

but more importantly, you can use it's get_message_content function, to directly get access to the chat reponse. Used like this:

...

content = reponse.get_message_content()

...

Happy prompting!

FAQ

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

Made with 🩸 by Leander