mirror of
https://github.com/YuuKi-OS/yuy-chat.git
synced 2026-02-18 22:01:09 +00:00
Actualizar hf_api.rs
This commit is contained in:
@@ -6,14 +6,18 @@ use crate::config::YUUKI_API;
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct YuukiRequest {
|
struct YuukiRequest {
|
||||||
prompt: String,
|
prompt: String,
|
||||||
|
model: String,
|
||||||
|
max_new_tokens: u32,
|
||||||
temperature: f32,
|
temperature: f32,
|
||||||
top_p: f32,
|
top_p: f32,
|
||||||
max_tokens: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct YuukiResponse {
|
struct YuukiResponse {
|
||||||
response: String,
|
response: String,
|
||||||
|
model: String,
|
||||||
|
tokens_generated: u32,
|
||||||
|
time_ms: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HuggingFaceAPI {
|
pub struct HuggingFaceAPI {
|
||||||
@@ -27,32 +31,32 @@ impl HuggingFaceAPI {
|
|||||||
Self {
|
Self {
|
||||||
client: Client::new(),
|
client: Client::new(),
|
||||||
token: Some(token),
|
token: Some(token),
|
||||||
model: format!("{}/{}", org, model),
|
model: model.to_lowercase(), // yuuki-best, yuuki-3.7, etc.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn generate(&self, prompt: &str, temperature: f32, top_p: f32) -> Result<String> {
|
pub async fn generate(&self, prompt: &str, temperature: f32, top_p: f32) -> Result<String> {
|
||||||
// Use Yuuki API endpoint
|
// Yuuki API endpoint: https://huggingface.co/spaces/OpceanAI/Yuuki-api/generate
|
||||||
let url = YUUKI_API;
|
let url = format!("{}/generate", YUUKI_API);
|
||||||
|
|
||||||
let request = YuukiRequest {
|
let request = YuukiRequest {
|
||||||
prompt: prompt.to_string(),
|
prompt: prompt.to_string(),
|
||||||
|
model: self.model.clone(),
|
||||||
|
max_new_tokens: 120,
|
||||||
temperature,
|
temperature,
|
||||||
top_p,
|
top_p,
|
||||||
max_tokens: 512,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut req = self.client.post(url).json(&request);
|
let response = self.client
|
||||||
|
.post(&url)
|
||||||
// Add token if available (optional for public API)
|
.json(&request)
|
||||||
if let Some(token) = &self.token {
|
.send()
|
||||||
req = req.header("Authorization", format!("Bearer {}", token));
|
.await?;
|
||||||
}
|
|
||||||
|
|
||||||
let response = req.send().await?;
|
|
||||||
|
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
anyhow::bail!("Yuuki API error: {}", response.status());
|
let status = response.status();
|
||||||
|
let error_text = response.text().await.unwrap_or_else(|_| "Unknown error".to_string());
|
||||||
|
anyhow::bail!("Yuuki API error {}: {}", status, error_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let yuuki_response: YuukiResponse = response.json().await?;
|
let yuuki_response: YuukiResponse = response.json().await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user