openai.Completion.create DON'T WORK

tsukada.mamoru 0 Reputation points
2023-11-30T06:27:56.9733333+00:00
#Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = "https://proc01.openai.azure.com/openai/deployments/autoprocesssetting/completions?api-version=2023-09-15-preview"
openai.api_version = "2023-09-15-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")

#print(openai.api_key)

response = openai.Completion.create(
  engine="autoprocesssetting",
  prompt="Extract the person's name, company name, location, and phone number from the text below.Hello, \n\nmy name is Robert Smith. My name is Robert Smith. I am calling from Contoso Insurance in Delaware. A colleague of mine wanted to know if you would like to learn more about our comprehensive benefits policy. If you have a few moments, could you please give me a call at (555) 346-9322. Thank you.\n\nRobert Smith\nContoso Insurance\nDelaware\n(555) 346-9322<|im_end|>",
  temperature=0.2,
  max_tokens=150,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0,
  stop=None)

    
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,510 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,185 Reputation points Microsoft Employee
    2023-11-30T07:27:09.22+00:00

    @tsukada.mamoru Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    Please use the below sample and let me know if that helps.

    More info about the sample is here.

    from openai import AzureOpenAI
    
    # gets the API Key from environment variable AZURE_OPENAI_API_KEY
    client = AzureOpenAI(
        api_key = "156*********e19431",
        api_version="2023-09-15-preview",
        azure_endpoint="https://proc01.openai.azure.com",
    )
    
    completion = client.chat.completions.create(
        model="gpt-35",  # e.g. gpt-35-instant
        messages=[{"role":"system","content":"Extract the person's name, company name, location, and phone number from the text below."},{"role":"user","content":"Hello, \\n\\nmy name is Robert Smith. My name is Robert Smith. I am calling from Contoso Insurance in Delaware. A colleague of mine wanted to know if you would like to learn more about our comprehensive benefits policy. If you have a few moments, could you please give me a call at (555) 346-9322. Thank you.\\n\\nRobert Smith\\nContoso Insurance\\nDelaware\\n(555) 346-9322"},{"role":"assistant","content":"Person's Name: Robert Smith\nCompany Name: Contoso Insurance\nLocation: Delaware\nPhone Number: (555) 346-9322"}],
    )
    print(completion.choices[0].message.content)
    

    .
    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.