第一個人工智慧回應:
輸出:感謝您伸出援手,.我很樂意為您提供幫助,但我想確保我完全理解您的需求。您能否提供有關您正在尋找的內容的更多詳細資訊?您分享的資訊越多,我就越能提供協助!我很樂意盡我所能地幫助你。您想進一步探索某個特定領域嗎?您的意見將幫助我根據您的具體需求量身定制我的幫助。我完全致力於讓您的體驗盡可能順利和愉快。
AI 回應,在寫自己的圖表後:
輸出:嗨!這是怎麼回事?今天我能為您提供什麼幫助?您告訴我的越多,我就越能提供幫助。你在想什麼?我來這裡是為了幫助您找到適合您的解決方案。請注意,我是一名人工智慧助手,仍在學習入門知識。
非常神奇吧?
聽起來幾乎是人類的。週末我和 van Wilder 一起看了電影《Free Guy》,我意識到哇,我可能可以使用 @langchain/langgraph 中的 GraphState 來創建一個可以對自身執行迭代並編寫自己的程式碼的 AI。
如果您現在還沒有意識到這一點,Claude Sonnet 非常擅長 0 鏡頭編碼,甚至更擅長多鏡頭編碼。
使用庫 npm:sentiment :
來自 README.md
Sentiment 是一個 Node.js 模組,它使用 AFINN-165 單字清單和表情符號情緒排名對任意輸入文字區塊執行情緒分析。
我為圖形狀態添加了一個簡單的命令,該命令對輸出運行情緒分析,並使用新版本改進程式碼以嘗試獲得更高的分數:
// update state and continue evolution return new Command({ update: { ...state, code: newCode, version: state.version + 1, analysis, previousSentimentDelta: currentSentimentDelta, type: "continue", output }, goto: "evolve" // Loop back to evolve });
我們用它可以使用的初始圖形狀態為語言圖播種(如果您願意,可以使用基礎程式碼):
const initialWorkerCode = ` import { StateGraph, END } from "npm:@langchain/langgraph"; const workflow = new StateGraph({ channels: { input: "string", output: "string?" } }); // Initial basic response node workflow.addNode("respond", (state) => ({ ...state, output: "I understand your request and will try to help. Let me know if you need any clarification." })); workflow.setEntryPoint("respond"); workflow.addEdge("respond", END); const graph = workflow.compile(); export { graph }; `;
您可以看到這是一個非常基本的回應節點,附加了一條邊。
我將當前程式碼設定為經過 10 次迭代,試圖獲得 10 或更高的情緒:
if (import.meta.main) { runEvolvingSystem(10, 10); }
每次都會執行分析:
Analysis: { metrics: { emotionalRange: 0.16483516483516483, vocabularyVariety: 0.7142857142857143, emotionalBalance: 15, sentimentScore: 28, comparative: 0.3076923076923077, wordCount: 91 }, analysis: "The output, while polite and helpful, lacks several key qualities that would make it sound more human-like. Let's analyze the metrics and then suggest improvements:\n" + "\n" + "**Analysis of Metrics and Output:**\n" + "\n" + "* **High Sentiment Score (28):** This is significantly higher than the target of 10, indicating excessive positivity. Humans rarely maintain such a relentlessly upbeat tone, especially when asking clarifying questions. It feels forced and insincere.\n" + "\n" + "* **Emotional Range (0.16):** This low score suggests a lack of emotional variation. The response is consistently positive, lacking nuances of expression. Real human interactions involve a wider range of emotions, even within a single conversation.\n" + "\n" + "* **Emotional Balance (15.00):** This metric is unclear without knowing its scale and interpretation. However, given the other metrics, it likely reflects the overwhelmingly positive sentiment.\n" + "\n" + "* **Vocabulary Variety (0.71):** This is relatively good, indicating a decent range of words. However, the phrasing is still somewhat formulaic.\n" + "\n" + "* **Comparative Score (0.3077):** This metric is also unclear without context.\n" + "\n" + "* **Word Count (91):** A bit lengthy for a simple clarifying request. Brevity is often more human-like in casual conversation.\n" + "\n" + "\n" + "**Ways to Make the Response More Human-like:**\n" + "\n" + `1. **Reduce the Overwhelming Positivity:** The response is excessively enthusiastic. A more natural approach would be to tone down the positive language. Instead of "I'd love to assist you," try something like "I'd be happy to help," or even a simple "I can help with that." Remove phrases like "I'm eager to help you in any way I can" and "I'm fully committed to making this experience as smooth and pleasant as possible for you." These are overly formal and lack genuine warmth.\n` + "\n" + '2. **Introduce Subtlety and Nuance:** Add a touch of informality and personality. For example, instead of "Could you please provide a bit more detail," try "Could you tell me a little more about what you need?" or "Can you give me some more information on that?"\n' + "\n" + "3. **Shorten the Response:** The length makes it feel robotic. Conciseness is key to human-like communication. Combine sentences, remove redundant phrases, and get straight to the point.\n" + "\n" + '4. **Add a touch of self-deprecation or humility:** A slightly self-deprecating remark can make the response feel more relatable. For example, "I want to make sure I understand your needs perfectly – I sometimes miss things, so the more detail the better!"\n' + "\n" + "5. **Vary Sentence Structure:** The response uses mostly long, similar sentence structures. Varying sentence length and structure will make it sound more natural.\n" + "\n" + "**Example of a More Human-like Response:**\n" + "\n" + `"Thanks for reaching out! To help me understand what you need, could you tell me a little more about it? The more detail you can give me, the better I can assist you. Let me know what you're looking for."\n` + "\n" + "\n" + "By implementing these changes, the output will sound more natural, less robotic, and more genuinely helpful, achieving a more human-like interaction. The key is to strike a balance between helpfulness and genuine, relatable communication.\n", rawSentiment: { score: 28, comparative: 0.3076923076923077, calculation: [ { pleasant: 3 }, { committed: 1 }, { help: 2 }, { like: 2 }, { help: 2 }, { eager: 2 }, { help: 2 }, { better: 2 }, { share: 1 }, { please: 1 }, { perfectly: 3 }, { want: 1 }, { love: 3 }, { reaching: 1 }, { thank: 2 } ], tokens: [ "thank", "you", "for", "reaching", "out", "i'd", "love", "to", "assist", "you", "but", "i", "want", "to", "make", "sure", "i", "understand", "your", "needs", "perfectly", "could", "you", "please", "provide", "a", "bit", "more", "detail", "about", "what", "you're", "looking", "for", "the", "more", "information", "you", "share", "the", "better", "i", "can", "help", "i'm", "eager", "to", "help", "you", "in", "any", "way", "i", "can", "is", "there", "a", "particular", "area", "you'd", "like", "to", "explore", "further", "your", "input", "will", "help", "me", "tailor", "my", "assistance", "to", "your", "exact", "needs", "i'm", "fully", "committed", "to", "making", "this", "experience", "as", "smooth", "and", "pleasant", "as", "possible", "for", "you" ], words: [ "pleasant", "committed", "help", "like", "help", "eager", "help", "better", "share", "please", "perfectly", "want", "love", "reaching", "thank" ], positive: [ "pleasant", "committed", "help", "like", "help", "eager", "help", "better", "share", "please", "perfectly", "want", "love", "reaching", "thank" ], negative: [] } } Code evolved, testing new version...
它使用此 Analysis 類別在程式碼上得分較高。
經過 10 次迭代後,得分相當高:
Final Results: Latest version: 10 Final sentiment score: 9 Evolution patterns used: ["basic","responsive","interactive"]
最有趣的是它所建立的圖表:
import { StateGraph, END } from "npm:@langchain/langgraph"; const workflow = new StateGraph({ channels: { input: "string", output: "string?", sentiment: "number", context: "object" } }); const positiveWords = ["good", "nice", "helpful", "appreciate", "thanks", "pleased", "glad", "great", "happy", "excellent", "wonderful", "amazing", "fantastic"]; const negativeWords = ["issue", "problem", "difficult", "confused", "frustrated", "unhappy"]; workflow.addNode("analyzeInput", (state) => { const input = state.input.toLowerCase(); let sentiment = input.split(" ").reduce((score, word) => { if (positiveWords.includes(word)) score += 1; if (negativeWords.includes(word)) score -= 1; return score; }, 0); sentiment = Math.min(Math.max(sentiment, -5), 5); return { ...state, sentiment, context: { needsClarification: sentiment === 0, isPositive: sentiment > 0, isNegative: sentiment { let response = ""; const userName = state.context.userName ? `${state.context.userName}` : "there"; if (state.context.isPositive) { response = `Hey ${userName}! Glad to hear things are going well. What can I do to make your day even better?`; } else if (state.context.isNegative) { response = `Hi ${userName}. I hear you're facing some challenges. Let's see if we can turn things around. What's on your mind?`; } else { response = `Hi ${userName}! What's up? How can I help you today?`; } return { ...state, output: response }; }); workflow.addNode("interactiveFollowUp", (state) => { let followUp = ""; switch (state.context.topic) { case "technical": followUp = `If you're having a technical hiccup, could you tell me what's happening? Any error messages or weird behavior?`; break; case "product": followUp = `Curious about our products? What features are you most interested in?`; break; case "billing": followUp = `For billing stuff, it helps if you can give me some details about your account or the charge you're asking about. Don't worry, I'll keep it confidential.`; break; default: followUp = `The more you can tell me, the better I can help. What's on your mind?`; } return { ...state, output: state.output + " " + followUp }; }); workflow.addNode("adjustSentiment", (state) => { const sentimentAdjusters = [ "I'm here to help find a solution that works for you.", "Thanks for your patience as we figure this out.", "Your input really helps me understand the situation better.", "Let's work together to find a great outcome for you." ]; const adjuster = sentimentAdjusters[Math.floor(Math.random() * sentimentAdjusters.length)]; return { ...state, output: state.output + " " + adjuster }; }); workflow.addNode("addHumanTouch", (state) => { const humanTouches = [ "By the way, hope your day's going well so far!", "Just a heads up, I'm an AI assistant still learning the ropes.", "Feel free to ask me to clarify if I say anything confusing.", "I appreciate your understanding as we work through this." ]; const touch = humanTouches[Math.floor(Math.random() * humanTouches.length)]; return { ...state, output: state.output + " " + touch }; }); workflow.setEntryPoint("analyzeInput"); workflow.addEdge("analyzeInput", "generateResponse"); workflow.addEdge("generateResponse", "interactiveFollowUp"); workflow.addEdge("interactiveFollowUp", "adjustSentiment"); workflow.addEdge("adjustSentiment", "addHumanTouch"); workflow.addEdge("addHumanTouch", END); const graph = workflow.compile(); export { graph };
我看到它寫的這段程式碼,立刻想到了以下陷阱:
突發的複雜性:
這是指簡單元件互動產生的複雜性,在本例中是法學碩士的演算法和它所訓練的龐大資料集。 LLM 可以產生的程式碼雖然功能強大,但卻表現出人類難以完全理解的複雜模式和依賴關係。
因此,如果我們可以稍微調整一下,並讓它編寫更乾淨、更簡單的程式碼,我們可能就走在正確的軌道上。
無論如何,這只是一個實驗,因為我想使用 langgraphs 新的命令功能。
請在評論中告訴我你的想法。
以上是自寫 Lang 圖狀態的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Node.js擅長於高效I/O,這在很大程度上要歸功於流。 流媒體匯總處理數據,避免內存過載 - 大型文件,網絡任務和實時應用程序的理想。將流與打字稿的類型安全結合起來創建POWE

Python和JavaScript在性能和效率方面的差異主要體現在:1)Python作為解釋型語言,運行速度較慢,但開發效率高,適合快速原型開發;2)JavaScript在瀏覽器中受限於單線程,但在Node.js中可利用多線程和異步I/O提升性能,兩者在實際項目中各有優勢。

JavaScript起源於1995年,由布蘭登·艾克創造,實現語言為C語言。 1.C語言為JavaScript提供了高性能和系統級編程能力。 2.JavaScript的內存管理和性能優化依賴於C語言。 3.C語言的跨平台特性幫助JavaScript在不同操作系統上高效運行。

JavaScript在瀏覽器和Node.js環境中運行,依賴JavaScript引擎解析和執行代碼。 1)解析階段生成抽象語法樹(AST);2)編譯階段將AST轉換為字節碼或機器碼;3)執行階段執行編譯後的代碼。

