Azure OpenAI 初体验 - 20230619

参考文档:

Quickstart - Get started using ChatGPT and GPT-4 with Azure OpenAI Service - Azure OpenAI Service | Microsoft Learn

先决条件

  • Azure 订阅
  • 在所需的 Azure 订阅中授予 Azure OpenAI 的访问权限。
  • 具有 或gpt-35-turbo已部署的模型。

Azure OpenAI 初体验 - 20230619_第1张图片

转到 Azure OpenAI Studio

导航到 Azure OpenAI Studio https://oai.azure.com/,并使用有权访问 OpenAI 资源的凭据登录。在登录工作流期间或之后,选择相应的目录、Azure 订阅和 Azure OpenAI 资源。

Azure OpenAI 初体验 - 20230619_第2张图片

已经部署了一些模型

在“部署”中选择模型:

Azure OpenAI 初体验 - 20230619_第3张图片

启动聊天会话

Azure OpenAI 初体验 - 20230619_第4张图片

Azure OpenAI 初体验 - 20230619_第5张图片

选择“从助理设置”下选择“查看代码”,将重播到目前为止整个对话背后的代码

#Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = "https://openainewone.openai.azure.com/"
openai.api_version = "2023-03-15-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")//需要替换系统参数或直接修改

response = openai.ChatCompletion.create(
  engine="openaig35turbo",
  messages = [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":"推荐端午节的华东好去处"},{"role":"assistant","content":"1. 苏州园林:苏州的园林建筑是中国传统文化的重要代表之一,端午节可以到苏州游览古典园林,感受传统文化的魅力。\n\n2. 杭州西湖:西湖是杭州的标志性景点,端午节可以欣赏西湖美景,品尝当地的龙井茶。\n\n3. 上海迪士尼乐园:迪士尼乐园是全家人的好去处,端午节可以带着孩子一起来到这里,享受欢乐时光。\n\n4. 黄山:黄山是中国著名的山水风景区,端午节可以在这里爬山、观赏云海,感受大自然的魅力。\n\n5. 千岛湖:千岛湖是一个美丽的水乡景区,端午节可以在这里游船、钓鱼、享受湖光山色。\n\n6. 乌镇:乌镇是一个古色古香的小镇,端午节可以在这里散步、品尝当地美食、感受古镇文化。\n\n7. 南京夫子庙:夫子庙是南京的著名古迹,端午节可以在这里游览、购物、品尝当地小吃。\n\n8. 嘉兴南湖:南湖是嘉兴的标志性景点,端午节可以在这里游船、欣赏景色、品尝当地美食。"}],
  temperature=0.7,
  max_tokens=800,
  top_p=0.95,
  frequency_penalty=0,
  presence_penalty=0,
  stop=None)

其中:openai.api_key = os.getenv("OPENAI_API_KEY")//需要替换系统参数或直接修改

Client USE Python 代码

  • 安装好Python 3
  • Set up
    Install the OpenAI Python client library with:

    pip install openai
    
    pip3 install openai // MAC OS use this commond

官方示例:

#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("AZURE_OPENAI_ENDPOINT") 
openai.api_version = "2023-05-15"
openai.api_key = os.getenv("AZURE_OPENAI_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'])

结合实验:

#Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = "https://openainewone.openai.azure.com/"
openai.api_version = "2023-03-15-preview"
openai.api_key = "c9bb1dd8326b493195abc16e53cc"

response = openai.ChatCompletion.create(
  engine="openaig35turbo",
  messages = [{"role":"system","content":"You are an AI assistant that helps people find information."},{"role":"user","content":"What's the ways to learn Azure OpenAI"}],
  temperature=0.7,
  max_tokens=800,
  top_p=0.95,
  frequency_penalty=0,
  presence_penalty=0,
  stop=None)

print(response)
PS C:\Users\v-yizhao1> & C:/Users/v-yizhao1/AppData/Local/Microsoft/WindowsApps/python3.11.exe "c:/Users/v-yizhao1/OneDrive - Microsoft/Documents/Python/OpenAI-Untitled-1.py"
{
  "id": "chatcmpl-7ThltTRf2ABTKJOjidNYUPHaYcXKq",
  "object": "chat.completion",
  "created": 1687314125,
  "model": "gpt-35-turbo",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "There are several ways to learn Azure OpenAI. Here are a few suggestions:\n\n1. Microsoft Learn: Microsoft Learn is an online learning platform that provides free courses and tutorials on Azure and OpenAI. You can learn at your own pace and earn badges and certifications.\n\n2. Azure AI Fundamentals certification: Microsoft offers a certification exam that covers the fundamentals of Azure AI. This certification can help you validate your skills and knowledge in this area.\n\n3. Online courses: There are several online courses available that cover Azure and OpenAI. Sites like Coursera, Udemy, and Pluralsight offer courses on these topics.\n\n4. Community resources: There are several online communities where you can connect with other professionals and learn from their experiences. Some examples include the Microsoft Azure community, the Azure AI community, and the OpenAI community.\n\n5. Books: There are several books available on Azure and OpenAI. Some popular titles include \"Azure for Architects\" by Ritesh Modi and \"Hands-On Machine Learning with Azure\" by Nishith Pathak."
      }
    }
  ],
  "usage": {
    "completion_tokens": 213,
    "prompt_tokens": 33,
    "total_tokens": 246
  }
}
   AI Answer:
"content": "There are several ways to learn Azure OpenAI. Here are a few suggestions:\n\n1. Microsoft Learn: Microsoft Learn is an online learning platform that provides free courses and tutorials on Azure and OpenAI. You can learn at your own pace and earn badges and certifications.\n\n2. Azure AI Fundamentals certification: Microsoft offers a certification exam that covers the fundamentals of Azure AI. This certification can help you validate your skills and knowledge in this area.\n\n3. Online courses: There are several online courses available that cover Azure and OpenAI. Sites like Coursera, Udemy, and Pluralsight offer courses on these topics.\n\n4. Community resources: There are several online communities where you can connect with other professionals and learn from their experiences. Some examples include the Microsoft Azure community, the Azure AI community, and the OpenAI community.\n\n5. Books: There are several books available on Azure and OpenAI. Some popular titles include \"Azure for Architects\" by Ritesh Modi and \"Hands-On Machine Learning with Azure\" by Nishith Pathak."

Deply to WEB

Azure OpenAI 初体验 - 20230619_第6张图片

这一步部署失败,系统并没给出原因!

你可能感兴趣的:(Azure OpenAI 初体验 - 20230619)