openai-python
openai-python copied to clipboard
TypeError upon API response
Describe the bug
When executing the API call specified in the code snippet the following error occurs: error.txt
Based on printouts, in some cases the API return with an ill-formed Python dictionary as below.
API response with null part of the dictionary: {"error":{"message":"The response was filtered due to the prompt triggering Azure OpenAI’s content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766", "type":null,"param":"prompt","code":"content_filter","status":400}}
To Reproduce
Run the code snippet attached on the input 'doc.txt'.
Code snippets
def prompt_openai(doc, max_tokens):
prompt = f"""
Create a summary of the text below.
'{doc}'
"""
try:
response = openai.Completion.create(
engine = openai.deployment,
prompt = prompt,
temperature = 1,
max_tokens = max_tokens,
top_p = 0.95,
frequency_penalty = 0.5,
presence_penalty = 0.5,
stop = None#"<|im_end|>"
)
return response['choices'][0]['text'].replace('\n', '').replace(' .', '.').strip()
OS
Windows 10
Python version
Python 3.10.9
Library version
openai 0.27.2