{"id":1865,"date":"2023-02-07T18:19:59","date_gmt":"2023-02-07T10:19:59","guid":{"rendered":"https:\/\/pjq.me\/?p=1865"},"modified":"2023-02-07T18:39:43","modified_gmt":"2023-02-07T10:39:43","slug":"one-command-to-call-the-chatgpt-api","status":"publish","type":"post","link":"https:\/\/pjq.me\/?p=1865","title":{"rendered":"Bash Function for ChatGPT API Calls in Command Line"},"content":{"rendered":"\n<p>Write one bash function to call the ChatGPT API in the command line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function .gpt3 {\nif &#91; \"$#\" = 2 ];then\n        KEYWORD=\"$1\"\n        TEMPERATURE=$2\nelif &#91; \"$#\" = 1 ];then\n        KEYWORD=\"$1\"\n        TEMPERATURE=1.0\nelse\n        .log \"Usage $0 \"Question\" &#91;Temperature] \"\n        return -1\nfi\necho \"Keyword: ${KEYWORD}\"\necho \"Temperature: $TEMPERATURE\"\n\ncurl=`cat &lt;&lt;EOF\ncurl https:\/\/api.openai.com\/v1\/completions \\\n  -H 'Content-Type: application\/json' \\\n  -H \"Authorization: Bearer $OPENAI_API_KEY\" \\\n  -d '{\n  \"model\": \"text-davinci-003\",\n  \"prompt\": \"$KEYWORD\",\n  \"max_tokens\": 4000,\n  \"temperature\": $TEMPERATURE\n\n}' \\\n--insecure | jq -r '.choices&#91;]'.text\nEOF`\n\n.log $curl\neval ${curl}\n}<\/code><\/pre>\n\n\n\n<p>So I can run it in my terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.gpt3 \"Write the strategy about Mobile Performance testing\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Keyword: Write the strategy about Mobile Performance testing\nTemperature: 1.0\ncurl https:\/\/api.openai.com\/v1\/completions   -H 'Content-Type: application\/json'   -H \"Authorization: Bearer sk-qDrS3x7YrOV5tl57PFM1T3BlbkFJpI4rgQa8Nxxxxxxxxxxxxxx\"   -d '{\n  \"model\": \"text-davinci-003\",\n  \"prompt\": \"Write the strategy about Mobile Performance testing\",\n  \"max_tokens\": 4000,\n  \"temperature\": 1.0\n\n}' --insecure | jq -r '.choices&#91;]'.text\n  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n100  1818    0  1673  100   145    140     12  0:00:12  0:00:11  0:00:01   525\n\n\n1. Establish Performance Testing Goals and Objectives: Start by assessing the overall performance needs of the mobile application, including response times, memory usage, battery life, and other key factors. Establish performance testing goals and objectives based on these assessments, and document them accordingly.\n\n2. Select Performance Testing Platforms and Tools: Based on the performance objectives, choose performance testing platforms and tools that best suited to measure the desired performance criteria.\n\n3. Test Mobile Client Performance: Run and test the performance of the mobile client side of the application, including stress tests on file size and networking, as well as responsiveness and memory usage.\n\n4. Test Mobile Server Performance: Assess the mobile server\u2019s performance by measuring response times, scalability, and system load.\n\n5. Analyze Performance Test Results: Analyze the performance test results and compare them to the desired performance objectives. Take steps to fix any performance issues that are found.\n\n6. Fine-Tune Performance: Fine-tune the performance tests and revise them, if necessary, to address any changes to the application that may have occurred on either the client or server side.\n\n7. Repeat Performance Tests: Repeat performance tests on a regular basis, to ensure that the mobile application continues to meet performance objectives.<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Write one bash function to call the ChatGPT API in the command line So I can run it in my terminal<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[202,200,213],"class_list":["post-1865","post","type-post","status-publish","format-standard","hentry","category-tech","tag-ai","tag-chatgpt","tag-openai"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog<\/title>\n<meta name=\"description\" content=\"One Command to call the ChatGPT API with just one click\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pjq.me\/?p=1865\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"One Command to call the ChatGPT API with just one click\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pjq.me\/?p=1865\" \/>\n<meta property=\"og:site_name\" content=\"Jianqing&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-07T10:19:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-07T10:39:43+00:00\" \/>\n<meta name=\"author\" content=\"pengjianqing\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pengjianqing\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/pjq.me\/?p=1865#article\",\"isPartOf\":{\"@id\":\"https:\/\/pjq.me\/?p=1865\"},\"author\":{\"name\":\"pengjianqing\",\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"headline\":\"Bash Function for ChatGPT API Calls in Command Line\",\"datePublished\":\"2023-02-07T10:19:59+00:00\",\"dateModified\":\"2023-02-07T10:39:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/pjq.me\/?p=1865\"},\"wordCount\":30,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"keywords\":[\"AI\",\"ChatGPT\",\"OpenAI\"],\"articleSection\":[\"Tech\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/pjq.me\/?p=1865#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/pjq.me\/?p=1865\",\"url\":\"https:\/\/pjq.me\/?p=1865\",\"name\":\"Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/pjq.me\/#website\"},\"datePublished\":\"2023-02-07T10:19:59+00:00\",\"dateModified\":\"2023-02-07T10:39:43+00:00\",\"description\":\"One Command to call the ChatGPT API with just one click\",\"breadcrumb\":{\"@id\":\"https:\/\/pjq.me\/?p=1865#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/pjq.me\/?p=1865\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/pjq.me\/?p=1865#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/pjq.me\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Bash Function for ChatGPT API Calls in Command Line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/pjq.me\/#website\",\"url\":\"https:\/\/pjq.me\/\",\"name\":\"Jianqing&#039;s Blog\",\"description\":\"Thoughts and Future\",\"publisher\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/pjq.me\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60\",\"name\":\"pengjianqing\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png\",\"contentUrl\":\"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png\",\"width\":460,\"height\":752,\"caption\":\"pengjianqing\"},\"logo\":{\"@id\":\"https:\/\/pjq.me\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/pjq.me\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog","description":"One Command to call the ChatGPT API with just one click","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/pjq.me\/?p=1865","og_locale":"en_US","og_type":"article","og_title":"Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog","og_description":"One Command to call the ChatGPT API with just one click","og_url":"https:\/\/pjq.me\/?p=1865","og_site_name":"Jianqing&#039;s Blog","article_published_time":"2023-02-07T10:19:59+00:00","article_modified_time":"2023-02-07T10:39:43+00:00","author":"pengjianqing","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pengjianqing","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pjq.me\/?p=1865#article","isPartOf":{"@id":"https:\/\/pjq.me\/?p=1865"},"author":{"name":"pengjianqing","@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"headline":"Bash Function for ChatGPT API Calls in Command Line","datePublished":"2023-02-07T10:19:59+00:00","dateModified":"2023-02-07T10:39:43+00:00","mainEntityOfPage":{"@id":"https:\/\/pjq.me\/?p=1865"},"wordCount":30,"commentCount":0,"publisher":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"keywords":["AI","ChatGPT","OpenAI"],"articleSection":["Tech"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pjq.me\/?p=1865#respond"]}]},{"@type":"WebPage","@id":"https:\/\/pjq.me\/?p=1865","url":"https:\/\/pjq.me\/?p=1865","name":"Bash Function for ChatGPT API Calls in Command Line - Jianqing&#039;s Blog","isPartOf":{"@id":"https:\/\/pjq.me\/#website"},"datePublished":"2023-02-07T10:19:59+00:00","dateModified":"2023-02-07T10:39:43+00:00","description":"One Command to call the ChatGPT API with just one click","breadcrumb":{"@id":"https:\/\/pjq.me\/?p=1865#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pjq.me\/?p=1865"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pjq.me\/?p=1865#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pjq.me\/"},{"@type":"ListItem","position":2,"name":"Bash Function for ChatGPT API Calls in Command Line"}]},{"@type":"WebSite","@id":"https:\/\/pjq.me\/#website","url":"https:\/\/pjq.me\/","name":"Jianqing&#039;s Blog","description":"Thoughts and Future","publisher":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pjq.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/pjq.me\/#\/schema\/person\/0eb1e72d1e69fbbd9b5c0bfd8e2aae60","name":"pengjianqing","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pjq.me\/#\/schema\/person\/image\/","url":"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png","contentUrl":"https:\/\/pjq.me\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-02-at-6.10.58-PM.png","width":460,"height":752,"caption":"pengjianqing"},"logo":{"@id":"https:\/\/pjq.me\/#\/schema\/person\/image\/"},"url":"https:\/\/pjq.me\/?author=1"}]}},"views":1467,"_links":{"self":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/1865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1865"}],"version-history":[{"count":3,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions"}],"predecessor-version":[{"id":1869,"href":"https:\/\/pjq.me\/index.php?rest_route=\/wp\/v2\/posts\/1865\/revisions\/1869"}],"wp:attachment":[{"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pjq.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}