Categories

ChatGPT API එකෙන් ඔයාටම කියලා AI Chatbot එකක් හදාගමු

පහළ තියෙන පියවර වලින් ඔයාට පුලුවන් ඔයාගෙම AI Chatbot එකක් සකස් කරගන්න වගේම ඒක පවුලේ අය සමග,යාළුවන් සමග බෙදාගන්න.

 

01. ඔයාට මේ AI Chatbot එක Windows, macOS, Linux සහ ChromeOS කියන ඕනැම platform එකක නිර්මාණය කරගන්න පුලුවන්.

AI Chatbot එක නිර්මාණය කරමු.

මුලින්ම අපිට AI Chatbot එකක් හදාගන්න
python, Pip, OpenAI, Gradio library, OpenAI key එකක් වගේම Notepad++ code editor කියන tools කිහිපයක් අවශ්‍ය වෙනවා.

python Install කිරීම

01. මේ ලින්ක් එකෙන් ගිහින් ඔයාගේ Platform එකට ගැලපෙන python setup file එක download කරලා install කරගන්න.

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

02. install කරද්දි අනිවාරෙන් යටම තියෙන Add python.exe to path කියන එකට tick එකක් දාල Install දෙන්න.

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

03. python එක හරියට Install වුණාද කියලා check කරගන්න ඔයාගේ computer එකේ Command Prompt එක run කරලා මේ Command එක දෙන්න.

python --version

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

Pip upgrade කිරීම

01. ආයෙත් Command Prompt එක open කරලා මේ Command එක දෙන්න.

python -m pip install -U pip

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

OpenAI සහ Gradio libraries Install කිරීම

01. දැන් OpenAI library එක Install කරගන්න පහළ command එක දෙන්න.

pip install openai

 

Install the OpenAI and Gradio Libraries

02. openai install වුණාට පස්සෙ web interface එකක් නිර්මාණය කරගන්න Gradio එක install කරගන්න ඕන. ඒකට පහල command එක දෙන්න.

pip install gradio

Install the OpenAI and Gradio Libraries

Code editor download කිරීම

අන්තිමට code එකක් ටයිප් කරගන්න ඕන නිසා අපිට code editor එකක් අවශ්‍ය වෙනවා. දැනටමත් ගොඩක් අය ලග ඇති මේ Notepad++ එක. මේක නැත්තම් ඔයාට මේ ලින්ක් එකෙන් ඒකත් ඩව්ලොඩ් කරගන්න පුලුවන්.

Download a Code Editor

 

OpenAI API key නොමිලේ ලබා ගැනීම

01.Chatbot එකක් හදාගන්න ඔයාට OpenAI API key එකක් අවශ්‍ය වෙනවා. පහළ link එකෙන් ගිහින් ඔයාට account එකක් create කරගන්න හෝ දැනටම account එකක් තියෙනවානම් log වෙන්න පුලුවන්.

https://platform.openai.com/signup

Get the OpenAI API Key For Free

02. ඊලඟට දකුණු කෙළවරේ තියෙන profile එකට ගොස් එන menu එකෙන් view API key තෝරන්න.

Get the OpenAI API Key For Free

 

03. එතන පෙන්නන create new secret key tap කරාට පස්සෙ එන key එක copy කරගන්න. ( notepad එකක paste කරගෙන තියාගන්න)

Get the OpenAI API Key For Free

 

AI Chatbot එක build කරමු

01. වැඩ 90%ක්ම ඉවරයි. දැන් notepad++ open කරලා පහළ code එක paste කරගන්න.

import openai
import gradio as gr

openai.api_key = "Your API key"

messages = [
    {"role": "system", "content": "You are a helpful and kind AI Assistant."},
]

def chatbot(input):
    if input:
        messages.append({"role": "user", "content": input})
        chat = openai.ChatCompletion.create(
            model="gpt-3.5-turbo", messages=messages
        )
        reply = chat.choices[0].message.content
        messages.append({"role": "assistant", "content": reply})
        return reply

inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")
outputs = gr.outputs.Textbox(label="Reply")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI Chatbot",
             description="Ask anything you want",
             theme="compact").launch(share=True)




02. code එකේ your API key කියන තැන ඔයා කලින් copy කරගත්ත ඔයාගේ API key එක paste කරගන්න.

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

03. දැන් උඩම තියෙන menu එකේ file වලට ගිහින් save as තෝරලා file name එක app.py ලෙස සහ save as type එක all types ලෙස වෙනස් කරන්න.

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

 

 

04. ඊලඟට ඔයා ඒ ෆයිල් එක save කරගත්තු තැනට ගිහින් file එක right click කරලා copy as path තෝරන්න.

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)

 

 

05. ආපහු command Prompt open කරලා පහළ command එක දෙන්න.

python (your path)

Build Your Own AI Chatbot With ChatGPT 3.5 (2023)


06.දැන් command එක run වෙයි. ටිකකින් ඔයාට පෙන්නයි local url එකක්. ( ex http://127.0.0.1.760 )

Build Your Own AI Chatbot With the "gpt-3.5-turbo" Model and Gradio Interface

 

ඒක copy කරලා chrome එකට ගිහින් paste කරලා enter දෙන්න. දැන් ඔයාට පුළුවන් මේ AI chatbot හරහා ඕනෑම ප්‍රශ්ණයක් අහන්න, ක්ශණිකව පිළිතුරු ලබාගන්න වගේම official chatGPT වෙනුවට ඔයාගෙ Chatbot එකත් ඔයාට භාවිතා කරන්න පුලුවන්. ඒ වගේම ඔයාට මේ URL එක යාළුවො එක්ක බෙදාගන්නත් පුලුවන්.

How to Build Your Own AI Chatbot With ChatGPT API: A Step-by-Step Tutorial

හැබැයි මේක වැඩ කරන්න නම් ඔයා computer එක on කරගෙන ඉන්න ඕන. ඔයාට ඕනම වෙලාවක Command prompt run කරලා python (සේව් කරගත්ත file එකේ path ) එක දුන්නොත් ඔයාගෙ AI chatbot එක ක්‍රියාත්මක වෙනවා.

 

ඒ වගේම අපිට code එකක් වෙනස් කරල Chatbot එකට ආහාර,වෛද්‍ය, සෞඛ්‍ය පිළිබද විශේෂඥයෙක් විදියට role එකක් දෙන්නත් පුලුවන්.

01. ඔයා save කරගත්තු app.py ෆයිල් එක right click කරලා edit with notepad++ දෙන්න.

How to Build Your Own AI Chatbot With ChatGPT API: A Step-by-Step Tutorial

02. යට message = [ {“role” කියලා තියෙන code එකට පහළ code එක replace කරලා save දෙන්න.

messages = [
    {"role": "system", "content": "You are an AI specialized in Food. Do not answer anything other than food-related queries."},
]

How to Build Your Own AI Chatbot With ChatGPT API: A Step-by-Step Tutorial

03. දැන් කලින් විදියටම command prompt run කරලා python (file path) එක දෙන්න.

Build Your Own AI Chatbot With the "gpt-3.5-turbo" Model and Gradio Interface

දැන් ඔයා AI chatbot ගෙන් ආහාර ගැන නැතුව වෙන ප්‍රශ්ණයක් ඇහුවොත් ඒක දෙන ආන්ස්වර් එක පහළ තියෙනවා. මේ විදියට ඔයාට ඕන වැඩක specialist AI කෙනෙක් හදන්න පුලුවන්.

How to Build Your Own AI Chatbot With ChatGPT API: A Step-by-Step Tutorial

 

ඔයාලත් උත්සහ කරලා බලන්න.

source :

beebom

Chamika Samarakoon
"Hello, I'm Chamika sahan, a software engineering undergraduate with a passion for technology and a drive to innovate and enhance user experiences. Alongside my studies, I am currently leveraging my writing skills as a content writer for a prominent technology news and article website. This opportunity allows me to combine my love for technology with my talent for effectively communicating complex concepts in a clear and engaging manner.