This is a library for integrating OpenAI in your flow function for flows.network.
```rust use openaiflows::{CompletionRequest, createcompletion}; use slackflows::{listentochannel, sendmessagetochannel};
pub fn run() { listentochannel("myworkspace", "mychannel", |sm| { let cr = CompletionRequest { prompt: sm.text, ..Default::default() }; let r = createcompletion("myaccount", cr); r.iter().foreach(|c| { sendmessagetochannel("myworkspace", "mychannel", c.tostring()); }); }); } ```
When a new message is received from mychannel
, we will create completions using create_completion
then send the result back to Slack.
```rust use openaiflows::{chatcompletion, ChatOptions}; use slackflows::{listentochannel, sendmessagetochannel};
pub fn run() { listentochannel("myworkspace", "mychannel", |sm| { let co = ChatOptions { restart: sm.text.eqignoreasciicase("/restart"), restartedsentence: Some("let's change the subject"), }; if let Some(r) = chatcompletion("myaccount", "anyconversationid", &sm.text, &co) { sendmessagetochannel("myworkspace", "mychannel", r.choice); } }); } ```
This example lets you have a conversation with ChatGPT using chat_completion
in Slack.
When you want to restart a new topic, just type /restart
.
The whole document is here.