modelfusion icon indicating copy to clipboard operation
modelfusion copied to clipboard

Deno Compatibility

Open 7flash opened this issue 7 months ago • 11 comments

7flash avatar Nov 25 '23 07:11 7flash

It works "deno run main.ts"

main.ts

import { generateText, openai } from "npm:modelfusion";

But when I am trying to build with deno-esbuild, it seems to not support npm specifiers and therefore would be better if I could import modelfusion package directly from deno.land

 const { generateText } = await import("https://deno.land/x/modelfusion/mod.ts");

7flash avatar Nov 25 '23 08:11 7flash

As a temporary solution, following works:

    const { generateText } = await import('https://dev.jspm.io/modelfusion');  

7flash avatar Nov 25 '23 08:11 7flash

@7flash thanks for reporting the issue!

I'm not too familiar with Deno. From your report, my sense is that ideally modelfusion should work with deno-esbuild. Can you tell me the error that you encountered w/ deno-esbuild?

regarding deno.land, is that a separate pkg registry i would need to upload to?

lgrammel avatar Nov 25 '23 11:11 lgrammel

The issue https://github.com/evanw/esbuild/issues/3506 seemed to be resolved by using jspm and though it works for simple case it fails when trying to register tools because of another issue with zod https://github.com/colinhacks/zod/issues/2991

@7flash thanks for reporting the issue!

I'm not too familiar with Deno. From your report, my sense is that ideally modelfusion should work with deno-esbuild. Can you tell me the error that you encountered w/ deno-esbuild?

regarding deno.land, is that a separate pkg registry i would need to upload to?

7flash avatar Nov 25 '23 12:11 7flash

https://github.com/colinhacks/zod/issues/2991 is not a Zod error. ModelFusion contains something called ZodSchema as well (I want to change the name to disambiguate, but haven't come up with a better name yet).

See https://github.com/lgrammel/modelfusion/blob/main/src/core/schema/ZodSchema.ts

The error message points to a potential issue with zod-to-json-schema - do you know if zod to json schema works in deno? ( https://www.npmjs.com/package/zod-to-json-schema )

lgrammel avatar Nov 25 '23 12:11 lgrammel

Is there are a way to provide directy my json schema instead of zod? Because I am building kind of visual editor based on modelfusion where user ends up describing his tools in json format anyway

7flash avatar Nov 26 '23 03:11 7flash

@7flash yes, you can use new UncheckedSchema (see https://github.com/lgrammel/modelfusion/blob/main/examples/basic/src/util/schema/generate-structure-unchecked-json-schema-example.ts for an example).

This will not do any validation on the structure of the result tho, just cast it (which could be wrong at runtime).

You can also implement your own schema and json schema acccessor, see https://github.com/lgrammel/modelfusion/blob/main/src/core/schema/Schema.ts and https://github.com/lgrammel/modelfusion/blob/main/src/core/schema/JsonSchemaProducer.ts for the relevant interfaces (they both need to be implemented in a single object / class). That way, you can use other JSON validations like Validbot.

Please note that ModelFusion uses Zod internally for validations that are not related to user-defined schemas.

PS: I've added an uncheckedSchema(...) facade function in v0.83.0 as well as a zodSchema facade function to more clearly distinguish from the zod ZodSchema

lgrammel avatar Nov 26 '23 09:11 lgrammel

@lgrammel that's amazing, and here just recorded a demo of visual agent editor I am building with modelfusion: https://youtu.be/V-rI_ughijw

7flash avatar Nov 26 '23 10:11 7flash

@lgrammel that's amazing, and here just recorded a demo of visual agent editor I am building with modelfusion: https://youtu.be/V-rI_ughijw

Pretty cool! Do you have an open source project or a website? I have started a showcase section on the ModelFusion website, when the project is mature and available, this might be a good fit.

lgrammel avatar Nov 26 '23 13:11 lgrammel

@lgrammel that's amazing, and here just recorded a demo of visual agent editor I am building with modelfusion: https://youtu.be/V-rI_ughijw

Pretty cool! Do you have an open source project or a website? I have started a showcase section on the ModelFusion website, when the project is mature and available, this might be a good fit.

Yes it's here https://github.com/galaxydo/galaxy-polkadot

7flash avatar Nov 27 '23 02:11 7flash

@lgrammel that's amazing, and here just recorded a demo of visual agent editor I am building with modelfusion: https://youtu.be/V-rI_ughijw

Pretty cool! Do you have an open source project or a website? I have started a showcase section on the ModelFusion website, when the project is mature and available, this might be a good fit.

Yes it's here https://github.com/galaxydo/galaxy-polkadot

Awesome - feel free to send a pull request. The "story teller" example in the showcase shows what needs to be added (section & separate page)

lgrammel avatar Nov 28 '23 11:11 lgrammel