Spaces:
Build error
Build error
Download src/meta_search/providers/github.rs from LuckyMod/intentforge: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/LuckyMod/intentforge/resolve/main/src/meta_search/providers/github.rs
- Command line
-
hf download hf://spaces/LuckyMod/intentforge/src/meta_search/providers/github.rs
-
curl -L -o github.rs https://huggingface.co/spaces/LuckyMod/intentforge/resolve/main/src/meta_search/providers/github.rs
1.72 kB
| use crate::meta_search::models::SearchResult; | |
| use crate::meta_search::providers::{SearchContext, SearchProvider}; | |
| use anyhow::Result; | |
| use async_trait::async_trait; | |
| use serde::Deserialize; | |
| use std::sync::Arc; | |
| struct GitHubSearchResponse { | |
| items: Vec<GitHubItem>, | |
| } | |
| struct GitHubItem { | |
| full_name: String, | |
| html_url: String, | |
| description: Option<String>, | |
| stargazers_count: u32, | |
| } | |
| pub struct GitHubProvider; | |
| impl SearchProvider for GitHubProvider { | |
| fn name(&self) -> &'static str { | |
| "github" | |
| } | |
| async fn search(&self, query: &str, ctx: Arc<SearchContext>) -> Result<Vec<SearchResult>> { | |
| let client = crate::meta_search::providers::build_client_with_transport(&ctx, 15).await?; | |
| let url = format!( | |
| "https://api.github.com/search/repositories?q={}&per_page=50", | |
| urlencoding::encode(query) | |
| ); | |
| let resp: GitHubSearchResponse = client.get(url).send().await?.json().await?; | |
| let results = resp | |
| .items | |
| .into_iter() | |
| .map(|item| SearchResult { | |
| title: item.full_name, | |
| url: item.html_url, | |
| description: format!( | |
| "[{}] {}", | |
| item.stargazers_count, | |
| item.description.unwrap_or_default() | |
| ), | |
| source: "github".to_string(), | |
| score: 0.8, | |
| media_type: "text".to_string(), | |
| thumbnail_url: None, | |
| published_at: None, | |
| }) | |
| .collect(); | |
| Ok(results) | |
| } | |
| fn as_any(&self) -> &dyn std::any::Any { | |
| self | |
| } | |
| } | |