#πŸ”’ Cohere-Terrarium and Packages

99 messages Β· Page 1 of 1 (latest)

frosty crow
#

Hi, I have https://github.com/cohere-ai/cohere-terrarium downloaded and running properly. It takes my code and runs it (I am using it to automatically run LLM generated code). I want to install new packages into this system for the LLM to be able to run, but unfortunately, the reference for doing so brings me to pyodide (https://pyodide.org/en/stable/usage/loading-packages.html) which I have never used before (nor do I have downloaded) and am struggling to understand the documentation. It mentions micropip, which I don't understand how to use without pyodide. I have tried

import json
import requests

def run_code(code) -> str:
        url = "http://localhost:8080"
        headers = {
            "Content-Type": "application/json"
        }
        jdata = {
            "code": code
        }
        response = json.loads(requests.post(url, headers=headers, json=jdata).text)
        print(response['std_out'])
        print(response['error']['message'])
        
run_code("""import pyodide_js as pyodide
await pyodide.loadPackage("micropip");
import micropip
""")```
but this gives me some obscure error: 

File "/lib/python3.11/site-packages/micropip/_compat_in_pyodide.py", line 7, in <module>
from pyodide.http import pyfetch
File "/lib/python311.zip/pyodide/http.py", line 9, in <module>
from js import Object
ImportError: cannot import name 'Object' from 'js' (unknown location)

Code context:
1: import pyodide_js as pyodide
2: await pyodide.loadPackage("micropip");
3: import mi```

not that I am even sure that trying to run micropip inside of cohere-terrarium makes sense in the first place.

fading geyserBOT
#

@frosty crow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frosty crow
#

@subtle timber i do see this thing called pyodide_cache with a list of wheels that get loaded when I start cohere-terrarium, but I have no idea where to get the wasm wheels to put into here

#

interestingly i had an idea, is it possible to install pyodide seperately, download the packages somewhere, and then drag it into my pyodide cache?

#

or does pyodide not work like that

subtle timber
#

You're running LLM generated code? That's not going to end well.

frosty crow
#

oh its mostly a fun project to replicate the chatgpt code compiler for me and a single other friend

#

it won't be shared online so there's no room for idiots to try to take over the system

#

but i thought it'd still be a good idea to sandbox it in case it runs file creation/deletion or smth

subtle timber
#

Yah, sandboxing is a good idea anyway and good xp

#

I don't know terrarium, let me check.. there's likely a pyodide javascript call that calls micropip to install.

frosty crow
#

idk im struggling with understanding where the "pyodide" part is

#

because i dont have pyodide installed

#

and while calling pyodide within the sandbox (which is where i thought it was) works, i cant seem to get micropip

subtle timber
#

Pyodide is a version of the Python interpreter that runs in web assembly (WASM)

#

WASM allows you to run compiled code inside a browser

frosty crow
#

right, so thats in the server that starts with the sandbox right?

subtle timber
#

Yah, if it's using Pyodide for sandboxing, then it probably is running a browser internally

frosty crow
#

yeah i guessed that much

frosty crow
subtle timber
#

Well, where did you get that code you're trying to run?

frosty crow
#

maybe micropip isnt installed

#

i coded it

#

im trying to install packages

#

the thing works

#

ie. i can run code in pyodide by sending requests

subtle timber
#

Yes, but that micropip code, where did you get that?

frosty crow
#
await pyodide_js.loadPackage('package_name')

Instead, the general advice is to use micropip.install() for everything except in the following cases where pyodide.loadPackage() might be more appropriate,

to load micropip itself,

when you are optimizing for size, do not want to install the micropip package, and do not need to install packages from PyPI with dependency resolution.
#

from what i understood

#

load package can be used to load micropip

#

so i am trying to do pyodide.loadPackage("micropip");

#

and then after it is loaded i try to import it

#

the loading part doesn't throw an error, but for some reason i cant import anything

subtle timber
#

Pyodide is a bit of a moving target, and I'm not impressed by this terrarium project (only 1 git issue ever?)

frosty crow
#

unless i misunderstood the error message

frosty crow
#

but well if this doesn't work im gonna have to go back to the drawing board and sandboxing seemed a little tricky so i was hoping this would just work πŸ’€

#

and i do have it working, its just solely this package thing

#

id be willing to bend over somehow if i could get the wasm packages or whatever pyodide needs elsewhere... but i cant figure out how to get them anywhere at all

subtle timber
#

But, here it is: await pyodide.loadPackage(["numpy", "matplotlib", "pandas"])

#

Add your module to that list

frosty crow
#

wait a sec lemme check

#

those might be preinstalled so im not sure

subtle timber
#

Altho it has a await pyodide.loadPackagesFromImports(code) line later, which should work too. What module are you trying to install?

frosty crow
#

requests...

subtle timber
#

Oh... that's a different issue

#

Due to browser security stuff, iirc, you need to use pyodide.http

frosty crow
#

im so sorry but i have no idea what that means

subtle timber
#

I might be out of date... checking

#

that means: not everything is allowed when running in a sandbox: requests, fo rinstance, could take data from your local network and push it to someone else

frosty crow
#

uhh

subtle timber
frosty crow
#

...ur right

subtle timber
frosty crow
#

well crap

#

i really needed requests πŸ’€

subtle timber
#

I'm saying it should work now.

frosty crow
#

no it doesn't

#

which is strange

#

beautifulsoup4 works?

subtle timber
#

THe package_log has pyodide 24.1

#

package_lock

frosty crow
#

is this pyodide outdated?

subtle timber
#

Yes.

frosty crow
#

god damn it

#

is an upgrade trivial or painful

subtle timber
#

Assuming you have 0.24.1, then this is Sep 2023, which is probs why your micropip and requests won't work.

subtle timber
frosty crow
#

uh... for someone whose never installed pyodide seperately how exactly do i update it?

subtle timber
#

Maybe just npm update pyodide... I'm not sure, I don't use node much

frosty crow
#

ok lets see

#

npm update pyodide

up to date, audited 137 packages in 1s

16 packages are looking for funding
run npm fund for details

8 vulnerabilities (1 low, 2 moderate, 5 high)

To address all issues, run:
npm audit fix

Run npm audit for details.

#

as someone also unfamiliar with javascript...

#

does this mean no packages were updated?

subtle timber
#

Oh, try: npm install pyodide@latest

frosty crow
#

it worked

#

holy shit

#

thank you so much

#

i never would've thought of this

#

hmm

#

something still isn't right

#

there's gotta be something in this package making pyodide not work :/

frosty crow
# subtle timber Oh, try: `npm install pyodide@latest`

for some incredibly strange reason both requests and pyodide.http trigger ImportError: cannot import name 'Object' from 'js' (unknown location)
whereas aiohttp truggers RuntimeError: asyncio.run() cannot be called from a running event loop (the same code runs fine normally)

#

the code causing the problem being response = requests.get(url) or url_contents = pyodide.http.open_url(url) ... etc

#

wait

#

thats because im stupid

#

NO network nor internet access (this is a current design choice and could be changed in the future)

subtle timber
#

You could also just build your own sandbox using pyscript (which also uses pyodide)

#

Just depends how you're trying to run it

fading geyserBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.