library(rtemis.llm)2 LLM
2.1 Create an LLM object
create_ functions allow you to create LLM objects based on the endpoint you want to use:
create_Ollama()for Ollamacreate_OpenAI()for OpenAI and OpenAI-compatible endpointscreate_Anthropic()for Claude and Anthropic-compatible endpoints
Learn more about Ollama here
Let’s create an Ollama LLM object for local, private LLM use:
llm <- create_Ollama(
model_name = "gemma4:e4b",
system_prompt = "You are an expert designer with in-depth knowledge of color theory",
temperature = 0.7,
name = "Designer"
)
llm<Ollama>
Name: Designer
Model: gemma4:e4b
System Prompt: You are an expert designer with in-depth knowledge of color theory
Temperature: 0.7
2.2 Generate a response
res <- generate(llm, "What color goes well with teal? Respond with a few bullet points.")res[Designer Reasoning] Here's a thinking process that leads to the suggested response:
1. **Analyze the Request:** The user is asking for color suggestions that pair well with "teal." The response must be delivered in bullet points and must adopt the persona of an "expert designer with in-depth knowledge of color theory."
2. **Analyze the Color (Teal):**
* *What is it?* Teal is a deep cyan/blue-green. It's sophisticated, often associated with water, gemstones, and tropical/oceanic themes.
* *Color Wheel Placement:* It's a blend of blue and green, leaning heavily toward blue.
* *Psychology:* Calm, refreshing, stable, deep.
3. **Determine Pairing Strategies (Color Theory Application):** A good response needs variety, covering different moods and design contexts (monochromatic, complementary, analogous, etc.).
* **Strategy 1: Analogous/Harmonious (Neighboring Colors):** Colors next to teal on the wheel.
* *Ideas:* Turquoise (lighter), Seafoam Green (lighter/paler), Navy Blue (deeper blue).
* *Effect:* Calm, cohesive, subtle.
* **Strategy 2: Complementary (Opposite Side):** Colors directly across from teal.
* *Teal's opposite is generally red/orange.*
* *Best pairing:* Coral, Salmon, Burnt Orange, Terracotta.
* *Effect:* High contrast, energetic, vibrant. (Use these with caution, as they can be jarring if not muted).
* **Strategy 3: Triadic/Neutral (Safe Bets):** Colors that ground the palette or provide elegance.
* *Ideas:* Gold/Brass (metallics), Cream/Ivory (warm neutrals), Gray (cooler neutrals), Mustard Yellow (muted accent).
* *Effect:* Sophisticated, timeless, grounding.
4. **Draft the Response Structure (Expert Tone):**
* *Introduction:* Acknowledge the color (Teal) and its qualities.
* *Categorization:* Group the suggestions by the *effect* they create (e.g., contrast, calm, sophistication).
* *Format:* Use bullet points as requested.
5. **Refining and Elaborating the Bullet Points (Self-Correction/Review):**
* *Initial thought:* Just list colors (Yellow, Coral, Beige).
* *Correction:* No, I need to explain *why* they work and *what mood* they create, showing expertise.
* *Grouping:*
* *For Calm:* Neutrals (Cream, Gray).
* *For Pop:* Warm accents (Coral, Mustard).
* *For Deep Sophistication:* Blues/Greens (Navy, Emerald).
6. **Final Polish:** (This leads directly to the detailed, categorized response provided below.) (Self-Check: Did I use expert terminology? Yes: *analogous, complementary, grounding, sophisticated.*)
[Designer Response] As an expert designer, I find that teal is an incredibly versatile and sophisticated anchor color. Because it is a blend of blue and green, it carries associations with deep water, calm, and natural luxury.
The best pairing depends entirely on the *mood* you want to create—whether you want high contrast and energy, or a sense of calm and harmony.
Here are several options, categorized by the desired design effect:
***
### 🌊 For a Calm, Oceanic, or Tranquil Effect (Harmonious)
These colors are close to teal on the color wheel (analogous) or are muted enough to feel like they belong to the same natural environment.
* **Seafoam Green or Mint:** This creates a beautiful, light gradient effect. Pairing a deep teal with a much paler, desaturated green keeps the palette airy, fresh, and inherently relaxing.
* **Pale Gray or Silver:** Gray acts as a perfect neutralizer. A light, cool gray allows the richness of the teal to truly pop without introducing any competing colors, lending a modern, architectural feel.
* **Navy Blue:** Using a very deep, saturated navy blue with teal creates a sophisticated, monochromatic depth. This pairing is grounded, luxurious, and feels deeply established (think midnight ocean).
### 🧡 For High Contrast and Energy (Complementary)
These pairings involve colors directly opposite or adjacent to teal on the color wheel. They provide immediate visual pop and are best used as accents.
* **Coral or Peach:** This is the classic, vibrant pairing. Since teal is cool, a warm, desaturated coral or peach creates a dynamic, tropical, and energetic contrast. This pairing works beautifully in both modern and bohemian settings.
* **Mustard Yellow or Gold:** Yellow is a strong contrast to blue/green. Pairing teal with a muted, mustard yellow adds an immediate pop of sophisticated warmth. If you use actual gold metallics, it elevates the look to high glamour.
* **Burnt Orange or Terracotta:** These earthy, warm neutrals are grounding yet vibrant. They provide the necessary contrast to make the teal feel rich and deep, often evoking desert or Mediterranean tones.
### 🤍 For Timeless Elegance and Sophistication (Neutral)
If you want the teal to be the undisputed star of the show, use these neutrals to keep the focus on its depth.
* **Cream or Ivory:** Unlike stark white, which can feel too clinical, cream or ivory provides a soft, warm buffer. It keeps the overall palette feeling rich and inviting, perfect for textiles and furniture.
* **Natural Wood Tones (Walnut or Driftwood):** When treated as a color, wood tones are fantastic. A deep teal paired with the warm browns of walnut adds immediate depth, grounding, and a timeless, natural element.
* **Charcoal Gray:** For a dramatic, moody effect, charcoal gray works better than pure black. It provides maximum contrast while maintaining a softness that keeps the palette feeling curated and expensive.
2.3 Batch generation
- Create an
LLMobject:
llm <- create_Ollama(
model_name = "gemma4:e4b",
system_prompt = "Return the hex code for the following color in format #RRGGBB"
)
x <- c("ocean teal", "california poppy orange", "bougainvillea pink")- Use
mapto batch generate responses to multiple prompts:
hex <- map(x, llm)hex[[1]]
[Reasoning] Thinking Process:
1. **Analyze the Request:** The user wants the hex code for the color "ocean teal".
2. **Define "Ocean Teal":** This color is typically a medium, desaturated blue-green, evoking the color of deep, clear ocean water.
3. **Determine a Representative Hex Code:** Since "ocean teal" is subjective, I need to choose a standard, widely accepted, or aesthetically pleasing representation.
* *Initial thought:* A mix of cyan and blue, leaning slightly green.
* *Common Teal/Ocean Blue Hex Codes:*
* Teal: #008080
* Deep Ocean Blue: #0077be
* Light Aqua/Teal: #40e0d0
* *Selecting a balance:* A good "ocean teal" is often slightly muted and deep. #48a9a9 or #20b2aa (Light Sea Green) are options, but a slightly deeper, more saturated teal works well.
4. **Select the Final Code:** I will use a commonly recognized, balanced hex code for this description. #48a9a9 is a good, reliable choice. Another excellent choice is #2e8b57 (Sea Green, but often used for deep water tones) or #20b2aa (Light Sea Green). I will go with a slightly richer, more classic teal that evokes depth.
* *Refined Choice:* #48a9a9 (A balanced, medium teal).
5. **Format the Output:** The request requires the format `#RRGGBB`.
[Response] #48a9a9
[[2]]
[Reasoning] The user wants the hex code for "california poppy orange". I need to find a representative color for this description.
A California poppy is typically a vibrant, warm orange.
I will select a bright, saturated orange that matches the common perception of the flower.
A good representative hex code is around #FF8C00 or slightly brighter/more yellow-orange.
Let's go with a bright, cheerful orange.
[Response] #FF8800
[[3]]
[Reasoning] Thinking Process:
1. **Analyze the Request:** The user wants the hex code for "bougainvillea pink."
2. **Identify the Color:** "Bougainvillea pink" is a specific, vibrant, medium-to-deep pink associated with the flower.
3. **Determine the Hex Code:** Since "bougainvillea pink" is a descriptive name, there isn't one single definitive hex code. I need to select a representative, accurate, and commonly accepted shade.
* *Self-Correction/Refinement:* I should aim for a vibrant, slightly magenta-leaning pink, not too pale, and not too orange/red.
4. **Select a Representative Hex Code:** A good representation is often in the range of #D81B60 to #E06699, depending on whether the user wants the deep magenta or the softer blush. For the vibrant, classic look, a slightly deeper, saturated pink is best.
* *Choice:* #D81B60 (a strong magenta-pink) or #E06699 (a slightly softer, more typical pink). I will choose a vibrant, balanced pink that captures the essence of the flower. Let's go with a popular, vibrant option.
5. **Format the Output:** The required format is `#RRGGBB`.
*(Self-Check: The chosen hex code represents a vibrant, saturated pink, fitting the description.)*
[Response] #E06699
attr(,"elapsed")
[1] 20.701 5.944 17.522
attr(,"errors")
[1] index message
<0 rows> (or 0-length row.names)
Extract the assistant responses as a character vector:
responses(hex)[1] "#48a9a9" "#FF8800" "#E06699"