(cls)
| 20 | class OpenAiAPI(ApiKey): |
| 21 | @classmethod |
| 22 | def is_valid(cls) -> Any | None: |
| 23 | if not st.session_state['openai_api_key']: |
| 24 | st.error('⚠️ :red[You have not pass OpenAI API key.] Use default model') |
| 25 | return |
| 26 | |
| 27 | openai.api_key = os.getenv('OPENAI_API_KEY') |
| 28 | try: |
| 29 | response = openai.Completion.create( |
| 30 | engine='davinci', |
| 31 | prompt=cls.query, |
| 32 | max_tokens=5 |
| 33 | ) |
| 34 | return response |
| 35 | except Exception as e: |
| 36 | st.error( |
| 37 | '🚨 :red[Your OpenAI API key has a problem.] ' |
| 38 | '[Check your usage](https://platform.openai.com/account/usage)' |
| 39 | ) |
| 40 | print(f'Test error\n{e}') |
| 41 | |
| 42 | |
| 43 | class SerpAPI(ApiKey): |
nothing calls this directly
no outgoing calls
no test coverage detected