BlueGit

ict rusty-teams

Files

rusty-teams / crates / chatsvc / examples / compose_copilot_probe.rs

compose_copilot_probe.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
compose_copilot_probe.rs 1.8 KiB Download Raw
1use chatsvc::compose_copilot::{Adjustment, ComposeAction, ComposeCopilot, ComposeRewrite};
2use session::{DEFAULT_ENDPOINT, Method, Scope, Session};
3
4const DRAFT: &str = "<p>hallo zusammen, wollte kurz fragen ob das treffen morgen noch steht oder ob wir es verschieben</p>";
5
6#[tokio::main]
7async fn main() {
8 let arguments: Vec<String> = std::env::args().skip(1).collect();
9 let action = match arguments.first().map(String::as_str) {
10 Some("proofread") => ComposeAction::Proofread,
11 Some("custom") => ComposeAction::Custom(arguments[1..].join(" ")),
12 Some(label) => Adjustment::ALL
13 .into_iter()
14 .find(|adjustment| adjustment.label().eq_ignore_ascii_case(label))
15 .map_or(ComposeAction::Rewrite, ComposeAction::Adjust),
16 None => ComposeAction::Rewrite,
17 };
18 let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned());
19 let session = Session::connect(&endpoint).await.expect("browser");
20 let organization = session
21 .request(
22 Method::Get,
23 "https://graph.microsoft.com/v1.0/organization?$select=id",
24 &Scope::graph("User.Read"),
25 None,
26 )
27 .await
28 .expect("organization");
29 let rewrite = ComposeRewrite {
30 tenant_id: organization.body["value"][0]["id"]
31 .as_str()
32 .expect("tenant id")
33 .to_owned(),
34 thread_id: "48:notes".to_owned(),
35 user_html: DRAFT.to_owned(),
36 action,
37 ui_language: "en-gb".to_owned(),
38 time_zone: "Europe/Berlin".to_owned(),
39 };
40 match ComposeCopilot::new(&session).rewrite(&rewrite).await {
41 Ok(answer) => println!("answer: {answer}"),
42 Err(error) => println!("error: {error}"),
43 }
44}