|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "59f98cf9", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "/home/aerdem/projects/nvidia/logits-processor-zoo\n" |
| 14 | + ] |
| 15 | + } |
| 16 | + ], |
| 17 | + "source": [ |
| 18 | + "%cd ../.." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 2, |
| 24 | + "id": "f2a86616", |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "# Run vllm serve like this:\n", |
| 29 | + "# vllm serve Qwen/Qwen2.5-1.5B-Instruct --dtype auto --api-key lpz-test --logits-processor-pattern \"logits_processor_zoo.vllm\"" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": 3, |
| 35 | + "id": "13f407ff", |
| 36 | + "metadata": {}, |
| 37 | + "outputs": [ |
| 38 | + { |
| 39 | + "name": "stdout", |
| 40 | + "output_type": "stream", |
| 41 | + "text": [ |
| 42 | + "Fried rice chicken is a popular Chinese dish that combines the flavors of fried rice with the tender texture and juicy meat of chicken. Here's a basic recipe to help you make it at home:\n", |
| 43 | + "\n", |
| 44 | + "### Ingredients:\n", |
| 45 | + "- 1 pound boneless skinless chicken breast or thighs (cut into bite-sized pieces)\n", |
| 46 | + "- 2 tablespoons vegetable oil\n", |
| 47 | + "- 3 cloves garlic, minced\n", |
| 48 | + "- 1 tablespoon ginger, grated\n", |
| 49 | + "- 1/4 cup soy sauce\n", |
| 50 | + "- 1/4 cup oyster sauce\n", |
| 51 | + "- 1 teaspoon sugar\n", |
| 52 | + "- 1/2 teaspoon salt\n", |
| 53 | + "- 1/4 teaspoon black pepper\n", |
| 54 | + "- 1 can (8 oz) condensed cream of mushroom soup\n", |
| 55 | + "- 1 cup frozen mixed vegetables (such as peas, carrots, corn)\n", |
| 56 | + "- 1/2 cup chopped green onions\n", |
| 57 | + "- 1/4 cup chopped cilantro\n", |
| 58 | + "\n", |
| 59 | + "### Instructions:\n", |
| 60 | + "\n", |
| 61 | + "#### Step 1: Prepare the Chicken\n", |
| 62 | + "1. **Marinate the Chicken:** In a bowl, mix together the chicken, soy sauce, oyster sauce, sugar, salt, and black pepper.\n", |
| 63 | + "2. **Cook the Chicken:** Heat the vegetable oil in a large skillet over medium-high heat. Add the marinated chicken and cook until browned on all sides, about 5 minutes per side. Remove from the pan and set aside.\n", |
| 64 | + "\n", |
| 65 | + "#### Step 2: Cook the Vegetables\n", |
| 66 | + "1. **Sauté the Vegetables:** In the same skillet, add the remaining 1 tablespoon of oil. Sauté the minced garlic and grated ginger for about 30 seconds until fragrant.\n", |
| 67 | + "2. **Add the Mixed Vegetables:** Stir in the frozen mixed vegetables and sauté until they start to soften, about 2-3 minutes.\n", |
| 68 | + "3. **Combine Everything:** Return the cooked chicken to the skillet along with the sautéed vegetables. Pour in the condensed cream of mushroom soup and stir well to combine everything.\n", |
| 69 | + "\n", |
| 70 | + "#### Step 3: Finish Cooking\n", |
| 71 | + "1. **Simmer the Sauce:** Bring the mixture to a simmer over low heat. Let it cook for about 5 minutes, stirring occasionally, until the sauce thickens slightly.\n", |
| 72 | + "2. **Serve:** Garnish with chopped green onions and cilantro before serving. This dish can be served hot or cold depending on your preference.\n", |
| 73 | + "\n", |
| 74 | + "Enjoy your homemade fried rice chicken! Adjust the seasoning according to your taste preferences.\n" |
| 75 | + ] |
| 76 | + } |
| 77 | + ], |
| 78 | + "source": [ |
| 79 | + "from openai import OpenAI\n", |
| 80 | + "\n", |
| 81 | + "model_name = \"Qwen/Qwen2.5-1.5B-Instruct\"\n", |
| 82 | + "\n", |
| 83 | + "client = OpenAI(\n", |
| 84 | + " base_url=\"http://localhost:8000/v1\",\n", |
| 85 | + " api_key=\"lpz-test\",\n", |
| 86 | + ")\n", |
| 87 | + "\n", |
| 88 | + "completion = client.chat.completions.create(\n", |
| 89 | + " model=model_name,\n", |
| 90 | + " messages=[\n", |
| 91 | + " {\"role\": \"user\", \"content\": \"Can you explain how fried rice chicken is cooked?\"}\n", |
| 92 | + " ], \n", |
| 93 | + " temperature=0,\n", |
| 94 | + " top_p=1\n", |
| 95 | + ")\n", |
| 96 | + "\n", |
| 97 | + "print(completion.choices[0].message.content)" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "code", |
| 102 | + "execution_count": 4, |
| 103 | + "id": "6227231c", |
| 104 | + "metadata": {}, |
| 105 | + "outputs": [ |
| 106 | + { |
| 107 | + "name": "stdout", |
| 108 | + "output_type": "stream", |
| 109 | + "text": [ |
| 110 | + "Fried rice chicken is a popular Chinese dish that combines the flavors of fried rice with the tender texture and juicy meat of chicken. Here's a basic recipe to help you make it at home:\n", |
| 111 | + "\n", |
| 112 | + "### Ingredients:\n", |
| 113 | + "- 1 pound boneless skinless chicken breast or thighs (cut into bite-sized pieces)\n", |
| 114 | + "- 2 tablespoons vegetable oil\n", |
| 115 | + "- 3 cloves garlic, minced\n", |
| 116 | + "- 1 tablespoon ginger, grated\n", |
| 117 | + "- 1/4 cup soy sauce\n", |
| 118 | + "- 1/4 cup oyster sauce\n", |
| 119 | + "- 1 teaspoon sugar\n", |
| 120 | + "- 1/2 teaspoon salt\n", |
| 121 | + "- 1/4 teaspoon black pepper\n", |
| 122 | + "- 1 can (8 oz) condensed cream of mushroom soup\n", |
| 123 | + "\n" |
| 124 | + ] |
| 125 | + } |
| 126 | + ], |
| 127 | + "source": [ |
| 128 | + "completion = client.chat.completions.create(\n", |
| 129 | + " model=model_name,\n", |
| 130 | + " messages=[\n", |
| 131 | + " {\"role\": \"user\", \"content\": \"Can you explain how fried rice chicken is cooked?\"}\n", |
| 132 | + " ],\n", |
| 133 | + " temperature=0,\n", |
| 134 | + " top_p=1,\n", |
| 135 | + " extra_body={\n", |
| 136 | + " \"logits_processors\": [{\n", |
| 137 | + " \"qualname\": \"logits_processor_zoo.vllm.GenLengthLogitsProcessor\",\n", |
| 138 | + " \"kwargs\": {\"tokenizer\": model_name, \"boost_factor\": 0.2, \"complete_sentences\": True}\n", |
| 139 | + " }]\n", |
| 140 | + " }\n", |
| 141 | + ")\n", |
| 142 | + "\n", |
| 143 | + "print(completion.choices[0].message.content)" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": null, |
| 149 | + "id": "96544ec2", |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [] |
| 153 | + } |
| 154 | + ], |
| 155 | + "metadata": { |
| 156 | + "kernelspec": { |
| 157 | + "display_name": "Python 3 (ipykernel)", |
| 158 | + "language": "python", |
| 159 | + "name": "python3" |
| 160 | + }, |
| 161 | + "language_info": { |
| 162 | + "codemirror_mode": { |
| 163 | + "name": "ipython", |
| 164 | + "version": 3 |
| 165 | + }, |
| 166 | + "file_extension": ".py", |
| 167 | + "mimetype": "text/x-python", |
| 168 | + "name": "python", |
| 169 | + "nbconvert_exporter": "python", |
| 170 | + "pygments_lexer": "ipython3", |
| 171 | + "version": "3.10.17" |
| 172 | + } |
| 173 | + }, |
| 174 | + "nbformat": 4, |
| 175 | + "nbformat_minor": 5 |
| 176 | +} |
0 commit comments