You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Heres a code snippet that takes in a user input and feeds it into ChatGPT and returns the response.
An OpenAI API key is required for it to work. The prompt can be amended to suit your needs/to create
your own custom agents.
/*Press `cmd+shift+enter` and enter the text you want to send to ChatGPT.*/// Name: Samantha// Description: Send a single prompt to ChatGPT// Shortcut: command shift enterimport"@johnlindquist/kit";let{ ChatOpenAI }=awaitimport("langchain/chat_models");let{ HumanChatMessage, SystemChatMessage }=awaitimport("langchain/schema");letopenAIApiKey=awaitenv("OPENAI_API_KEY",{hint: `Grab a key from <a href="https://platform.openai.com/account/api-keys">here</a>`,});let{ CallbackManager }=awaitimport("langchain/callbacks");letprompt=`#####You are ChatGPT, a large language model trained by OpenAI. Follow the user'sinstructions carefully. Respond using markdown.########`;letcurrentMessage="";constchat=newChatOpenAI({temperature: 0.3,openAIApiKey: openAIApiKey,streaming: true,callbackManager: CallbackManager.fromHandlers({handleLLMStart: async(token)=>{letwidget=awaitwidget(`<div class="bg-black text-white h-screen p-5"> Loading...<div>`);log(`handleLLMStart`);currentMessage+=token;lethtml=md(token);awaitdiv(html);},handleLLMNewToken: async(token,runId)=>{log(`handleLLMNewToken`);currentMessage+=token;lethtml=md(currentMessage);awaitdiv(html);},handleLLMError: async(err)=>{warn(`error`,JSON.stringify(err));awaitsetSelectedText(JSON.stringify(err));},handleLLMEnd: async()=>{widget=null;log(`handleLLMEnd`);lethtml=md(currentMessage);awaitdiv(html);},}),});lettextFromUser=awaitarg("How can I help you?");awaitchat.call([newSystemChatMessage(prompt),newHumanChatMessage(textFromUser)]);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Heres a code snippet that takes in a user input and feeds it into ChatGPT and returns the response.
An OpenAI API key is required for it to work. The prompt can be amended to suit your needs/to create
your own custom agents.
Beta Was this translation helpful? Give feedback.
All reactions