{ "cells": [ { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Our company builds AI Recommendation Systems for Matching Platforms using the latest technology company goliath\n", "sending request\n", "\n", "Goliath builds AI Recommendation Systems for Matching Platforms using the latest technology.\n", "Our company builds AI Recommendation Systems for Matching Platforms using the latest technology company we\n", "sending request\n", "\n", "We build AI Recommendation Systems for Matching Platforms using the latest technology.\n", "Our company is estabilished and operates in Japan company goliath\n", "sending request\n", "\n", "Our goliath is established and operates in Japan.\n", "Our company is estabilished and operates in Japan company we\n", "sending request\n", "\n", "Our we is established and operates in Japan.\n", "Our company uses the AWS Cloud to manage Servers company goliath\n", "sending request\n", "\n", "Goliath uses the AWS Cloud to manage Servers.\n", "Our company uses the AWS Cloud to manage Servers company we\n", "sending request\n", "\n", "We use the AWS Cloud to manage Servers.\n", "Our company can use GPT3 as well company goliath\n", "sending request\n", "\n", "Goliath can use GPT3 as well.\n", "Our company can use GPT3 as well company we\n", "sending request\n", "\n", "We can use GPT3 as well.\n", "Our company also builds GPT3-based chatbots company goliath\n", "sending request\n", "\n", "Goliath also builds GPT3-based chatbots.\n", "Our company also builds GPT3-based chatbots company we\n", "sending request\n", "\n", "We also build GPT3-based chatbots.\n", "Our company can use open-source models, if requested company goliath\n", "sending request\n", "\n", "Our goliath can use open-source models, if requested.\n", "Our company can use open-source models, if requested company we\n", "sending request\n", "\n", "If requested, we can use open-source models.\n", "Our company uses open source models. company goliath\n", "sending request\n", "\n", "Goliath uses open source models.\n", "Our company uses open source models. company we\n", "sending request\n", "\n", "We use open source models.\n" ] }, { "data": { "text/plain": [ "['Goliath operates in Japan',\n", " 'Goliath builds AI Recommendation Systems for Matching Platforms using the latest technology.',\n", " 'Goliath builds AI Recommendation Systems for Matching Platforms using the latest technology.',\n", " 'We build AI Recommendation Systems for Matching Platforms using the latest technology.',\n", " 'Our company builds AI Recommendation Systems for Matching Platforms using the latest technology',\n", " 'Our goliath is established and operates in Japan.',\n", " 'Our we is established and operates in Japan.',\n", " 'Our company is estabilished and operates in Japan',\n", " 'Goliath uses the AWS Cloud to manage Servers.',\n", " 'We use the AWS Cloud to manage Servers.',\n", " 'Our company uses the AWS Cloud to manage Servers',\n", " 'Goliath can use GPT3 as well.',\n", " 'We can use GPT3 as well.',\n", " 'Our company can use GPT3 as well',\n", " 'Goliath also builds GPT3-based chatbots.',\n", " 'We also build GPT3-based chatbots.',\n", " 'Our company also builds GPT3-based chatbots',\n", " 'Our goliath can use open-source models, if requested.',\n", " 'If requested, we can use open-source models.',\n", " 'Our company can use open-source models, if requested',\n", " 'Goliath uses open source models.',\n", " 'We use open source models.',\n", " 'Our company uses open source models.',\n", " 'The price of a recommendation system depends on the amount of complexity that is required to build, as well as the volume of customers. Reach us to get a quotation',\n", " 'The price of a chatbot depends by its intended usage and complexity, contact us for a quotation.',\n", " 'If your company wants to recommend products to customers, we can build a recommendation system for you',\n", " 'GPT3 can be used to build recommendation systems by using embeddings, mapping choices in a mathematical space',\n", " 'Once the recommendation system has been built, we will manage it in the future as well',\n", " 'Recommendation system could also be built for startups, though they will be in smaller size',\n", " 'We use AWS OpenSearch to host recommendation system.',\n", " 'A matching platform is a business with thousands of users, who could be customers, individuals or companies, who are interacting with one another. For example dating apps, ecommerce platforms, or job recruiting platforms.']" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import requests\n", "\n", "def gpt3_question(prompt):\n", " api_key = \"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\"\n", " api_endpoint = \"https://api.openai.com/v1/engines/text-davinci-003/completions\"\n", " headers = {\n", " \"Content-Type\": \"application/json\",\n", " \"Authorization\": f\"Bearer {api_key}\"\n", " }\n", " data = {\n", " \"prompt\": prompt,\n", " \"max_tokens\": 400,\n", " \"temperature\": 0.5\n", " }\n", " print('sending request')\n", " response = requests.post(api_endpoint, headers=headers, json=data)\n", " print(response)\n", " generated_text = response.json()[\"choices\"][0][\"text\"]\n", "\n", " return generated_text\n", "\n", "context_dict = {\n", " \"company; goliath; we\" : \n", " \"\"\"\n", " Our company builds AI Recommendation Systems for Matching Platforms using the latest technology. Our company is estabilished and operates in Japan. Our company uses the AWS Cloud to manage Servers. Our company can use GPT3 as well. Our company also builds GPT3-based chatbots. Our company can use open-source models, if requested. Our company uses open source models. Our company operates in Japan. Our company has been operating for 1 year, and we are expanding in Hong Kong. Our company offers other services apart from recommendation systems, like GPT3 chatbots. Our company can also build recommendation systems for mobile apps.\n", " \"\"\"\n", " ,\n", " \"price\" :\n", " \"\"\"\n", " The price of a recommendation system depends on the amount of complexity that is required to build, as well as the volume of customers. Reach us to get a quotation. The price of a chatbot depends by its intended usage and complexity, contact us for a quotation.\n", " \"\"\"\n", " ,\n", " \"recommendation system\" :\n", " \"\"\"\n", " If your company wants to recommend products to customers, we can build a recommendation system for you. GPT3 can be used to build recommendation systems by using embeddings, mapping choices in a mathematical space. Once the recommendation system has been built, we will manage it in the future as well. Recommendation system could also be built for startups, though they will be in smaller size. We use AWS OpenSearch to host recommendation system.\n", " \"\"\"\n", " ,\n", " \"a matching platform\" :\n", " \"\"\"\n", " A matching platform is a business with thousands of users, who could be customers, individuals or companies, who are interacting with one another. For example dating apps, ecommerce platforms, or job recruiting platforms. \n", " \"\"\"\n", "}\n", "\n", "def split_paragraph(text, keyword):\n", " list1 = [x.strip() for x in text.split('.')]\n", " list2 = []\n", " \n", " for sentence in list1:\n", " # Check if the sentence contains the phrase \"chamber of commerce\"\n", " if keyword in sentence.lower():\n", " list2.append(1)\n", " else:\n", " list2.append(0)\n", "\n", " #in case first sentence has no keyword, we add it\n", " if list2[0] == 0:\n", " list1[0] = f'the {keyword}: ' + list1[0]\n", " list2[0] = 1\n", "\n", " # print(list1)\n", " # print(list2)\n", "\n", " list3 = list()\n", " current_string = ''\n", " # Loop through each element of list1 and list2\n", " for i in range(len(list1)):\n", " # If the corresponding element in list2 is 1, add the current string to list3 and reset the current string\n", "\n", " if list2[i] == 1:\n", " list3.append(current_string)\n", " current_string = \"\" #reset\n", " current_string += list1[i]\n", "\n", " # Otherwise, concatenate the current string with the current element of list1\n", " if list2[i] == 0:\n", " current_string += '. '+list1[i]\n", "\n", " # Add the final concatenated string to list3\n", " list3.append(current_string)\n", "\n", " return [x.strip() for x in list3[1:]]\n", "\n", "def context_dict2context_list(context_dict):\n", " list1 = list()\n", " for all_keys in context_dict:\n", " key = all_keys.split(';')[0]\n", " try:\n", " synonyms = all_keys.split(';')[1:]\n", " except:\n", " pass\n", " # print(key)\n", " str1 = context_dict[all_keys]\n", " \n", " split_list = [x.replace('\\n', '').strip() for x in str1.split('\\n\\n')]\n", " split_list\n", "\n", " for sentence in split_list:\n", " for s in split_paragraph(sentence, key):\n", " #add synonyms\n", " for synonym in synonyms:\n", " #manual replacement causes a wrong grammar\n", " #gpt3 replacement\n", " print(s, key, synonym)\n", " prompt = f'in the following sentence: {s}. Replace {key} with {synonym} correcting the grammar'\n", " answer = gpt3_question(prompt).replace('\\n', '')\n", " list1.append(answer)\n", " list1.append(s)\n", " return list1\n", "\n", "#prepare context\n", "context_list = context_dict2context_list(context_dict)\n", "context_list" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sending request\n", "\n" ] }, { "data": { "text/plain": [ "'\\n\\nWe build AI Recommendation Systems for Matching Platforms using the latest technology.'" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = 'Our company builds AI Recommendation Systems for Matching Platforms using the latest technology'\n", "key = 'company'\n", "synonym = 'we'\n", "\n", "prompt = f'in the following sentence: {s}. Replace {key} with {synonym} correcting the grammar'\n", "gpt3_question(prompt).replace('\\n', '')" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'company'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "str1 = 'company; goliath; we'\n", "\n", "str1.split(';')[0]\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.13" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }