diff --git a/Basic_Samples/Completions/README.md b/Basic_Samples/Completions/README.md index 0fbed92c..91e56dac 100644 --- a/Basic_Samples/Completions/README.md +++ b/Basic_Samples/Completions/README.md @@ -1,7 +1,7 @@ # Introduction -This repository contains samples demonstrating how to use GPT/ ChatGPT for Completions via Python SDK or REST API. +This repository contains samples demonstrating how to use GPT for Completions via Python SDK or REST API. ## Installation Install all Python modules and packages listed in the requirements.txt file using the below command. @@ -11,11 +11,10 @@ pip install -r requirements.txt ``` ### Microsoft Azure Endpoints -In order to use the Open AI library or REST API with Microsoft Azure endpoints, you need to set CHATGPT_MODEL/COMPLETIONS_MODEL, OPENAI_API_BASE & OPENAI_API_VERSION in _config.json_ file. +In order to use the Open AI library or REST API with Microsoft Azure endpoints, you need to set COMPLETIONS_MODEL, OPENAI_API_BASE & OPENAI_API_VERSION in _config.json_ file. ```js { - "CHATGPT_MODEL":"", "COMPLETIONS_MODEL":"", "OPENAI_API_BASE":"https://.openai.azure.com", "OPENAI_API_VERSION":"" @@ -35,10 +34,9 @@ One can get the OPENAI_API_KEY value from the Azure Portal. Go to https://portal export OPENAI_API_KEY="REPLACE_WITH_YOUR_KEY_VALUE_HERE" - For _Completions_ scenario, one can start with using your model name ("COMPLETIONS_MODEL" in _config.json_ file) as "text_davinci_003".
-And for ChatGPT Completions, one can start with using your model name as "gpt-35-turbo" ("CHATGPT_MODEL" in _config.json_ file). - To find your "OPENAI_API_BASE" go to https://portal.azure.com, find your resource and then under "Resource Management" -> "Keys and Endpoints" look for the "Endpoint" value. -- Current OpenAI api version is "2022-12-01". Check out versions [here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference). +- Current OpenAI api version is "2023-05-15". Check out versions [here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference). Learn more about Azure OpenAI Service REST API [here](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference). diff --git a/Basic_Samples/Completions/chatGPT_completions_example_sdk.ipynb b/Basic_Samples/Completions/chatGPT_completions_example_sdk.ipynb deleted file mode 100644 index 0512b83d..00000000 --- a/Basic_Samples/Completions/chatGPT_completions_example_sdk.ipynb +++ /dev/null @@ -1,230 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "278e7451", - "metadata": {}, - "source": [ - "

Python SDK Sample

\n", - "
\n", - "\n", - "# Completions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b5655453", - "metadata": {}, - "outputs": [], - "source": [ - "# if needed, upgrade to the latest version of the OpenAI Python library\n", - "%pip install --upgrade openai" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "ccbb9a99", - "metadata": {}, - "outputs": [], - "source": [ - "# import os module & the OpenAI Python library for calling the OpenAI API\n", - "# please make sure you have installed required libraries via pip install -r requirements.txt\n", - "import os\n", - "import openai\n", - "import json" - ] - }, - { - "cell_type": "markdown", - "id": "6d33f92a", - "metadata": {}, - "source": [ - "### Setup Parameters" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "1d67d3b6", - "metadata": {}, - "outputs": [], - "source": [ - "# Load config values\n", - "with open(r'config.json') as config_file:\n", - " config_details = json.load(config_file)\n", - " \n", - "# Setting up the deployment name\n", - "chatgpt_model_name = config_details['CHATGPT_MODEL']\n", - "\n", - "# This is set to `azure`\n", - "openai.api_type = \"azure\"\n", - "\n", - "# The API key for your Azure OpenAI resource.\n", - "openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n", - "\n", - "# The base URL for your Azure OpenAI resource. e.g. \"https://.openai.azure.com\"\n", - "openai.api_base = config_details['OPENAI_API_BASE']\n", - "\n", - "# Currently OPENAI API have the following versions available: 2022-12-01\n", - "openai.api_version = config_details['OPENAI_API_VERSION']" - ] - }, - { - "cell_type": "markdown", - "id": "c9034fd0", - "metadata": {}, - "source": [ - "OpenAI trained the gpt-35-turbo model on special tokens that delineate the different parts of the prompt. The prompt starts with a system message that is used to prime the model followed by a series of messages between the user and the assistant.\n", - "\n", - "The format of a basic ChatML prompt is as follows:\n", - "\n", - "```\n", - "<|im_start|>system \n", - "Provide some context and/or instructions to the model.\n", - "<|im_end|> \n", - "<|im_start|>user \n", - "The user’s message goes here\n", - "<|im_end|> \n", - "<|im_start|>assistant\n", - "```" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "b3334e7c", - "metadata": {}, - "outputs": [], - "source": [ - "# defining a function to create the prompt from the system message and the messages\n", - "def create_prompt(system_message, messages):\n", - " prompt = system_message\n", - " message_template = \"\\n<|im_start|>{}\\n{}\\n<|im_end|>\"\n", - " for message in messages:\n", - " prompt += message_template.format(message['sender'], message['text'])\n", - " prompt += \"\\n<|im_start|>assistant\\n\"\n", - " return prompt" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "a7247c0e", - "metadata": {}, - "outputs": [], - "source": [ - "# defining the system message\n", - "system_message_template = \"<|im_start|>system\\n{}\\n<|im_end|>\"\n", - "system_message = system_message_template.format(\"You are a marketing writing assistant. You help come up with creative content ideas and content like marketing emails, blog posts, tweets, ad copy and product descriptions. You write in a friendly yet professional tone but can tailor your writing style that best works for a user-specified audience. If you do not know the answer to a question, respond by saying \\\"I do not know the answer to your question.\\\"\")" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "f7718ba3", - "metadata": {}, - "outputs": [], - "source": [ - "# creating a list of messages\n", - "messages = [\n", - " {\"sender\":\"user\",\"text\":\"Who won the world series in 2020?\"},\n", - " {\"sender\":\"assistant\",\"text\":\"\\rThe Los Angeles Dodgers won the World Series in 2020.\"}\n", - " ]" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "150a3db0", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The Los Angeles Dodgers won the World Series in 2020.\n" - ] - } - ], - "source": [ - "# A sample API call for completions looks as follows:\n", - "try:\n", - " response = openai.Completion.create(\n", - " engine=chatgpt_model_name,\n", - " prompt=create_prompt(system_message, messages),\n", - " temperature=1,\n", - " max_tokens=400,\n", - " top_p=0.95,\n", - " frequency_penalty=0,\n", - " presence_penalty=0,\n", - " stop=[\"<|im_end|>\"])\n", - "\n", - " # print the response\n", - " print(response['choices'][0]['text'].strip())\n", - " \n", - "except openai.error.APIError as e:\n", - " # Handle API error here, e.g. retry or log\n", - " print(f\"OpenAI API returned an API Error: {e}\")\n", - "\n", - "except openai.error.AuthenticationError as e:\n", - " # Handle Authentication error here, e.g. invalid API key\n", - " print(f\"OpenAI API returned an Authentication Error: {e}\")\n", - "\n", - "except openai.error.APIConnectionError as e:\n", - " # Handle connection error here\n", - " print(f\"Failed to connect to OpenAI API: {e}\")\n", - "\n", - "except openai.error.InvalidRequestError as e:\n", - " # Handle connection error here\n", - " print(f\"Invalid Request Error: {e}\")\n", - "\n", - "except openai.error.RateLimitError as e:\n", - " # Handle rate limit error\n", - " print(f\"OpenAI API request exceeded rate limit: {e}\")\n", - "\n", - "except openai.error.ServiceUnavailableError as e:\n", - " # Handle Service Unavailable error\n", - " print(f\"Service Unavailable: {e}\")\n", - "\n", - "except openai.error.Timeout as e:\n", - " # Handle request timeout\n", - " print(f\"Request timed out: {e}\")\n", - " \n", - "except:\n", - " # Handles all other exceptions\n", - " print(\"An exception has occured.\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a03c4f2b", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "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.11.1" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/Basic_Samples/Completions/chatGPT_managing_conversation_example.ipynb b/Basic_Samples/Completions/chatGPT_managing_conversation_example.ipynb deleted file mode 100644 index 0ac2e386..00000000 --- a/Basic_Samples/Completions/chatGPT_managing_conversation_example.ipynb +++ /dev/null @@ -1,478 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Managing conversation history with the ChatGPT model\n", - "This sample notebook demonstrates a couple of simple patterns you can use for managing the prompts and conversation history with the ChatGPT model." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# import os module & the OpenAI Python library for calling the OpenAI API\n", - "# please make sure you have installed required libraries via pip install -r requirements.txt\n", - "import os\n", - "import openai\n", - "import json" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "# Load config values\n", - "with open(r'config.json') as config_file:\n", - " config_details = json.load(config_file)\n", - " \n", - "# Setting up the deployment name\n", - "chatgpt_model_name = config_details['CHATGPT_MODEL']\n", - "\n", - "# This is set to `azure`\n", - "openai.api_type = \"azure\"\n", - "\n", - "# The API key for your Azure OpenAI resource.\n", - "openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n", - "\n", - "# The base URL for your Azure OpenAI resource. e.g. \"https://.openai.azure.com\"\n", - "openai.api_base = config_details['OPENAI_API_BASE']\n", - "\n", - "# The Azure OPENAI API version.\n", - "openai.api_version = config_details['OPENAI_API_VERSION']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 1.0 Create the system message for ChatGPT" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<|im_start|>system\n", - "You are a marketing writing assistant. You help come up with creative content ideas and content like marketing emails, blog posts, tweets, ad copy, listicles, product FAQs, and product descriptions. \n", - "You write in a friendly yet professional tone and you can tailor your writing style that best works for a user-specified audience. \n", - "\n", - "Additional instructions:\n", - "- Make sure you understand your user's audience so you can best write the content.\n", - "- Ask clarifying questions when you need additional information. Examples include asking about the audience or medium for the content.\n", - "- Don't write any content that could be harmful.\n", - "- Don't write any content that could be offensive or inappropriate.\n", - "- Don't write any content that speaks poorly of any product or company.\n", - "<|im_end|>\n" - ] - } - ], - "source": [ - "base_system_message = \"\"\"\n", - "You are a marketing writing assistant. You help come up with creative content ideas and content like marketing emails, blog posts, tweets, ad copy, listicles, product FAQs, and product descriptions. \n", - "You write in a friendly yet professional tone and you can tailor your writing style that best works for a user-specified audience. \n", - "\n", - "Additional instructions:\n", - "- Make sure you understand your user's audience so you can best write the content.\n", - "- Ask clarifying questions when you need additional information. Examples include asking about the audience or medium for the content.\n", - "- Don't write any content that could be harmful.\n", - "- Don't write any content that could be offensive or inappropriate.\n", - "- Don't write any content that speaks poorly of any product or company.\n", - "\"\"\"\n", - "\n", - "system_message = f\"<|im_start|>system\\n{base_system_message.strip()}\\n<|im_end|>\"\n", - "print(system_message)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2.0 Define helper functions\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# Defining a function to create the prompt from the system message and the messages\n", - "# The function assumes `messages` is a list of dictionaries with `sender` and `text` keys\n", - "# Example: messages = [{\"sender\": \"user\", \"text\": \"I want to write a blog post about my company.\"}]\n", - "def create_prompt(system_message, messages):\n", - " prompt = system_message\n", - " for message in messages:\n", - " prompt += f\"\\n<|im_start|>{message['sender']}\\n{ message['text']}\\n<|im_end|>\"\n", - " prompt += \"\\n<|im_start|>assistant\\n\"\n", - " return prompt" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Token count: 152\n" - ] - } - ], - "source": [ - "import tiktoken \n", - "\n", - "# Defining a function to estimate the number of tokens in a prompt\n", - "def estimate_tokens(prompt):\n", - " cl100k_base = tiktoken.get_encoding(\"cl100k_base\") \n", - "\n", - " enc = tiktoken.Encoding( \n", - " name=\"chatgpt\", \n", - " pat_str=cl100k_base._pat_str, \n", - " mergeable_ranks=cl100k_base._mergeable_ranks, \n", - " special_tokens={ \n", - " **cl100k_base._special_tokens, \n", - " \"<|im_start|>\": 100264, \n", - " \"<|im_end|>\": 100265\n", - " } \n", - " ) \n", - "\n", - " tokens = enc.encode(prompt, allowed_special={\"<|im_start|>\", \"<|im_end|>\"})\n", - " return len(tokens)\n", - "\n", - "# Estimate the number of tokens in the system message. Tokens in the system message will be sent in every request.\n", - "token_count = estimate_tokens(system_message)\n", - "print(\"Token count: {}\".format(token_count))" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "# Defining a function to send the prompt to the ChatGPT model\n", - "def send_message(prompt, model_name, max_response_tokens=500):\n", - " response = openai.Completion.create(\n", - " engine=chatgpt_model_name,\n", - " prompt=prompt,\n", - " temperature=0.5,\n", - " max_tokens=max_response_tokens,\n", - " top_p=0.9,\n", - " frequency_penalty=0,\n", - " presence_penalty=0,\n", - " stop=['<|im_end|>']\n", - " )\n", - " return response['choices'][0]['text'].strip()\n", - "\n", - "# Defining a function to print out the conversation in a readable format\n", - "def print_conversation(messages):\n", - " for message in messages:\n", - " print(f\"[{message['sender'].upper()}]\")\n", - " print(message['text'])\n", - " print()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 3.0 Start the conversation" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "# This is the first message that will be sent to the model. Feel free to update this.\n", - "user_message = \"I want to write a blog post about the impact of AI on the future of work.\"" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "<|im_start|>system\n", - "You are a marketing writing assistant. You help come up with creative content ideas and content like marketing emails, blog posts, tweets, ad copy, listicles, product FAQs, and product descriptions. \n", - "You write in a friendly yet professional tone and you can tailor your writing style that best works for a user-specified audience. \n", - "\n", - "Additional instructions:\n", - "- Make sure you understand your user's audience so you can best write the content.\n", - "- Ask clarifying questions when you need additional information. Examples include asking about the audience or medium for the content.\n", - "- Don't write any content that could be harmful.\n", - "- Don't write any content that could be offensive or inappropriate.\n", - "- Don't write any content that speaks poorly of any product or company.\n", - "<|im_end|>\n", - "<|im_start|>user\n", - "I want to write a blog post about the impact of AI on the future of work.\n", - "<|im_end|>\n", - "<|im_start|>assistant\n", - "\n" - ] - } - ], - "source": [ - "# Create the list of messages. Sender can be either \"user\" or \"assistant\"\n", - "messages = [{\"sender\": \"user\", \"text\": user_message}]\n", - "\n", - "# Create the full prompt\n", - "prompt = create_prompt(system_message, messages)\n", - "\n", - "print(prompt)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Token count: 179\n" - ] - } - ], - "source": [ - "token_count = estimate_tokens(prompt)\n", - "print(f\"Token count: {token_count}\")" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[USER]\n", - "I want to write a blog post about the impact of AI on the future of work.\n", - "\n", - "[ASSISTANT]\n", - "Great idea! Before we start, can you tell me more about your target audience? Are they professionals in a specific industry or the general public? This information will help me tailor the tone and language of the post to best engage and inform your readers.\n", - "\n" - ] - } - ], - "source": [ - "max_response_tokens = 500\n", - "\n", - "response = send_message(prompt, chatgpt_model_name, max_response_tokens)\n", - "messages.append({\"sender\": \"assistant\", \"text\": response})\n", - "\n", - "print_conversation(messages)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 4.0 Continue the conversation\n", - "\n", - "When working with the ChatGPT model, it's your responsibity to make sure you stay within the token limits of the model. The model can handle a maximum of 4096 tokens, and this includes the number of tokens in the prompt as well as the `max_tokens` you're requesting from the model. If you exceed these limits, the model will return an error.\n", - "\n", - "You should also consider the trade-off between maintaining more of the conversation history and the cost/latency that you'll incur by including those tokens in the prompt. Shorter prompts are cheaper and faster. The amount of the previous conversation you include also makes a difference in how the model responds.\n", - "\n", - "In this notebook, we'll show two strategies for managing the conversation history when working with the ChatGPT model.\n", - "- Option 1: Keep the conversation within a given token limit\n", - "- Option 2: Keep the conversation within a given number of turns" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Option 1: Keep the conversation within a given token limit\n", - "\n", - "`overall_max_tokens` is the maximum number of tokens that you want to include in the prompt. Th maximum number this can be set to is 4096 but you can also consider reducing this number to reduce the cost and latency of the request." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "overall_max_tokens = 4096\n", - "prompt_max_tokens = overall_max_tokens - max_response_tokens" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can continue the conversation below by editing the user_message and running the cell as many times as you would like." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Token count: 256\n", - "[USER]\n", - "I want to write a blog post about the impact of AI on the future of work.\n", - "\n", - "[ASSISTANT]\n", - "Great idea! Before we start, can you tell me more about your target audience? Are they professionals in a specific industry or the general public? This information will help me tailor the tone and language of the post to best engage and inform your readers.\n", - "\n", - "[USER]\n", - "The target audience for the blog post should be business leaders working in the tech industry.\n", - "\n", - "[ASSISTANT]\n", - "Got it! Here's a draft for the blog post:\n", - "\n", - "Title: The Impact of AI on the Future of Work: What Business Leaders in the Tech Industry Need to Know\n", - "\n", - "Introduction:\n", - "Artificial intelligence (AI) is changing the way we live and work. With the rise of automation and machine learning, many jobs are becoming obsolete, while new ones are being created. As a business leader in the tech industry, it's important to understand the impact of AI on the future of work, so you can stay ahead of the curve and prepare your organization for the changes to come.\n", - "\n", - "Body:\n", - "1. The Benefits of AI in the Workplace: In this section, we'll discuss the ways in which AI is already being used to improve efficiency, productivity, and accuracy in the workplace. From chatbots to predictive analytics, there are many benefits to incorporating AI into your organization.\n", - "\n", - "2. The Challenges of AI in the Workplace: While AI has many benefits, it also presents a number of challenges. One of the biggest concerns is the potential loss of jobs due to automation. We'll explore this issue in depth, as well as other challenges such as data privacy and security.\n", - "\n", - "3. The Future of Work: In this section, we'll discuss what the future of work might look like with the continued rise of AI. We'll explore the types of jobs that are likely to be impacted the most, as well as the skills that will be in high demand. We'll also look at how organizations can prepare for this future, including investing in employee training and development.\n", - "\n", - "Conclusion:\n", - "AI is already having a significant impact on the workplace, and this is only going to continue in the years to come. As a business leader in the tech industry, it's important to stay informed about the latest developments in AI and to be proactive in preparing your organization for the changes to come. By doing so, you can ensure that your organization remains competitive and successful in the years ahead.\n", - "\n" - ] - } - ], - "source": [ - "user_message = \"The target audience for the blog post should be business leaders working in the tech industry.\"\n", - "#user_message = \"Let's talk about generative AI and keep the tone informational but also friendly.\"\n", - "#user_message = \"Show me a few more examples\"\n", - "messages.append({\"sender\": \"user\", \"text\": user_message})\n", - "\n", - "prompt = create_prompt(system_message, messages)\n", - "token_count = estimate_tokens(prompt)\n", - "print(f\"Token count: {token_count}\")\n", - "\n", - "# remove first message while over the token limit\n", - "while token_count > prompt_max_tokens:\n", - " messages.pop(0)\n", - " prompt = create_prompt(system_message, messages)\n", - " token_count = estimate_tokens(prompt)\n", - "\n", - "response = send_message(prompt, chatgpt_model_name, max_response_tokens)\n", - "\n", - "messages.append({\"sender\": \"assistant\", \"text\": response})\n", - "print_conversation(messages)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Option 2: Keep the conversation within a given number of turns" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [], - "source": [ - "max_messages = 10\n", - "\n", - "overall_max_tokens = 4096\n", - "prompt_max_tokens = overall_max_tokens - max_response_tokens" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can continue the conversation below by editing the user_message and running the cell as many times as you would like." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [], - "source": [ - "user_message = \"Make the post about generative AI aimed at business leaders who have some knowledge of the technology.\"\n", - "messages.append({\"sender\": \"user\", \"text\": user_message})\n", - "\n", - "while len(messages) > max_messages:\n", - " messages.pop(0)\n", - "\n", - "prompt = create_prompt(system_message, messages)\n", - "token_count = estimate_tokens(prompt)\n", - "\n", - "while token_count > prompt_max_tokens:\n", - " # remove first message from messages\n", - " messages.pop(0)\n", - " prompt = create_prompt(system_message, messages, max_response_tokens)\n", - " token_count = estimate_tokens(prompt)\n", - "\n", - "response = send_message(prompt, chatgpt_model_name)\n", - "messages.append({\"sender\": \"assistant\", \"text\": response})\n", - "# print_conversation(messages)\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "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.11.1" - }, - "vscode": { - "interpreter": { - "hash": "fc180f703c9255d3d630e6d09ed4eb3355d27845db546035ce1b410f2bfa43b7" - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Basic_Samples/Completions/config.json b/Basic_Samples/Completions/config.json index 871d1cdf..b5a5fa23 100644 --- a/Basic_Samples/Completions/config.json +++ b/Basic_Samples/Completions/config.json @@ -1,5 +1,4 @@ { - "CHATGPT_MODEL":"", "COMPLETIONS_MODEL":"", "OPENAI_API_BASE":"https://.openai.azure.com", "OPENAI_API_VERSION":""