File size: 276 Bytes
167e68e
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
from langchain.llms import OpenAI

def oai_key_isvalid(api_key):
    """Check if a given OpenAI key is valid"""
    try:
        llm = OpenAI(openai_api_key = api_key)
        out = llm("This is a test")
        print(out)
        return True
    except:
        return False