I’m using the openai python module. How can I retrieve the context_length for a model (or a list for all models)?
gpt-3.5-turbo suggested the following, which does not work:
models = openai.Model.list()
for model in models['data']:
if model['id'] == 'davinci':
config = model['model_configuration']
context_length = config['max_tokens']
break
print(f"The context length for the davinci model is {context_length} tokens.")
--------------------------
KeyError Traceback (most recent call last)
Cell In [21], line 4
2 for model in models['data']:
3 if model['id'] == 'davinci':
----> 4 config = model['model_details']['config']
5 context_length = config['max_tokens']
6 break
KeyError: 'model_details'