This is a library for integrating OpenAI in your flow function for flows.network.
Usage example
use openai_flows::{CompletionRequest, create_completion};
use slack_flows::{listen_to_channel, send_message_to_channel};
#[no_mangle]
pub fn run() {
listen_to_channel("myworkspace", "mychannel", |sm| {
let cr = CompletionRequest {
prompt: sm.text,
..Default::default()
};
let r = create_completion("myaccount", cr);
r.iter().for_each(|c| {
send_message_to_channel("myworkspace", "mychannel", c.to_string());
});
});
}
When a new message is received from mychannel
, we will create completions using create_completion
then send the result back to Slack.
Visit ChatGPT
use openai_flows::{chat_completion, ChatOptions, ChatModel};
use slack_flows::{listen_to_channel, send_message_to_channel};
#[no_mangle]
pub fn run() {
listen_to_channel("myworkspace", "mychannel", |sm| {
let co = ChatOptions {
model: ChatModel::GPT35Turbo,
restart: sm.text.eq_ignore_ascii_case("/restart"),
restarted_sentence: Some("let's change the subject"),
retry_times: 2,
};
if let Some(r) = chat_completion("myaccount", "any_conversation_id", &sm.text, &co) {
send_message_to_channel("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.