{ "cells": [ { "cell_type": "markdown", "id": "865525ac-d33e-4f44-a670-451980d5e828", "metadata": {}, "source": [ "

Vison Agents

\n", "\n", "The goal of this notebook is to use a visual model to create agentic systems that work to produce visual content that they can (hopefully) iteratively refine." ] }, { "cell_type": "markdown", "id": "ad115e5e-e74b-4837-b07f-cbeb30257037", "metadata": {}, "source": [ "[

Groq + Llama Vision

](https://console.groq.com/docs/vision)" ] }, { "cell_type": "code", "execution_count": 2, "id": "4df0ad72-04a4-4b1f-bcaf-b1fb1cf0221f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ChatCompletionMessage(content='This is an image of a chip that is being viewed through a microscope.', role='assistant', function_call=None, tool_calls=None)\n" ] } ], "source": [ "from groq import Groq\n", "\n", "client = Groq()\n", "completion = client.chat.completions.create(\n", " model=\"llama-3.2-11b-vision-preview\",\n", " messages=[\n", " {\n", " \"role\": \"user\",\n", " \"content\": [\n", " {\n", " \"type\": \"text\",\n", " \"text\": \"What's in this image?\"\n", " },\n", " {\n", " \"type\": \"image_url\",\n", " \"image_url\": {\n", " \"url\": \"https://upload.wikimedia.org/wikipedia/commons/f/f2/LPU-v1-die.jpg\"\n", " }\n", " }\n", " ]\n", " }\n", " ],\n", " temperature=1,\n", " max_tokens=1024,\n", " top_p=1,\n", " stream=False,\n", " stop=None,\n", ")\n", "\n", "print(completion.choices[0].message)" ] }, { "cell_type": "code", "execution_count": 4, "id": "4c8b06f0-a689-4d5e-9027-daa2972d607f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This image shows a screenshot of YouTube video players and various programming screenshots and programming text that reads (translated) 'The Simplest Tech Stack' at the top, saying things like 'Go let's go ahead and do that', 'Under the templates directory' and code, which suggests a tutorial on code. For example, the yellow marker picks out parts of the image related to going ahead and doing something.\n", "\n", "The video players show mostly black screens with various videos' comments in white text. These include HTML/XML code under the title in the same screenshot as the title is shown at the top-left of the screenshot. White icons arranged in vertical rows are in the right and left margins, and the bars of some videos are visible at the bottom of the screenshot. This appears to be a screenshot from a tutorial that helps viewers build their own website.\n" ] } ], "source": [ "from groq import Groq\n", "import base64\n", "\n", "# Function to encode the image\n", "def encode_image(image_path):\n", " with open(image_path, \"rb\") as image_file:\n", " return base64.b64encode(image_file.read()).decode('utf-8')\n", "\n", "# Path to your image\n", "image_path = \"examples/data/sample.png\"\n", "\n", "# Getting the base64 string\n", "base64_image = encode_image(image_path)\n", "\n", "client = Groq()\n", "\n", "chat_completion = client.chat.completions.create(\n", " messages=[\n", " {\n", " \"role\": \"user\",\n", " \"content\": [\n", " {\"type\": \"text\", \"text\": \"What's in this image?\"},\n", " {\n", " \"type\": \"image_url\",\n", " \"image_url\": {\n", " \"url\": f\"data:image/jpeg;base64,{base64_image}\",\n", " },\n", " },\n", " ],\n", " }\n", " ],\n", " model=\"llama-3.2-11b-vision-preview\",\n", ")\n", "\n", "print(chat_completion.choices[0].message.content)" ] }, { "cell_type": "code", "execution_count": null, "id": "7bd1b552-805d-40d9-9341-1c530f939a22", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "groq", "language": "python", "name": "groq" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }