Do you support custom LLMs?
Show HN: Magentic – Use LLMs as simple Python functions
51–60 of 70 posts
Re: Show HN: Magentic – Use LLMs as simple Python functions
#52Earlier quoted context omitted.
Oh, and some companies offer APIs that match the OpenAI API and there are some open-source projects that do this for llama running locally. Since those would be compatible with the openai python package they will work with magentic too - though some of these do not support function calling. See for example Anyscale Endpoints https://app.endpoints.anyscale.com/landing and https://github.com/AmineDiro/cria
There's also LocalAI[0] which allows the use of local LLMs with an OpenAI compatible API. [0] https://github.com/go-skynet/LocalAI
Re: Show HN: Magentic – Use LLMs as simple Python functions
#53Awesome job with the simplicity, gonna play with it. Have you tried using yaml as the format with the models instead of JSOn? Feel like you'll use far fewer tokens to describe the same thing. Perhaps it's a bit more forgiving as well. EDIT: Just tried using the decorator to output a fairly complex pydantic model and it failed with "magentic.chat_model.openai_chat_model.StructuredOutputError: Failed to parse model out…
In the meantime, have a look at the ValidationError traceback which might highlight a specific field that is causing the issue. Some options to resolve the issue might be: the type for this field could be made more lenient (e.g. str); the `Annotated` type hint could be used to give the field a description to help correct the error [0]; the field could be removed. You could also try using gpt-4 by setting the env var MAGENTIC_OPENAI_MODEL [1].
If none of these help resolve it or it appears to be an issue with magentic itself please file a github issue with an example. Comments on how to improve error messages and debugging are also welcome! Thanks for trying it out.
[0] https://docs.pydantic.dev/latest/concepts/fields/#using-anno...
Re: Show HN: Magentic – Use LLMs as simple Python functions
#54Does this do System vs. Assistant vs. User prompting?
Re: Show HN: Magentic – Use LLMs as simple Python functions
#55Re: Show HN: Magentic – Use LLMs as simple Python functions
#56Then I kept on reading, and I have to admit that the object creation with LLMs is really amazing!
Re: Show HN: Magentic – Use LLMs as simple Python functions
#57Curious as to why you chose to do it as a decorator instead of just a function call?
I found this was the most compact way to represent what I wanted to define, and makes it easy to keep the type hints for parameters. If you look inside `@prompt` it's creating a `PromptFunction` instance which I think would be a similar API to what you would end up with without using decorators https://github.com/jackmpcollins/magentic/blob/afdb22513385b...
Re: Show HN: Magentic – Use LLMs as simple Python functions
#58The API looks very clean. Today I learned about "..." in Python
It is just a noop, but here it looks very appropriate/readable because it reads as saying "AI will fill this in".
In other words, it happens to work and look neat, but pass is the correct way to do it.
Re: Show HN: Magentic – Use LLMs as simple Python functions
#59This library is impressive, I appreciate it and I will apply it to my project.
Re: Show HN: Magentic – Use LLMs as simple Python functions
#60I am amazed that `...` is a valid syntax in Python, not a pseudo grammar. This library is impressive, I appreciate it and I will apply it to my project.