自写 Lang 图状态

自写 lang 图状态

第一人工智能响应:

输出:感谢您伸出援手,.我很乐意为您提供帮助,但我想确保我完全理解您的需求。您能否提供有关您正在寻找的内容的更多详细信息?您分享的信息越多,我就越能提供帮助!我很乐意尽我所能地帮助你。您想进一步探索某个特定领域吗?您的意见将帮助我根据您的具体需求定制我的帮助。我完全致力于让您的体验尽可能顺利和愉快。

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 nodeworkflow.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: 10final sentiment score: 9evolution 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 图状态的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1499596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
我的 React 之旅:第 19 天
上一篇 2025年12月19日 21:53:38
人工智能发音训练器
下一篇 2025年12月19日 21:53:51

相关推荐

  • 芯原推出低功耗AI降噪与AI超分辨率系列IP

    ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 芯原股份推出全新AI图像处理IP系列,赋能高清影像时代 2025年2月27日,上海——芯原股份(芯原,股票代码:688521.SH)今日宣布推出其最新一代AI图像处理IP系列,包括智能降噪IP …

    2026年8月29日
    000
  • 如何使用Composer解决Laravel项目中的数据表格展示问题?yajra/laravel-datatables助你轻松实现!

    可以通过一下地址学习composer:学习地址 在开发 laravel 项目时,数据表格的展示和处理是一个常见且重要的需求。我最近在项目中遇到了一个棘手的问题:如何高效地展示大量数据,并提供排序、搜索、分页等功能。开始时,我尝试了手动编写代码来实现这些功能,但发现这不仅耗时,而且容易出错。经过一番探…

    用户投稿 2026年8月29日
    000
  • 美团王兴,中国具身智能第一投资人

    美团王兴,中国具身智能第一投资人美团王兴,中国具身智能第一投资人美团王兴,中国具身智能第一投资人美团王兴,中国具身智能第一投资人

    你可能没留意到,如火如荼的具身智能融资大潮里,棋局热闹,棋子如云,而低调又凶猛的棋手,却不显山不露水。 美团王兴,就是这场激战里真正的(骑手)棋手。 尽管 7 月只过去了 11 天,美团已经接连出手了 2 家具身智能公司:它石智航 & 星海图。 其中包含对星海图连续领投 2 次,又猛又狠 —…

    2026年8月29日 用户投稿
    000
  • 出货量创历史新高,艾为电子2024年净利润同比增长399.83%

    艾为电子2024年业绩强劲增长,营收利润双双提升! ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 艾为电子近日发布2024年业绩快报,显示公司全年业绩实现大幅增长。具体数据如下:营业收入达293.29亿元,同比增长15.88%;营业利润23…

    2026年8月29日
    000
  • 智能助手怎么处理多模态任务_AI理解图片语音和文本方法

    多模态智能助手通过多模态嵌入、注意力机制、Transformer架构和对比学习等技术,将图像、语音和文本统一表示并关联,实现跨模态理解与响应;实际应用中面临数据稀疏性、模态不对齐、异构性和计算复杂度等挑战;性能评估需结合单模态指标、跨模态指标、用户满意度及对抗性测试综合判断。 ☞☞☞AI 智能聊天,…

    2026年8月29日
    000
  • 流畅阅读— 开源AI浏览器翻译插件,支持双语对照显示

    流畅阅读— 开源AI浏览器翻译插件,支持双语对照显示流畅阅读— 开源AI浏览器翻译插件,支持双语对照显示流畅阅读— 开源AI浏览器翻译插件,支持双语对照显示流畅阅读— 开源AI浏览器翻译插件,支持双语对照显示

    fluentread:你的浏览器翻译利器,助你畅享无障碍阅读体验! FluentRead是一款开源浏览器翻译插件,它利用先进的AI技术,旨在为你提供如同母语般流畅的阅读体验。支持多种翻译引擎,包括传统的机器翻译和强大的AI大模型,并且允许你自定义翻译服务。其核心功能包含智能翻译、便捷的双语对照显示以…

    2026年8月29日 用户投稿
    100
  • 拼多多商家能取消订单吗?拼多多商家能取消退款吗

    答案:拼多多商家取消订单需根据状态选择处理方式。未发货订单可在工作台或APP操作取消;已发货订单须拦截物流并引导买家退款;退款申请不可强制取消,需协商或举证驳回;特殊场景如恶意下单、系统异常等需平台介入。 如果您作为拼多多商家,因库存、物流等原因需要取消已生成的订单或处理买家发起的退款申请,平台允许…

    2026年8月29日
    000
  • 《中国足球环境及未来发展白皮书(2025)》发布:100吋大屏电视成标配

    2025年,世俱杯的激情与“苏超”的热潮遥相呼应,掀起了一场全球范围内的足球盛宴。这份源自赛场内外的热情,不仅展现了足球运动的巨大魅力,也正逐步汇聚成推动中国足球环境改善的重要力量。 7月10日,由经济观察研究院发布的《中国足球环境及未来发展白皮书(2025)》(以下简称《白皮书》)引发广泛关注。该…

    2026年8月29日
    000
  • switch520热门游戏资源入口-switch520免费资源链接地址

    Switch热门游戏资源与免费链接的获取,核心在于官方平台与玩家社区结合。首先,任天堂eShop提供《堡垒之夜》《Apex英雄》等免费游戏及试玩版,是合法资源首选;其次,通过DekuDeals等价格追踪网站和IGN等媒体掌握最新折扣与资讯;最后,积极参与Reddit、贴吧等玩家社区,可获取限时活动、…

    2026年8月29日
    000
  • 使用 Java 编码单词:基于字母表的字符映射教程

    本文档旨在指导开发者如何使用 Java 编程语言,根据预定义的字母表将单词编码为字符序列。我们将详细介绍实现此功能的代码,解释关键步骤,并提供示例代码,确保编码过程能够准确地保留单词的原始顺序。本教程将涵盖字符大小写处理、循环优化以及结果输出等关键方面,帮助读者掌握字符编码的核心技术。 ### 字符…

    2026年8月29日
    000
  • 首款搭载海光4号处理器笔记本,联想开天X7定义信创PC旗舰性能

    北京,2025年7月10日——在今日举行的海光新一代pc处理器发布会上,联想开天作为核心战略合作伙伴,同步发布了一款面向国产信创领域的重磅新品——联想开天x7高性能信创旗舰笔记本。该产品不仅是全球首款配备海光4号处理器的笔记本电脑,更首次在国产笔记本中引入独立npu芯片,标志着国产“信创aipc”迈…

    2026年8月29日
    100
  • Dubbo消费者配置中“标签的id属性有什么作用?

    `标签的id属性作用” /> 深入理解Dubbo消费者配置中标签的id属性 在基于Dubbo框架的分布式系统中,消费者配置文件的标签扮演着关键角色,其id属性尤为重要。本文将详细解释中id=”timeservice”的具体作用。 这段配置代码声明了对名为cn.suiwei.serv…

    2026年8月29日
    000
  • 如何解决Swagger/OpenAPI规范的管理问题?使用Composer可以轻松搞定!

    可以通过以下地址学习 composer:学习地址 在开发 API 时,管理和操作 Swagger/OpenAPI 规范常常是一项复杂且耗时的任务。我曾在一个项目中遇到过这样的问题:需要频繁地修改和更新 Swagger 文档,手动操作不仅容易出错,还非常低效。最终,我通过 Composer 安装了 e…

    用户投稿 2026年8月29日
    000
  • 完美世界入选“2025高品质消费品牌TOP100”榜单

    7月10日,南方都市报联合广东连锁经营协会发布“2025高品质消费品牌top100”榜单,完美世界股份有限公司成功入选,并荣获“年度十大消费科技创新品牌”奖项,彰显其在高品质兴趣消费领域的引领地位。 在数字经济时代,数字内容产品已成为大众文化精神生活的重要组成部分。以数字游戏、电子竞技、影视作品为代…

    2026年8月29日
    000
  • GRUtopia 2.0— 上海 AI Lab 推出的通用具身智能仿真平台

    GRUtopia 2.0— 上海 AI Lab 推出的通用具身智能仿真平台GRUtopia 2.0— 上海 AI Lab 推出的通用具身智能仿真平台GRUtopia 2.0— 上海 AI Lab 推出的通用具身智能仿真平台GRUtopia 2.0— 上海 AI Lab 推出的通用具身智能仿真平台

    ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 文心智能体平台 百度推出的基于文心大模型的Agent智能体平台,已上架2000+AI智能体 0 查看详情 上海人工智能实验室推出的grutopia 2.0(桃源2.0)是一款功能强大的通用具身智…

    2026年8月29日 用户投稿
    000
  • TGS2025《如龙极3/如龙3 外传》制作人采访 外传剧情有参考OL

    TGS2025《如龙极3/如龙3 外传》制作人采访 外传剧情有参考OLTGS2025《如龙极3/如龙3 外传》制作人采访 外传剧情有参考OLTGS2025《如龙极3/如龙3 外传》制作人采访 外传剧情有参考OLTGS2025《如龙极3/如龙3 外传》制作人采访 外传剧情有参考OL

    在tgs2025前夕,世嘉如龙工作室举办发布会发表了“极”系列的第三部作品《如龙极3》,而这次最特别是在游戏内还同捆了以反派峰义孝为主角的《如龙3 外传》。这款游戏也在tgs现场提供了最速试玩,此前我们也给大家带来了实机试玩视频。 https://www.bilibili.com/video/BV1…

    2026年8月29日 用户投稿
    000
  • 《恐怖黎明》新资料片“Fangs of Asterkarn”迄今最大 恐延期到2026年

    《恐怖黎明》全新资料片“fangs of asterkarn”早在两年前便已公布,原定于2024年发布的计划现已确认无法如期实现。开发商crate entertainment最近发布了更新进度,表示该资料片可能将在今年晚些时候上线,但同时也坦言存在延期至2026年春季甚至初夏的可能性。 根据官方介绍…

    2026年8月29日
    000
  • MyBatis XML文件中如何正确处理SQL语句中的引号以避免JSON_CONTAINS函数出错?

    MyBatis XML 文件中 SQL 语句引号处理及 JSON_CONTAINS 函数使用 在使用 MyBatis 等框架操作数据库时,XML 文件中的 SQL 语句引号处理常常令人头疼,尤其是在使用 JSON_CONTAINS 等函数时。本文将通过一个案例,讲解如何正确处理 XML 文件中的 S…

    2026年8月29日
    100
  • laravel5源码分析

    Laravel 5 深入分析揭示了其强大的架构和核心组件:MVC 设计模式、路由、依赖注入、事件、队列和验证。通过分析代码,开发者可以深入了解框架的实现,包括路由定义、控制器处理、模型交互、视图呈现、依赖关系管理、事件系统、异步任务和数据验证。这有助于开发者自定义、扩展框架并解决遇到的问题。 Lar…

    2026年8月29日
    100
  • MyBatis XML Mapper文件中JSON_CONTAINS函数引号处理难题如何解决?

    MyBatis XML Mapper 文件中 JSON_CONTAINS 函数引号处理难题及解决方案 在使用 MyBatis 等框架编写 SQL 语句时,经常会遇到 XML 文件中引号处理的问题,尤其是在使用 JSON 函数,例如 JSON_CONTAINS 时。本文将针对一个常见的 XML 文件中…

    2026年8月29日
    100

发表回复

登录后才能评论
关注微信