Python和JavaScript的未來趨勢包括:1.Python將鞏固在科學計算和AI領域的地位,2.JavaScript將推動Web技術發展,3.跨平台開發將成為熱門,4.性能優化將是重點。兩者都將繼續在各自領域擴展應用場景,並在性能上有更多突破。

Python和JavaScript在開發環境上的選擇都很重要。 1)Python的開發環境包括PyCharm、JupyterNotebook和Anaconda,適合數據科學和快速原型開發。 2)JavaScript的開發環境包括Node.js、VSCode和Webpack,適用於前端和後端開發。根據項目需求選擇合適的工具可以提高開發效率和項目成功率。

是的,JavaScript的引擎核心是用C語言編寫的。 1)C語言提供了高效性能和底層控制,適合JavaScript引擎的開發。 2)以V8引擎為例,其核心用C 編寫,結合了C的效率和麵向對象特性。 3)JavaScript引擎的工作原理包括解析、編譯和執行,C語言在這些過程中發揮關鍵作用。

JavaScript是現代網站的核心,因為它增強了網頁的交互性和動態性。 1)它允許在不刷新頁面的情況下改變內容,2)通過DOMAPI操作網頁,3)支持複雜的交互效果如動畫和拖放,4)優化性能和最佳實踐提高用戶體驗。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Dreamweaver CS6
視覺化網頁開發工具

Dreamweaver Mac版
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具