Likhith Sai Seemala
Deploy IntentForge v2 to HF Spaces
0ca462b
Raw History Blame Contribute Delete
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;
#[derive(Deserialize)]
struct GitHubSearchResponse {
items: Vec<GitHubItem>,
}
#[derive(Deserialize)]
struct GitHubItem {
full_name: String,
html_url: String,
description: Option<String>,
stargazers_count: u32,
}
pub struct GitHubProvider;
#[async_trait]
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
}
}