Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for separate output resolution model #1450

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jac-mtllm/examples/inherit_basellm.jac
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import from mtllm.llms.base { BaseLLM }
import:py from mtllm.llms { OpenAI }
import:py from PIL { Image }
import torch;
import from transformers { AutoModelForCausalLM, AutoProcessor }
Expand Down Expand Up @@ -85,6 +86,7 @@ obj Florence :BaseLLM: {
}

glob llm = Florence('microsoft/Florence-2-base');
glob llm2 = OpenAI(verbose=True, model_name="gpt-4o-mini");

enum DamageType {
NoDamage,
Expand All @@ -94,7 +96,8 @@ enum DamageType {
}

can ""
predict_vehicle_damage(img: Image) -> DamageType by llm(is_custom=True,raw_output=True);
# predict_vehicle_damage(img: Image) -> DamageType by llm(is_custom=True,raw_output=True);
predict_vehicle_damage(img: Image) -> DamageType by llm(is_custom=True,resolve_with =llm2);

with entry {
img = 'car_scratch.jpg';
Expand Down
11 changes: 8 additions & 3 deletions jac-mtllm/mtllm/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ def with_llm(
_globals,
_locals,
)
resolver_model = (
model_params.pop("resolve_with")
if "resolve_with" in model_params
else model
)
_output = (
model.resolve_output(
meaning_out
if raw_output
else resolver_model.resolve_output(
meaning_out, output_hint, output_type_explanations, _globals, _locals
)
if not raw_output
else meaning_out
)
return _output

Expand Down
Loading