Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

提示.js

Posted on 2024-12-08

提示.js

我一直在测试 OpenAI 的新 o1 模型,尤其是代码方面。我印象非常深刻 – 感觉它给了我与 Claude 3.5 Sonnet 类似的代码质量,至少对于 Python、JavaScript 和 Bash 来说是这样……但它返回输出的速度明显更快。

我决定尝试构建一个我已经考虑了一段时间的库 – 浏览器内置的alert() 、 confirm()和prompt()函数的基于await ...的替代实现。

简短版本:它可以让你这样做:

等待提示。警报(  
    “这是一条警报信息!”  
) ;  
  
const确认Boolean =等待提示。确认(  
    “你确定要继续吗?”  
) ;  
  
const nameString =等待提示。迅速的(  
    “请输入您的姓名”  
) ;

这是源代码和现场演示,您可以在其中试用:

Prompts.js 的动画演示 - 三个按钮,一个用于显示警报,一个用于显示确认,一个用于显示提示。警报显示一条警报消息,确认按钮询问您是否要继续使用返回 true 或 false 的“确定”和“取消”按钮,提示按钮询问您的姓名并以字符串形式返回,如果取消则返回 null。

我认为以这种方式使用await确实很有趣。

过去,每次我在 Python 或 JavaScript 中使用它时,我都会期望我正在等待的东西会尽快返回 – 我实际上只是将其用作性能黑客来解锁事件循环并允许它在我等待操作完成时执行其他操作。

这实际上根本没有必要!对于可能需要很长时间才能完成的操作(例如用户与模式对话框交互),没有理由不使用await 。

有法学硕士来帮助构建这种图书馆想法的原型真的很有趣。这是另一个例子,如果没有一个模型来为我完成大部分代码编写工作,我可能不会费心去探索。

我并没有完全通过一个提示来得到它,但是在与 o1 来回进行了一些操作之后,我得到了我想要的东西 – 首先缺少的是合理的键盘支持(特别是 Enter 和 Escape 键) 。

我的打开提示如下:

Write me a JavaScript library - no extra dependencies - which gives me the following functions:

await Prompts.alert("hi there"); -> displays a modal with a message and waits for you to click OK on it
await Prompts.confirm("Are you sure") -> an OK and cancel option, returns true or false<br> await Prompts.prompt("What is your name?") -> a form asking the user's name, an OK button and cancel - if cancel returns null otherwise returns a string

These are equivalent to the browser builtin alert() and confirm() and prompt() - but I want them to work as async functions and to implement their own thing where they dull out the screen and show as a nicely styled modal

All CSS should be set by the Javascript, trying to avoid risk of existing CSS interfering with it

这是完整的共享 ChatGPT/o1 记录。

然后,我使用 Google 的新gemini-exp-1206模型来编写 README 的初稿,这次是通过我的 LLM 工具:

 cat index.js | llm -m gemini-exp-1206 -s \ 'write a readme for this suitable for display on npm'

这是回应。我最终对此进行了相当多的编辑。

我将结果作为提示-js 发布到 npm ,部分是为了再次锻炼这些肌肉 – 这只是我在那里发布的第二个包(第一个是Web Component )。

这意味着它可以通过 CDN(例如jsDelivr)获得 – 因此您可以将其加载到页面中并开始使用它,如下所示:

 <脚本  
  src =“ https://cdn.jsdelivr.net/npm/[email protected] ”  
> </脚本>

我还没有弄清楚如何让它作为 ES 模块工作 –这里有一个悬而未决的问题。

标签: Gemini 、 llm 、 o1 、 openai 、 npm 、 llms 、人工智能辅助编程、 javascript 、项目

原文: https://simonwillison.net/2024/Dec/7/prompts-js/#atom-everything

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • Elad Gil
  • Ellie Huxtable
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme