Copilot commented on code in PR #818: URL: https://github.com/apache/dubbo-go-samples/pull/818#discussion_r2083095420
########## llm/book-flight/go-server/agents/task.go: ########## @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package agents + +import ( + "context" + "strings" +) + +import ( + "github.com/apache/dubbo-go-samples/llm/book-flight/go-server/tools" +) + +type TaskState int + +const ( + TaskUndefined TaskState = 0 + TaskSubmitted TaskState = 1 << iota + TaskWorking + TaskInputRequired + TaskCompleted + TaskFailed + TaskCanceled + TaskUnrelated +) + +// InitTaskState +func InitTaskState(value string) TaskState { + var rst TaskState + switch strings.ToUpper(value) { + case "TASKUNDEFINED": + rst = TaskUndefined + case "TASKSUBMITTED": + rst = TaskSubmitted + case "TASKWORKING": + rst = TaskWorking + case "TASKINPUTREQUIRED": + rst = TaskInputRequired + case "TASKCOMPLETED": + rst = TaskCompleted + case "TASKFAILED": + rst = TaskFailed + case "TASKCANCELED": + rst = TaskCanceled + case "TASKUNRELATED": + rst = TaskUnrelated + default: + rst = TaskUndefined + } + return rst +} + +// CreateToolkit +func CreateTaskToolkit(description string, taskFlag TaskState, ts ...tools.Tool) tools.Tools { + toolsTask := append(ts, tools.CreateTool[TaskUnrelatedTool]("TaskUnrelated", "不相关问题占位符工具", "")) Review Comment: The 'TaskUnrelatedTool' is appended unconditionally and then is potentially appended again if the 'TaskUnrelated' flag is set later. This could lead to duplicate tool entries. Consider removing the unconditional append or reviewing the flag logic. ```suggestion toolsTask := ts ``` ########## llm/book-flight/go-server/mcp/jsonrpc.go: ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package mcp + +const ( + jsonrpc = "2.0" // jsonrpc version +) + +type RequestRPC struct { + // JsonRPC specifies the JSON-RPC version. It MUST be exactly "2.0". + JsonRPC string `json:"jsonrpc"` // Explicitly named "jsonrpc" in JSON + // Method is a string containing the name of the method to be invoked. + // Method names that begin with a lowercase letter are reserved for + // system-defined methods and MUST NOT be used for custom methods. + Method string `json:"method"` + // Params is a structured value that holds the parameter values to be used + // during the invocation of the method. This member MAY be omitted. + Params map[string]any `json:"params,omitempty"` // Omitempty to skip if nil + // Id is an identifier established by the client that MUST contain a String, + // Number, or Null value if included. If not included it is assumed to be a + // notification. The value SHOULD normally not be Null [1] and Numbers SHOULD + // NOT contain fractional parts [2]. + // [1] Using Null as a value for the id member in a Request object is + // discouraged, as there are no benefits and it introduces ambiguities + // when differentiating between Requests, Notifications, and Response + // objects. + // [2] Fractional parts SHOULD NOT be used as there is no clear + // interoperable way to represent them across all systems. + Id string `json:"id,omitempty"` // Omitempty to skip if empty +} + +// NewRequestRPC creates a new RequestRPC with the JsonRPC field set to "2.0". +func NewRequestRPC(method string, params map[string]any, id string) *RequestRPC { + return &RequestRPC{ + JsonRPC: jsonrpc, + Method: method, + Params: params, + Id: id, + } +} + +type ErrorRPC struct { + // A Number that indicates the error type that occurred. + // This MUST be an integer. + Code int64 `json:"code"` + // A String providing a shot description of the error. Review Comment: It appears there is a typo in the comment ('shot' should be 'short'). Consider updating the comment to 'A String providing a short description of the error.' ```suggestion // A String providing a short description of the error. ``` ########## llm/book-flight/go-client/frontend/templates/index.html: ########## @@ -0,0 +1,68 @@ +<!DOCTYPE html> +<html lang="en" dir="ltr"> +<head> + <meta charset="utf-8"> + <title>Chatbot in JavaScript | CodingNepal</title> + <link rel="stylesheet" href="../static/style.css"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" /> + <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@48,400,1,0" /> + <script src="../static/script.js" defer></script> + <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css"> + <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> + <style> + .markdown-body { + line-height: 1.2; + font-family: sans-serif; + padding: 20px; + } + </style> +</head> +<body> + +<!-- 机票预订信息 --> +<div class="booking-confirmation"> + <div id="flight-info"> + <h3>航班信息</h3> + <p>正在加载航班信息...</p> + </div> +</div> +<div class="chatbot"> + <header> + <h2>Chatbot</h2> + </header> + <ul class="chatbox"> + <li class="chat incoming"> + <span class="material-symbols-outlined">smart_toy</span> + <p class="chat incoming content" id="content">Hi there 👋</p> + </li> + </ul> + <div class="chat-input"> + <textarea placeholder="Enter a message..." spellcheck="false" required></textarea> + <span id="send-btn" class="material-symbols-rounded">send</span> + <div id="drop" class="drop-box"></div> + <span1 id="add-btn" class="material-symbols-rounded">add</span1> Review Comment: The HTML tag 'span1' is non-standard. It is recommended to change it to a standard tag such as 'span' for better browser compatibility. ```suggestion <span id="add-btn" class="material-symbols-rounded">add</span> ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
