rust-cnb 0.1.2

[DEPRECATED - use `cnb` crate instead] rust-cnb with Generated API client
Documentation
//! Ai API 客户端

use crate::error::{ApiError, Result};
use reqwest::Client;
use serde_json::Value;
use url::Url;

/// Ai API 客户端
pub struct AiClient {
    base_url: String,
    client: Client,
}

impl AiClient {
    /// 创建新的 Ai API 客户端
    pub fn new(base_url: String, client: Client) -> Self {
        Self { base_url, client }
    }

    /// 设置认证信息
    pub fn with_auth(self, token: &str) -> Self {
        // 这里可以扩展认证逻辑
        self
    }

    /// Ai 对话,参数根据模型不同会有区别。Ai chat completions, params may differ by model.
    pub async fn post_repo_ai_chat_completions(
        &self,
        repo: String,
        request_data: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/ai/chat/completions", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::POST,
            url
        );



        request = request.json(&request_data);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 根据传入的需求内容和需求标题借助 AI 自动编码并提 PR。Automatically code and create a PR with AI based on the input requirement content and title.
    pub async fn post_repo_build_ai_auto_pr(
        &self,
        repo: String,
        request_data: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/build/ai/auto-pr", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::POST,
            url
        );



        request = request.json(&request_data);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

}