Rh8 can't connect local ollama (but works with Rh7 python component)

Hi all, I’m trying to connect an ollama model through openAI compatible script.
The OpenAI script works well in VS code but failed to work in Rh8 Python component.

Full output is:

        {0}
  1. Rhino.Runtime.Code.Execution.ExecuteException: Environment “default” is corrupted due to a possible package installation failure
    —> Rhino.Runtime.Code.Environments.CorruptEnvironException: Environment “default” is corrupted due to a possible package installation failure
    at Rhino.Runtime.Code.Languages.PythonNet.CPythonEnviron.ThrowIfCorrupt()
    at Rhino.Runtime.Code.Languages.PythonNet.CPythonCode.Execute(RunContext context)
    at Rhino.Runtime.Code.Code.ExecTry(RunContext context, IPlatformDocument& doc, Object& docState)
    at Rhino.Runtime.Code.Code.Run(RunContext context)
    — End of inner exception stack trace —
    Rhino.Runtime.Code.Environments.CorruptEnvironException: Environment “default” is corrupted due to a possible package installation failure
    at Rhino.Runtime.Code.Languages.PythonNet.CPythonEnviron.ThrowIfCorrupt()
    at Rhino.Runtime.Code.Languages.PythonNet.CPythonCode.Execute(RunContext context)
    at Rhino.Runtime.Code.Code.ExecTry(RunContext context, IPlatformDocument& doc, Object& docState)
    at Rhino.Runtime.Code.Code.Run(RunContext context)

It works when I used an older script in Rhino 7 and copy to Rhino 8.

The script is referenced from a post from last year.

And it works well using Rh7 Python component, and copy-and-paste the compone to Rhino8 as well. (Screenshot below is the Rh7 component copied to Rh8)

I am happy to use the worked one in Rhino 8, but for long-term, it would be great if I could use it properly with new Python component in Rhion 8 with OpenAI compatible scripts.

My last attempt is to copy the old script into new (Rh8) python component, it shows urllib2 not found. But I failed to pip install urllib2 as well.

May I know how could I achieve both “connect the local ollama model” & “use Rh8 Python component” at the same time?

Thanks in advance!

(I am using the latest rhino (8.9.24194.18121, 2024-07-12), Educational license)

Quick updates:

For the “urllib2” approach, i resolved by updating the script from “urllib2”(python2) into “urllib.request” (python3)

For the OpenAI-compatible approach, I successfully pip-installed OpenAI library through ScriptEditor → Open Python 3 shell

However, it displays 404 when executing the script (despite the exact same script works normally in VS code)