forked from 0xPlaygrounds/rig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentiment_classifier.rs
More file actions
35 lines (29 loc) · 823 Bytes
/
sentiment_classifier.rs
File metadata and controls
35 lines (29 loc) · 823 Bytes
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
use rig::providers::openai;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, JsonSchema, Serialize)]
/// An enum representing the sentiment of a document
enum Sentiment {
Positive,
Negative,
Neutral,
}
#[derive(Debug, Deserialize, JsonSchema, Serialize)]
struct DocumentSentiment {
/// The sentiment of the document
sentiment: Sentiment,
}
#[tokio::main]
async fn main() {
// Create OpenAI client
let openai_client = openai::Client::from_env();
// Create extractor
let data_extractor = openai_client
.extractor::<DocumentSentiment>("gpt-4")
.build();
let sentiment = data_extractor
.extract("I am happy")
.await
.expect("Failed to extract sentiment");
println!("GPT-4: {:?}", sentiment);
}