33个版本 (8个重大更改)
0.9.1 | 2023年11月7日 |
---|---|
0.8.5 | 2023年7月5日 |
0.2.3 | 2023年3月29日 |
在网络编程类别中排名第846
每月下载量499次
32KB
496 行
这是一个用于将OpenAI集成到您的flows.network流函数中的库。
访问ChatGPT
use flowsnet_platform_sdk::logger;
use lambda_flows::{request_received, send_response};
use openai_flows::{
chat::{ChatModel, ChatOptions},
OpenAIFlows,
};
use serde_json::Value;
use std::collections::HashMap;
#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn run() {
logger::init();
request_received(handler).await;
}
async fn handler(_qry: HashMap<String, Value>, body: Vec<u8>) {
let co = ChatOptions {
model: ChatModel::GPT35Turbo,
restart: false,
system_prompt: None,
};
let of = OpenAIFlows::new();
let r = match of
.chat_completion(
"any_conversation_id",
String::from_utf8_lossy(&body).into_owned().as_str(),
&co,
)
.await
{
Ok(c) => c.choice,
Err(e) => e,
};
send_response(
200,
vec![(
String::from("content-type"),
String::from("text/plain; charset=UTF-8"),
)],
r.as_bytes().to_vec(),
);
}
此示例允许您通过chat_completion
和Lambda请求进行ChatGPT对话。
整个文档在这里。
依赖项
~1-2MB
~43K SLoC