br_openai/
lib.rs

1use json::JsonValue;
2use crate::chat::Chat;
3use crate::files::Files;
4use crate::models::Models;
5
6/// 聊天
7mod chat;
8/// 图像生成
9mod images;
10/// 模型列表
11mod models;
12/// 文件
13mod files;
14#[derive(Clone, Debug)]
15pub struct OpenAi {
16    token: String,
17    // 用户ID
18    // user_id: String,
19    /// 模型名称
20    model: String,
21}
22
23impl OpenAi {
24    pub fn new(token: &str, _user_id: &str, model: &str) -> Self {
25        Self {
26            token: token.to_string(),
27            // user_id: user_id.to_string(),
28            model: model.parse().unwrap(),
29        }
30    }
31    /// 聊天
32    pub fn chat(&mut self, history: JsonValue, prompt: &str, file: &str) -> Result<JsonValue, String> {
33        Chat::new(self.clone()).request(history, prompt, file).clone()
34    }
35    /// 模型列表
36    pub fn models(&mut self) -> Result<JsonValue, String> {
37        Models::new(self.clone()).request()
38    }
39    /// 文件
40    pub fn files(&mut self, path: String) -> Result<JsonValue, String> {
41        Files::new(self.clone()).request(path)
42    }
43}