Skip to content

Commit 4cf22fd

Browse files
authored
feat: add examples/responses-web-search (#517)
1 parent 034bb4e commit 4cf22fd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "responses-web-search"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
async-openai = { path = "../../async-openai", features = ["responses"] }
9+
tokio = { version = "1", features = ["full"] }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::error::Error;
2+
3+
use async_openai::{
4+
types::responses::{
5+
CreateResponseArgs, Tool, WebSearchApproximateLocationArgs,
6+
WebSearchApproximateLocationType, WebSearchToolArgs, WebSearchToolFilters,
7+
WebSearchToolSearchContextSize,
8+
},
9+
Client,
10+
};
11+
12+
#[tokio::main]
13+
async fn main() -> Result<(), Box<dyn Error>> {
14+
let client = Client::new();
15+
16+
let user_location = WebSearchApproximateLocationArgs::default()
17+
.r#type(WebSearchApproximateLocationType::Approximate)
18+
.city("San Francisco")
19+
.country("US")
20+
.build()?;
21+
22+
let web_search = WebSearchToolArgs::default()
23+
.search_context_size(WebSearchToolSearchContextSize::Low)
24+
.filters(WebSearchToolFilters {
25+
allowed_domains: Some(vec!["news.ycombinator.com".to_string()]),
26+
})
27+
.user_location(user_location)
28+
.build()?;
29+
30+
let request = CreateResponseArgs::default()
31+
.model("gpt-5-mini")
32+
.input(
33+
"Search the Hacker News front page and summarize the top 3 stories in one sentence each. And also see if there was any new stories about Apple on Hacker News.",
34+
)
35+
.tools(vec![Tool::WebSearch(web_search)])
36+
.build()?;
37+
38+
let response = client.responses().create(request).await?;
39+
40+
println!("Response: {:#?}", response);
41+
42+
Ok(())
43+
}

0 commit comments

Comments
 (0)