<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Fabric  - cant import AzureOpenAI in Hack Together</title>
    <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3703263#M65</link>
    <description>&lt;P&gt;Hi. I must have chose the wrong type of post. I was not Posting a question but a solution.&lt;/P&gt;&lt;P&gt;I followed the instructions from the github repo and ran into Thais issue. That's why I thought I'd post the solution for others to benefit.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 06:58:28 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-02-16T06:58:28Z</dc:date>
    <item>
      <title>Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3702288#M59</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;when you try to run the sample code in a fabric pyspark(python) notebook you might instantly hit the following issue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;ImportError&lt;/SPAN&gt;&lt;SPAN&gt;: cannot import name 'AzureOpenAI' from 'openai' (/home/trusted-service-user/cluster-env/trident_env/lib/python3.10/site-packages/openai/__init__.py)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is because the version 0.27.8 is the default in the fabric environment. To force a newer verison make sure to install it either inline or via an environment config&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;here is the inline code:&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%pip install openai==&lt;/SPAN&gt;&lt;SPAN&gt;1.12&lt;/SPAN&gt;&lt;SPAN&gt;.0&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 Feb 2024 20:08:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3702288#M59</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-15T20:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3702627#M61</link>
      <description>&lt;P&gt;You might want to take a look at this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="Access Azure OpenAI for Hack Together, for Free!" href="https://github.com/microsoft/Hack-Together-Fabric-AI/blob/main/AI_access.md" target="_self"&gt;Access Azure OpenAI for Hack Together, for Free!&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let us know if you managed to make it work.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2024 23:30:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3702627#M61</guid>
      <dc:creator>edchuy</dc:creator>
      <dc:date>2024-02-15T23:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3703263#M65</link>
      <description>&lt;P&gt;Hi. I must have chose the wrong type of post. I was not Posting a question but a solution.&lt;/P&gt;&lt;P&gt;I followed the instructions from the github repo and ran into Thais issue. That's why I thought I'd post the solution for others to benefit.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 06:58:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3703263#M65</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-16T06:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3703267#M66</link>
      <description>&lt;P&gt;here is the inline code needed at the top of your script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%pip install openai==1.12.0&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 06:59:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3703267#M66</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-16T06:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3704287#M70</link>
      <description>&lt;P&gt;OK. That's good to know.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 14:57:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3704287#M70</guid>
      <dc:creator>edchuy</dc:creator>
      <dc:date>2024-02-16T14:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3704321#M71</link>
      <description>&lt;P&gt;FYI. If you plan to run a notebook on a schedule or via Rest-API, then you'll have issues as %pip magic is disabled there. Need to create a custom environment with the correct openai dll pre-loaded and use that instead. Makes the startup of the notebook much slower though. instead of 5-10s for getting a running starterpool it will take 1-2 minutes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 15:11:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3704321#M71</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-16T15:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710707#M94</link>
      <description>&lt;P&gt;Hi! Do you know how to use this openai endpoint with Python? I am not sure how to authenticate correctly.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 10:19:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710707#M94</guid>
      <dc:creator>arminokic</dc:creator>
      <dc:date>2024-02-20T10:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710838#M95</link>
      <description>&lt;P&gt;The github page has all you need. the sample uses environment variables. not that simple in fabric. so if you want to get started fast, try putting the parameters into the code directly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instructions on getting started and getting your API Key here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/microsoft/Hack-Together-Fabric-AI/blob/main/AI_access.md" target="_blank"&gt;Hack-Together-Fabric-AI/AI_access.md at main · microsoft/Hack-Together-Fabric-AI · GitHub&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample code to talk to the api here&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/microsoft/azure-openai-service-proxy/blob/main/examples/python/openai_sdk_1.x/azure_openai_chat.py/?WT.mc_id=academic-120916-reneenoble" target="_blank"&gt;azure-openai-service-proxy/examples/python/openai_sdk_1.x/azure_openai_chat.py at main · microsoft/azure-openai-service-proxy · GitHub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and to make your life easier: here a snippet that worked for me. just replace the api key&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;%pip install openai==&lt;/SPAN&gt;&lt;SPAN&gt;1.12&lt;/SPAN&gt;&lt;SPAN&gt;.0&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; openai&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; openai &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; AzureOpenAI&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;client = AzureOpenAI(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;azure_endpoint&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;A href="https://polite-ground-030dc3103.4.azurestaticapps.net/api/v1" target="_blank"&gt;https://polite-ground-030dc3103.4.azurestaticapps.net/api/v1&lt;/A&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;api_key&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"your-api-key-from-the-step-previous"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;api_version&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"2023-09-01-preview"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;MESSAGES&lt;/SPAN&gt;&lt;SPAN&gt; = [&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;"role"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"system"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"content"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"""you are a funny bot"""&lt;/SPAN&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;"role"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"user"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"content"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"tell me a joke about pumpkins"&lt;/SPAN&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;"role"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"assistant"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"content"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"Why do pumpkins sit on people's porches? They have no hands to knock on the door!"&lt;/SPAN&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;MESSAGES&lt;/SPAN&gt;&lt;SPAN&gt;.append({&lt;/SPAN&gt;&lt;SPAN&gt;"role"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"user"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"content"&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;"tell me a joke about frogs"&lt;/SPAN&gt;&lt;SPAN&gt;})&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;completion = client.chat.completions.create(&lt;/SPAN&gt;&lt;SPAN&gt;model&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"gpt-35-turbo"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;messages&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;MESSAGES&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;temperature&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;0.9&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(completion.choices[&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;].message.content)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 20 Feb 2024 11:18:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710838#M95</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-02-20T11:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Fabric  - cant import AzureOpenAI</title>
      <link>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710849#M96</link>
      <description>&lt;P&gt;Thanks a lot. This was helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 11:21:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Hack-Together/Fabric-cant-import-AzureOpenAI/m-p/3710849#M96</guid>
      <dc:creator>arminokic</dc:creator>
      <dc:date>2024-02-20T11:21:39Z</dc:date>
    </item>
  </channel>
</rss>

