-
Notifications
You must be signed in to change notification settings - Fork 536
refactor: align crates/jina with OpenAPI specs #3943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,64 @@ | ||
| use crate::client::{JinaClient, check_response}; | ||
| use crate::common_derives; | ||
| use crate::types::{ReaderResponseEnvelope, RespondWith, RetainImages}; | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ReadUrlRequest { | ||
| #[schemars(description = "The URL to read and convert to markdown")] | ||
| pub url: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Response format")] | ||
| pub respond_with: Option<RespondWith>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Whether to bypass the cache")] | ||
| pub no_cache: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "CSS selectors to focus on specific elements")] | ||
| pub target_selector: Option<Vec<String>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "CSS selectors for elements to wait for before reading")] | ||
| pub wait_for_selector: Option<Vec<String>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "CSS selectors for elements to remove from the output")] | ||
| pub remove_selector: Option<Vec<String>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Maximum number of tokens in the output")] | ||
| pub token_budget: Option<u32>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Include a summary of all links at the end")] | ||
| pub with_links_summary: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Include a summary of all images at the end")] | ||
| pub with_images_summary: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "How to handle images in the output")] | ||
| pub retain_images: Option<RetainImages>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Generate alt text for images")] | ||
| pub with_generated_alt: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Include iframe content")] | ||
| pub with_iframe: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Include shadow DOM content")] | ||
| pub with_shadow_dom: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Timeout in milliseconds")] | ||
| pub timeout: Option<u32>, | ||
| } | ||
| } | ||
|
|
||
| impl JinaClient { | ||
| pub async fn read_url(&self, req: ReadUrlRequest) -> Result<String, crate::Error> { | ||
| let url = format!("https://r.jina.ai/{}", req.url); | ||
|
|
||
| let response = self.client.get(&url).send().await?; | ||
| let response = self | ||
| .client | ||
| .post("https://r.jina.ai/") | ||
| .json(&req) | ||
| .send() | ||
| .await?; | ||
| let response = check_response(response).await?; | ||
| Ok(response.text().await?) | ||
| let envelope: ReaderResponseEnvelope = response.json().await?; | ||
| Ok(envelope.data.content) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| use crate::client::{JinaClient, check_response}; | ||
| use crate::common_derives; | ||
| use crate::types::{SearchEngine, SearchResponseEnvelope, SearchResultItem, SearchType}; | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct SearchRequest { | ||
| #[schemars(description = "The search query")] | ||
| pub q: String, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[serde(rename = "type")] | ||
| #[schemars(description = "Type of search: web, images, or news")] | ||
| pub search_type: Option<SearchType>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Number of results to return (0-20)")] | ||
| pub num: Option<u32>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Search engine to use")] | ||
| pub engine: Option<SearchEngine>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Country code for geolocation")] | ||
| pub gl: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Language code")] | ||
| pub hl: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Location for search results")] | ||
| pub location: Option<String>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Page number for pagination")] | ||
| pub page: Option<u32>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Limit results to specific sites")] | ||
| pub site: Option<Vec<String>>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Whether to bypass the cache")] | ||
| pub no_cache: Option<bool>, | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| #[schemars(description = "Maximum number of tokens in the output")] | ||
| pub token_budget: Option<u32>, | ||
| } | ||
| } | ||
|
|
||
| impl JinaClient { | ||
| pub async fn search(&self, req: SearchRequest) -> Result<Vec<SearchResultItem>, crate::Error> { | ||
| let response = self | ||
| .client | ||
| .post("https://s.jina.ai/") | ||
| .json(&req) | ||
| .send() | ||
| .await?; | ||
| let response = check_response(response).await?; | ||
| let envelope: SearchResponseEnvelope = response.json().await?; | ||
| Ok(envelope.data) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| use crate::common_derives; | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ReaderResponseEnvelope { | ||
| pub code: u16, | ||
| pub status: u32, | ||
| pub data: ReaderData, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct ReaderData { | ||
| #[serde(default)] | ||
| pub title: String, | ||
| #[serde(default)] | ||
| pub url: String, | ||
| #[serde(default)] | ||
| pub content: String, | ||
| #[serde(default)] | ||
| pub description: String, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct SearchResponseEnvelope { | ||
| pub code: u16, | ||
| pub status: u32, | ||
| pub data: Vec<SearchResultItem>, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct SearchResultItem { | ||
| #[serde(default)] | ||
| pub title: String, | ||
| #[serde(default)] | ||
| pub url: String, | ||
| #[serde(default)] | ||
| pub content: String, | ||
| #[serde(default)] | ||
| pub description: String, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub enum RespondWith { | ||
| #[serde(rename = "markdown")] | ||
| Markdown, | ||
| #[serde(rename = "html")] | ||
| Html, | ||
| #[serde(rename = "text")] | ||
| Text, | ||
| #[serde(rename = "screenshot")] | ||
| Screenshot, | ||
| #[serde(rename = "pageshot")] | ||
| Pageshot, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub enum RetainImages { | ||
| #[serde(rename = "none")] | ||
| None, | ||
| #[serde(rename = "all")] | ||
| All, | ||
| #[serde(rename = "alt")] | ||
| Alt, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub enum SearchType { | ||
| #[serde(rename = "web")] | ||
| Web, | ||
| #[serde(rename = "images")] | ||
| Images, | ||
| #[serde(rename = "news")] | ||
| News, | ||
| } | ||
| } | ||
|
|
||
| common_derives! { | ||
| pub enum SearchEngine { | ||
| #[serde(rename = "google")] | ||
| Google, | ||
| #[serde(rename = "bing")] | ||
| Bing, | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.