MCPcopy Create free account
hub / github.com/CL-lau/SQL-GPT / is_valid

Method is_valid

gpt/check_api_key.py:22–40  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

20class 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
43class SerpAPI(ApiKey):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected