mirror of
https://github.com/NovaOSS/nova-python.git
synced 2024-11-25 20:43:58 +01:00
Compare commits
4 commits
ccbaa4e247
...
1361d09025
Author | SHA1 | Date | |
---|---|---|---|
1361d09025 | |||
2bdab522ee | |||
8c4bcf4b7f | |||
3a210d7b5b |
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nova-python"
|
name = "nova-python"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -9,7 +9,7 @@ name = "nova_python"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pyo3 = {version = "0.19.2", features = ["extension-module", "generate-import-lib"]}
|
pyo3 = {version = "0.19.2", features = ["generate-import-lib"]}
|
||||||
reqwest = "0.11.18"
|
reqwest = "0.11.18"
|
||||||
tokio = { version = "1.29.1", features = ["rt-multi-thread", "time"] }
|
tokio = { version = "1.29.1", features = ["rt-multi-thread", "time"] }
|
||||||
serde_json = "1.0.104"
|
serde_json = "1.0.104"
|
12
README.md
12
README.md
|
@ -36,7 +36,7 @@ Now, to make a request, use the `make_request` function. For example:
|
||||||
from nova_python import Endpoints, Models, NovaClient
|
from nova_python import Endpoints, Models, NovaClient
|
||||||
client = NovaClient("YOUR_API_KEY")
|
client = NovaClient("YOUR_API_KEY")
|
||||||
|
|
||||||
reponse = client.make_request(
|
response = client.make_request(
|
||||||
endpoint=Endpoints.CHAT_COMPLETION,
|
endpoint=Endpoints.CHAT_COMPLETION,
|
||||||
model=Models.GPT3,
|
model=Models.GPT3,
|
||||||
data=[
|
data=[
|
||||||
|
@ -54,7 +54,7 @@ or
|
||||||
from nova_python import Endpoints, Models, NovaClient
|
from nova_python import Endpoints, Models, NovaClient
|
||||||
client = NovaClient("YOUR_API_KEY")
|
client = NovaClient("YOUR_API_KEY")
|
||||||
|
|
||||||
reponse = client.make_request(
|
response = client.make_request(
|
||||||
endpoint=Endpoints.MODERATION,
|
endpoint=Endpoints.MODERATION,
|
||||||
model=Models.MODERATION_STABLE,
|
model=Models.MODERATION_STABLE,
|
||||||
data=[{"input": "I'm going to kill them."}]
|
data=[{"input": "I'm going to kill them."}]
|
||||||
|
@ -65,20 +65,20 @@ reponse = client.make_request(
|
||||||
If everything goes to plan, you'll receive a string containing JSON-Data, which you can then use in your project.
|
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.
|
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:
|
You can access the response's json.data, by casting it to a string using the `str` method, like this:
|
||||||
```python
|
```python
|
||||||
...
|
...
|
||||||
|
|
||||||
str(reponse)
|
str(response)
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
but more importantly, you can use it's `get_message_content` function, to directly get access to the chat reponse. Used like this:
|
but more importantly, you can use it's `get_message_content` function, to directly get access to the chat response. Used like this:
|
||||||
```
|
```
|
||||||
...
|
...
|
||||||
|
|
||||||
content = reponse.get_message_content()
|
content = response.get_message_content()
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -231,23 +231,14 @@ impl ChatResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn model_is_compatible(endpoint: &Endpoints, model: &Models) -> bool {
|
fn model_is_compatible(endpoint: &Endpoints, model: &Models) -> bool {
|
||||||
if endpoint == &Endpoints::ChatCompletion {
|
let chat_models = [Models::Gpt3, Models::Gpt4];
|
||||||
if [Models::Gpt3, Models::Gpt4].contains(model) {
|
let moderation_models = [Models::ModerationStable, Models::ModerationLatest];
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if endpoint == &Endpoints::Moderation {
|
match endpoint {
|
||||||
if [Models::ModerationStable, Models::ModerationLatest].contains(model) {
|
Endpoints::ChatCompletion => chat_models.contains(model),
|
||||||
return true;
|
Endpoints::Moderation => moderation_models.contains(model),
|
||||||
} else {
|
_ => false
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_is_valid(api_key: &str) -> bool {
|
fn key_is_valid(api_key: &str) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue