0

I would like to sample code to run in Visual Studio Code in Mac. However I cannot get this simple code to work. What can I try next?

*(base) johnsmith@Johns-MBP ~ % /usr/bin/python3 /Users/johnsmith/Documents/Python/openai_test.py
Traceback (most recent call last):
  File "/Users/johnsmith/Documents/Python/openai_test.py", line 3, in <module>
    import openai
  File "/Users/johnsmith/Documents/Python/openai.py", line 9, in <module>
    response = openai.ChatCompletion.create(
AttributeError: partially initialized module 'openai' has no attribute 'ChatCompletion' (most likely due to a circular import)*


Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = os.getenv("OPENAI_API_BASE") 
openai.api_version = "2023-03-15-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.ChatCompletion.create(
    engine="gpt-35-turbo", # engine = "deployment_name".
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
        {"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
        {"role": "user", "content": "Do other Azure Cognitive Services support this too?"}
    ]
)

print(response)
print(response['choices'][0]['message']['content'])
Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
Kenny_I
  • 2,001
  • 5
  • 40
  • 94

0 Answers0