gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Fix errors and bugs in the given code, without changing its intended functionality. ONLY…
- User
Fix errors and bugs in the given code, without changing its intended functionality. ONLY return the fixed code and nothing else. Enclose the entire code in a single code block.
def search_patents(query: str, n: int = 5) -> List[Dict]: """ Search for relevant patents using the PQAI API.
Args: query (str): Search query token (str): PQAI API token n (int): Number of results to return (default: 5) Returns: List of patent dictionaries containing title and description """ endpoint = "https://api.projectpq.ai" route = "/search/102" url = endpoint + route # Get patents from the last 5 years after_date = (datetime.now() - timedelta(days=5*365)).strftime("%Y-%m-01") token = os.environ.get("PQAI_API_KEY") params = {"q": query, "n": n, "type": "patent", "after": after_date, "token": token} try: response = requests.get(url, params=params) response.raise_for_status() # Raise an error for bad status codes results = response.json().get("results", []) # Format results for use in our workflow formatted_patents = [] for patent in results: formatted_patents.append( { "title": patent.get("title", "No title"), "abstract": patent.get("abstract", "No abstract"), "publication_number": patent.get("id", "Unknown"), "publication_date": patent.get("publication_date", "Unknown"), "score": patent.get("score", 0), "url": patent.get("url", ""), } ) return formatted_patents - Assistant
import os import requests from datetime import datetime, timedelta from typing import List, Dict def search_patents(query: str, n: int = 5) -> List[Dict]: """ Search for relevant patents using the PQAI API. Args: query (str): Search query n (int): Number of results to return (default: 5) Returns: List of patent dictionaries containing title and description """ endpoint = "https://api.projectpq.ai" route = "/search/102" url = endpoint + route # Get patents from the last 5 years after_date = (datetime.now() - timedelta(days=5*365)).strftime("%Y-%m-01") token = os.environ.get("PQAI_API_KEY") params = {"q": query, "n": n, "type": "patent", "after": after_date, "token": token} try: response = requests.get(url, params=params) response.raise_for_status() # Raise an error for bad status codes results = response.json().get("results", []) # Format results for use in our workflow formatted_patents = [] for patent in results: formatted_patents.append( { "title": patent.get("title", "No title"), "abstract": patent.get("abstract", "No abstract"), "publication_number": patent.get("id", "Unknown"), "publication_date": patent.get("publication_date", "Unknown"), "score": patent.get("score", 0), "url": patent.get("url", ""), } ) return formatted_patents except Exception as e: print(f"An error occurred: {e}") return []