|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "716ae275", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "### Call using Ollama Python module" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": 2, |
| 14 | + "id": "b44ea4ad", |
| 15 | + "metadata": { |
| 16 | + "scrolled": false |
| 17 | + }, |
| 18 | + "outputs": [ |
| 19 | + { |
| 20 | + "name": "stdout", |
| 21 | + "output_type": "stream", |
| 22 | + "text": [ |
| 23 | + "<think>\n", |
| 24 | + "Okay, so the user has asked me to write four lines of a poem explaining why pizza and salad don't like each other. Hmm, interesting request. Let's break this down.\n", |
| 25 | + "\n", |
| 26 | + "First, I need to think about the elements that make pizza and salad incompatible. Pizza is usually loaded with cheese, meat, and tomato sauce—it’s rich and thick. Salad, on the other hand, has crisp vegetables, maybe avocado, and dressings like ranch or balsamic—that tend to be lighter and more acidic.\n", |
| 27 | + "\n", |
| 28 | + "So the poem should contrast these flavors and textures. Maybe pizza is heavy and sturdy, while salad is light and airy. That's a good start.\n", |
| 29 | + "\n", |
| 30 | + "Next, I want each line of the poem to touch on different aspects of their incompatibility. The first line could focus on the base elements: cheese and tomato sauce versus lettuce and avocado. Then move on to how they don't mix well together.\n", |
| 31 | + "\n", |
| 32 | + "I should consider how pizza is more substantial—like a hearty meal—and salad as lighter, maybe for appetizers or snacks. Their combination doesn’t work because one is too rich, and the other is too light.\n", |
| 33 | + "\n", |
| 34 | + "Another angle could be about their textures: pizza's chewiness versus salad's crispiness. Or perhaps the way they handle each bite differently—pizza being more satisfying in a single bite, while salad might require multiple bites to enjoy fully.\n", |
| 35 | + "\n", |
| 36 | + "I should make sure each line flows well and paints a vivid picture without using too complex words. It needs to be poetic but clear about why they don't mix.\n", |
| 37 | + "\n", |
| 38 | + "Also, considering the user asked for four lines, I need to ensure each line stands out and contributes to the overall message of their incompatibility.\n", |
| 39 | + "\n", |
| 40 | + "Alright, putting it all together: start with their base ingredients, move into texture and flavor profiles, then discuss how they complement or oppose each other. That should cover why pizza and salad don't get along well.\n", |
| 41 | + "</think>\n", |
| 42 | + "\n", |
| 43 | + "Sure! Here's a poetic take on your request:\n", |
| 44 | + "\n", |
| 45 | + "---\n", |
| 46 | + "\n", |
| 47 | + "In flavors so opposed, where could they meet? \n", |
| 48 | + "Pizza's cheese and tomato sauce entice, \n", |
| 49 | + "While salad's greens and avocado shine. \n", |
| 50 | + "Two worlds apart—they never seem to mesh. \n", |
| 51 | + "\n", |
| 52 | + "--- \n", |
| 53 | + "\n", |
| 54 | + "Let me know if you'd like more!\n" |
| 55 | + ] |
| 56 | + } |
| 57 | + ], |
| 58 | + "source": [ |
| 59 | + "from ollama import chat\n", |
| 60 | + "\n", |
| 61 | + "response = chat(model='deepseek-r1:7b', messages=[\n", |
| 62 | + " {\n", |
| 63 | + " 'role': 'user',\n", |
| 64 | + " 'content': 'Write 4 line on poem on why pizza and salad do not like each other',\n", |
| 65 | + " },\n", |
| 66 | + "])\n", |
| 67 | + "print(response.message.content)" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "markdown", |
| 72 | + "id": "326a862b", |
| 73 | + "metadata": {}, |
| 74 | + "source": [ |
| 75 | + "### Call using langchain" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": 3, |
| 81 | + "id": "a46dd482", |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [], |
| 84 | + "source": [ |
| 85 | + "from langchain_ollama import ChatOllama\n", |
| 86 | + "\n", |
| 87 | + "llm = ChatOllama(\n", |
| 88 | + " model=\"deepseek-r1:7b\",\n", |
| 89 | + " temperature=0.7,\n", |
| 90 | + ")" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 4, |
| 96 | + "id": "8310854f", |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "data": { |
| 101 | + "text/plain": [ |
| 102 | + "AIMessage(content='<think>\\nOkay, so I need to help the user by writing four-line poems about why pizza and salad don\\'t like each other. Hmm, let\\'s see. First, I should think about what makes pizza and salad incompatible.\\n\\nPizza is usually warm, circular, with cheese and sauce—those are rich, hearty flavors. On the other hand, salad is crisp, fresh, maybe with some tangy elements from dressing or herbs. The contrast between these two could be a good angle for the poem.\\n\\nI want each line to highlight different aspects of their differences. Maybe start by describing pizza first: warm, cheesy, in your mouth... Then move on to the salad\\'s crunch and freshness. \\n\\nWait, but how do I show they don\\'t like each other? Maybe through some sort of conflict or tension. Like, one is a feast, the other is light. Or perhaps their flavors clash—sweet vs. tangy.\\n\\nLet me try structuring it line by line:\\n\\nFirst line: Pizza\\'s description—warm, cheesy.\\nSecond line: Salad\\'s texture—crunchy and fresh.\\nThird line: Maybe something about conflict or not sharing.\\nFourth line: The result of their dislike—a silent debate or just not getting along.\\n\\nPutting that together... Let me see. Maybe \"Pizza is warm, cheesy, in your mouth.\" Then \"Salad is crunchy, with herbs too.\" Third line could be \"They don\\'t mix well,\" and the last one something like \"A silent debate begins.\"\\n\\nWait, I think that captures it. Each line introduces a different element of their nature and how they clash. It shows the contrast between the two foods and why they might not get along.\\n\\nI should make sure each line is vivid and paints a clear picture without being too complicated. Keeping it simple and straightforward would be best for the poem\\'s effect.\\n</think>\\n\\nPizza, warm and cheesy, \\nIn your mouth, rich and hearty. \\nSalad, crunchy with herbs, \\nA burst of fresh green delight. \\n\\nThey don\\'t mix well, you see, \\nA silent debate begins.', additional_kwargs={}, response_metadata={'model': 'deepseek-r1:7b', 'created_at': '2025-01-31T18:45:44.4632173Z', 'done': True, 'done_reason': 'stop', 'total_duration': 74310799100, 'load_duration': 72144200, 'prompt_eval_count': 29, 'prompt_eval_duration': 2233000000, 'eval_count': 423, 'eval_duration': 71507000000, 'message': Message(role='assistant', content='', images=None, tool_calls=None)}, id='run-b2390e82-c5fb-4a21-845c-20b9b3b6185b-0', usage_metadata={'input_tokens': 29, 'output_tokens': 423, 'total_tokens': 452})" |
| 103 | + ] |
| 104 | + }, |
| 105 | + "execution_count": 4, |
| 106 | + "metadata": {}, |
| 107 | + "output_type": "execute_result" |
| 108 | + } |
| 109 | + ], |
| 110 | + "source": [ |
| 111 | + "from langchain_core.messages import AIMessage\n", |
| 112 | + "\n", |
| 113 | + "messages = [\n", |
| 114 | + " (\n", |
| 115 | + " \"system\",\n", |
| 116 | + " \"You are a helpful assistant that can write creative poems\",\n", |
| 117 | + " ),\n", |
| 118 | + " (\"human\", \"Write 4 line on poem on why pizza and salad do not like each other\"),\n", |
| 119 | + "]\n", |
| 120 | + "ai_msg = llm.invoke(messages)\n", |
| 121 | + "ai_msg" |
| 122 | + ] |
| 123 | + } |
| 124 | + ], |
| 125 | + "metadata": { |
| 126 | + "kernelspec": { |
| 127 | + "display_name": "Python 3 (ipykernel)", |
| 128 | + "language": "python", |
| 129 | + "name": "python3" |
| 130 | + }, |
| 131 | + "language_info": { |
| 132 | + "codemirror_mode": { |
| 133 | + "name": "ipython", |
| 134 | + "version": 3 |
| 135 | + }, |
| 136 | + "file_extension": ".py", |
| 137 | + "mimetype": "text/x-python", |
| 138 | + "name": "python", |
| 139 | + "nbconvert_exporter": "python", |
| 140 | + "pygments_lexer": "ipython3", |
| 141 | + "version": "3.10.11" |
| 142 | + } |
| 143 | + }, |
| 144 | + "nbformat": 4, |
| 145 | + "nbformat_minor": 5 |
| 146 | +} |
0 commit comments