{"id":153,"date":"2024-10-18T15:30:08","date_gmt":"2024-10-18T15:30:08","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/a_mermur\/?p=153"},"modified":"2024-10-18T15:30:08","modified_gmt":"2024-10-18T15:30:08","slug":"chatgpt-using-api","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/a_mermur\/2024\/10\/18\/chatgpt-using-api\/","title":{"rendered":"ChatGPT using api"},"content":{"rendered":"\n<p>Hi there! I&#8217;ve created a new Python script that uses the OpenAI API to interact with ChatGPT. Unfortunately, I&#8217;ve reached my API request limit, so I&#8217;ll have to wait until tomorrow to continue testing it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import openai\n\nopenai.api_key = \"You-Want-My-API?LOL\"\n\n\ndef chat_with_gpt(prompt):\n    response = openai.Completion.create(\n        model=\"gpt-3.5-turbo\",\n        messages=&#91;{\"role\": \"user\", \"content\": prompt}],\n    )\n\n    return response.choices&#91;0].message.content.strip()\n\n\nif __name__ == \"__main__\":\n    while True:\n        user_input = input(\"You: \")\n        if user_input.lower() in &#91;\"exit\", \"quit\", \"bye\", \"911\"]:\n            break\n\n        response = chat_with_gpt(user_input)\n        print(\"Chatbot:\", response)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi there! I&#8217;ve created a new Python script that uses the OpenAI API to interact with ChatGPT. Unfortunately, I&#8217;ve reached my API request limit, so I&#8217;ll have to wait until tomorrow to continue testing it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-free-friday"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":1,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/posts\/153\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/a_mermur\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}