| 41 | |
| 42 | |
| 43 | class SerpAPI(ApiKey): |
| 44 | @classmethod |
| 45 | def is_valid(cls) -> str: |
| 46 | if not st.session_state['serpapi_api_key']: |
| 47 | st.warning('⚠️ You have not pass SerpAPI key. (You cannot ask current events.)') |
| 48 | return |
| 49 | from langchain import SerpAPIWrapper |
| 50 | |
| 51 | os.environ['SERPAPI_API_KEY'] = os.getenv('SERPAPI_API_KEY') |
| 52 | try: |
| 53 | search = SerpAPIWrapper() |
| 54 | response = search.run(cls.query) |
| 55 | return response |
| 56 | except Exception as e: |
| 57 | st.error( |
| 58 | '🚨 :red[Your SerpAPI key has a problem.] ' |
| 59 | '[Check your usage](https://serpapi.com/dashboard)' |
| 60 | ) |
| 61 | print(f'Test error\n{e}') |
nothing calls this directly
no outgoing calls
no test coverage detected