Chatgpt,嵌入搜索和检索尖叫/Smalltalk的检索一代
语义(来自古希腊语Sēmantikós )是指信息的重要性或含义。虽然尖叫的正常String和Text类以文本为一系列字符和格式化说明, SemanticText侧重于文本的意义和理解。随着NLP(自然语言处理)和LLM(大语言模型)的出现,计算系统中文本可解释性的可用性正在大大扩展。该软件包旨在通过提供以下功能来使语义上下文可以在尖叫/Smalltalk中访问:
有关更多详细信息,请安装软件包并潜入类评论和代码中,或继续在下面阅读。
chatgpt 编辑器集成:解释 /总结 /说 Openai API费用观察者 | 帮助浏览器集成:语义搜索和检索增强发电(RAG) 尖叫收件箱谈话集成:类似的对话搜索 |
仍在开发中。可能会随之而来。反馈和贡献欢迎!
获取当前的吱吱声躯干图像(推荐)或尖叫式6.0图像(仅支持有限),并在工作区中执行此操作:
Metacello new
baseline: ' SemanticText ' ;
repository: ' github://hpi-swa-lab/Squeak-SemanticText:main ' ;
get; " for updates "
load.由于大多数功能当前基于OpenAI API,因此您需要在此处设置一个API密钥并将其粘贴到OpenAI API Key偏好中。虽然OpenAI API无法免费使用,但您只为所需的费用付费,并且信用机制也不令人惊讶。令牌真的很便宜 - 例如,您可以设置5美元的门槛,足以聊天超过1 mio。单词或嵌入50 mio。单词(或莎士比亚收集的作品的42倍)。
从世界主码头栏中,转到Apps > Chatgpt 。输入您的提示,然后按CMD + S ,或按声音进行连续的音频对话。在高级模式下,您还可以定义模型可以调用的系统指令和功能。通过窗口菜单
,您也可以选择其他模型或编辑更多的首选项。
在String , Collection , SequenceableCollection , AbstractSound等上查看*SemanticText扩展方法。一些例子:
' smalltalk inventor ' semanticAnswer. -- > ' Alan Kay '
' It ' ' s easier to invent the future than ' semanticComplete. -- > ' to predict it. '
#(apple banana cherry) semanticComplete: 5 . -- > #('date' 'elderberry' 'fig' 'grape' 'honeydew')
Character comment asString semanticSummarize.
Morph comment asString semanticAsk: ' difference between bounds and fullBounds ' .
(( SystemWindow windowsIn: Project current world satisfying: [ :ea | ea model isKindOf: Workspace ]) collect: #label )
semanticFindRankedObjects: 20 similarToQuery: ' open bugs ' .
' Hello Squeak ' semanticSayIt.
SampledSound semanticFromUser semanticToText.基本用法就是这样:
SemanticConversation new
addSystemMessage: ' You make a bad pun about everything the user writes to you. ' ;
addUserMessage: ' Yesterday I met a black cat! ' ;
getAssistantReply. -- > ' I hope it was a purr-fectly nice encounter and not a cat-astrophe! '您还可以通过在交互之前插入其他用户/助手消息来改进提示(几次提示):
SemanticConversation new
addSystemMessage: ' You answer every question with the opposite of the truth. ' ;
addUserMessage: ' What is the biggest animal on earth? ' ;
addAssistantMessage: ' The biggest animal on earth is plankton. ' ;
addUserMessage: ' What is the smallest country on earth? ' ;
getAssistantReply. -- > ' The smallest country on earth is Russia. ' | conversation message |
conversation := SemanticConversation new .
message := conversation
addUserMessage: ' What time is it? ' ;
addFunction: ( SemanticFunction fromString: ' getTime ' action: [ Time now]);
getAssistantMessage.
[conversation resolveAllToolCalls] whileTrue:
[message := conversation getAssistantMessage].
message -- > [assistant] ' The current time is 20:29:52. ' SemanticConversation new
withConfigDo: [ :config |
config temperature: 1.5 .
config nucleusSamplingMass: 0.8 .
config maxTokens: 200 " high temperatures may cause the model to output nonsense and not find an end! " ];
addUserMessage: ' Write a short poem about Alan Kay and Smalltalk ' ;
getAssistantReply -- > ' In the realm of silicon and spark,
A visionary left his mark,
Alan Kay, with dreams unfurled,
Birthed a language to change the world.
Smalltalk, a whisper, soft and clear,
A paradigm that pioneers,
Objects dancing, message flows,
In its design, innovation grows.
A windowed world where thoughts collide,
A playground where ideas abide,
From his vision, the seeds were sown,
For the digital gardens we have grown.
So here ' ' s to Kay, a mind so bright,
Who lit the way with insight ' ' s light,
In every line of code, we find,
A legacy that reshapes the mind. ' 您可以在SemanticConversation的班级侧面找到更多示例(例如消息流,检索多个响应和记录令牌概率)。
可以这样定义一个简单的代理:
SemanticAgent subclass: #SemanticSqueakAgent
instanceVariableNames: ' '
classVariableNames: ' '
poolDictionaries: ' '
category: ' SemanticText-Model-Agents ' .
SemanticSqueakAgent >> initializeConversation: aConversation
super initializeConversation: aConversation.
aConversation addSystemMessage: ' You are a Squeak/Smalltalk assistant. ' .
SemanticSqueakAgent >> eval: aString
" Evaluate a Smalltalk expression in the running Squeak image. "
< function: eval(
expression: string " e.g. '(8 nthRoot: 3)-1' "
) >
^ Compiler evaluate: aString然后,这样调用:
SemanticSqueakAgent makeNewConversation
addUserMessage: ' how many windows are open ' ;
getAssistantReply -- > ' You currently have 138 open windows in your Squeak environment. '或通过使用SemanticSqueakAgent openNewConversation来提出对话编辑。
一切都始于类SemanticCorpus 。例如,这是您如何为尖叫的帮助系统设置语义搜索语料库:
" Set up and populate semantic corpus "
helpTopics := CustomHelp asHelpTopic semanticDeepSubtopicsSkip: [ :topic |
topic title = ' All message categories ' ]. " not relevant "
corpus := SemanticPluggableCorpus titleBlock: #title contentBlock: #contents .
corpus addFragmentDocumentsFromAll: helpTopics.
corpus estimatePriceToInitializeEmbeddings. -- > approx ¢ 1.66
corpus updateEmbeddings.
" Similarity search "
originTopic := helpTopics detect: [ :ea | ea key = #firstContribution ].
results := corpus findObjects: 10 similarToObject: originTopic.
" Semantic search "
results := corpus findObjects: 10 similarToQuery: ' internet connection ' .
" Optionally, display results in a HelpBrowser "
resultsTopic := HelpTopic named: ' Search results ' .
results do: [ :ea | resultsTopic addSubtopic: ea].
resultsTopic browse.
" RAG "
(corpus newConversationForQuery: ' internet connection ' ) open.在任何文本编辑器上yound单击(在此之前选择选择的一部分文本),单击更多... ,然后选择“解释” ,总结它,询问问题...或说。还是通过键盘不久: ESC ? ,输入, q 。 ?
您也可以选择“与类型”的说法来指示文本。
打开世界主码头栏的帮助浏览器,然后将查询输入搜索字段。请注意,目前,同义搜索词比问题更好(例如,“我可以访问互联网?”而不是“互联网连接”?)。
笔记
首先需要在首选项浏览器中启用此功能(“帮助浏览器中的语义搜索”)。
获取尖叫收件箱谈话(世界主码头栏>工具>尖叫收件箱谈话),通过“设置”菜单将其更新为最新版本,然后在Preageences浏览器中打开“ Squeak Inbox Talk”中的选项语义搜索。之后,您可以:
这是一个实验研究项目。请查看语义Queak,我们的论文或我的论文,以获取更多信息。
这样做:
OpenAIAccount openExpenseWatcher我个人喜欢从这种变体中获取最后一个子类型,并将其插入我的主要码头栏中。如果您也喜欢这样做,请提交功能请求或拉动请求以自动化此问题!
提供商可以注册不同的模型,通过SemanticText接口进行选择和使用。今天的主要提供商是OpenAI API客户端,但可能会遵循更多的客户。注册表可以像defaultEmbeddingModel , chooseDefaultConversationModel或registeredSpeechSynthesisModels一样查询。
为了进行调试和测试目的,我们还为对话和嵌入式提供了模拟提供商。
此外,还有一个针对克拉特插件的语音合成提供商。它需要语音软件包,可以与SemanticTextProviders-Klatt软件包分开加载(或通过指定load: #full )。
我的论文附录中提供了有关Semantictext的体系结构,API和工具的更多详细信息。请注意,这可能包括过时的信息或尚未应用的重构(但也包括不错的图表和示例!以及背后的一堆理论!)。
目前,已知以下项目使用Semantictext:
虽然在技术上无关,但Squeakgpt探索了使用生成AI进行尖叫的类似方法。
感谢Marcel Taeumel(@marceltaeumel)在整个学习和实验中为我提供建议。感谢Toni Mattis(@Amintos)的有关嵌入搜索的提示(尤其是541ae49 )。感谢Vincent Eichhorn(@vincenteichhorn)给我概述了向量DBS的索引技术(很快就会实施!)。感谢R/MachineLearning的人们建议替代嵌入模型(您的建议可能有一天可以实施)。
快乐的吱吱作响!