Skip to content

Commit

Permalink
use GOOGLE_API_KEY and CSE_ID if defined in .env
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 15, 2024
1 parent 719c1bd commit a966f2f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from web_search import WebSearch, WebSearchConfig, GoogleSearchConfig
config = WebSearchConfig(
sources=["google", "wikipedia"],
google_config=GoogleSearchConfig(
api_key="your_api_key",
api_key="your_google_api_key",
cse_id="your_cse_id"
)
)
Expand Down
7 changes: 4 additions & 3 deletions src/web_search/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from dataclasses import dataclass, field
import os
from typing import Literal

SearchSources = Literal["google", "wikipedia", "arxiv"]


@dataclass
class GoogleSearchConfig:
api_key: str
cse_id: str
api_key: str = os.environ["GOOGLE_API_KEY"]
cse_id: str = os.environ["CSE_ID"]
max_results: int = 3
app_domain: str | None = None

Expand All @@ -33,4 +34,4 @@ class SearchResult:
preview: str

def __str__(self):
return f"Title: {self.title}\nPreview: {self.preview}"
return f"Title: {self.title}\nPreview: {self.preview}"

0 comments on commit a966f2f

Please sign in to comment.