关于openssl:Azure-OpenAI-初体验-20230619

32次阅读

共计 5112 个字符,预计需要花费 13 分钟才能阅读完成。

参考文档:

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 Studio

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

曾经部署了一些模型

在“部署”中抉择模型:

启动聊天会话

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

#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

这一步部署失败,零碎并没给出起因!

正文完
 0