using JSON, Dates, UUIDs, PrettyPrinting, Base64, NATS, HTTP using GeneralUtils, msghandler config = JSON.parsefile("./appconfig.json") agent_conn = NATS.connect(config["nats_server_info"]["url"]) function text2text_instruct_llm(openai_msg::AbstractDict) payloads = [("msg", openai_msg, "dictionary")] # List of tuples _, msg_envelope_json_str = msghandler.smartpack( config["externalService"]["servicesloadbalancer"]["nats"], payloads; msg_purpose="text2text", broker_url=config["nats_server_info"]["url"], fileserver_url=config["externalService"]["fileserver"]["url"]) reply = NATS.request(agent_conn, config["externalService"]["servicesloadbalancer"]["nats"], msg_envelope_json_str, timeout=120) incoming_env_json_str = String(reply.payload) incoming_env = msghandler.smartunpack(incoming_env_json_str) _llm_response = incoming_env["payloads"][1][2] llm_response = _llm_response["choices"][1]["message"]["content"] return llm_response end # 1. Read local file and encode to base64 string image1_path = "test/large_image.png" image1_bytes = read(image1_path) image1_base64_string = base64encode(image1_bytes) # 2. Match the MIME type according to your file extension (e.g., png, jpeg) mime_type = "image/png" data1_uri = "data:$(mime_type);base64,$(image1_base64_string)" # 3. Construct payload with the Data URI openai_msg = Dict( "model" => "gemma-4-E4B-it-UD-Q4_K_XL", "messages" => [ Dict( "role" => "user", "content" => [ Dict("type" => "text", "text" => "Do you know this wine? Just give me brief intro."), Dict( "type" => "image_url", "image_url" => Dict("url" => data1_uri) ) ] ) ], "temperature" => 0.7 ) llm_response = text2text_instruct_llm(openai_msg) # 1. Read local file and encode to base64 string image2_path = "test/small_image.png" image2_bytes = read(image2_path) image2_base64_string = base64encode(image2_bytes) # 2. Match the MIME type according to your file extension (e.g., png, jpeg) mime_type = "image/png" data2_uri = "data:$(mime_type);base64,$(image2_base64_string)" openai_msg = Dict( "model" => "gemma-4-E4B-it-UD-Q4_K_XL", "messages" => [ Dict( "role" => "user", "content" => [ Dict("type" => "text", "text" => "Do you know this wine? Just give me brief intro."), Dict( "type" => "image_url", "image_url" => Dict("url" => data1_uri) ) ] ), Dict( "role" => "assistant", "content" => [ Dict("type" => "text", "text" => "Yes, I do!\n\nThis is **Asolo Bella Principessa**, a high-quality Italian sparkling wine made from the Prosecco region.\n\n### 🥂 Brief Intro\n\n* **What it is:** A Prosecco Superiore D.O.C.G., meaning it meets strict quality standards for a premium sparkling wine.\n* **Style:** It is a **Sparkling White Wine** and is designated as **Extra Dry**. This means it is crisp, refreshing, and has a dry finish (not overly sweet).\n* **Flavor Profile:** Expect bright, lively bubbles, often with notes of green apple, pear, and citrus.\n* **Best For:** It's a versatile wine, perfect for celebratory toasts, enjoying with appetizers (like seafood or charcuterie), or simply as a refreshing aperitivo."), ] ), Dict( "role" => "user", "content" => [ Dict("type" => "text", "text" => "How does this wine differ from earlier wine?"), Dict( "type" => "image_url", "image_url" => Dict("url" => data2_uri) ) ] ), ], "temperature" => 0.7 ) llm_response = text2text_instruct_llm(openai_msg)