diff --git a/LinkToolAddin.csproj b/LinkToolAddin.csproj index 299d12b..710c8a5 100644 --- a/LinkToolAddin.csproj +++ b/LinkToolAddin.csproj @@ -98,6 +98,7 @@ + diff --git a/client/CallArcGISPro.cs b/client/CallArcGISPro.cs index c04c526..a3c00e4 100644 --- a/client/CallArcGISPro.cs +++ b/client/CallArcGISPro.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using LinkToolAddin.server; using Newtonsoft.Json; @@ -6,10 +7,10 @@ namespace LinkToolAddin.client; public class CallArcGISPro { - public static string CallArcGISProTool(Dictionary parameters) + public async static Task CallArcGISProTool(Dictionary parameters) { // Call the ArcGIS Pro method and get the result - var result = server.CallArcGISPro.CallArcGISProTool(parameters["toolName"], JsonConvert.DeserializeObject>(parameters["toolParams"])); + var result = await server.CallArcGISPro.CallArcGISProTool(parameters["toolName"], JsonConvert.DeserializeObject>(parameters["toolParams"])); // Serialize the result back to a JSON string return JsonConvert.SerializeObject(result); diff --git a/common/HttpRequest.cs b/common/HttpRequest.cs new file mode 100644 index 0000000..a38807c --- /dev/null +++ b/common/HttpRequest.cs @@ -0,0 +1,21 @@ +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using LinkToolAddin.host.llm.entity; +using Newtonsoft.Json; + +namespace LinkToolAddin.common; + +public class HttpRequest +{ + public static async Task SendPostRequestAsync(string url, string jsonContent, string apiKey) + { + using var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); + var response = await httpClient.PostAsync(url, new StringContent(jsonContent, Encoding.UTF8, "application/json")); + response.EnsureSuccessStatusCode(); + var responseBody = await response.Content.ReadAsStringAsync(); + return responseBody; + } +} \ No newline at end of file diff --git a/host/CallMcp.cs b/host/CallMcp.cs index b27178c..a98488d 100644 --- a/host/CallMcp.cs +++ b/host/CallMcp.cs @@ -13,17 +13,16 @@ namespace LinkToolAddin.host public class CallMcp { private static readonly ILog log = LogManager.GetLogger(typeof(CallMcp)); - public static string CallInnerMcpTool(string jsonRpcString) + public static async Task CallInnerMcpTool(string jsonRpcString) { log.Info("通过反射调用内部MCP工具"); var jsonRpcEntity = JsonConvert.DeserializeObject(jsonRpcString); Type type = Type.GetType("LinkToolAddin.client."+jsonRpcEntity.Method.Split('.')[0]); MethodInfo method = type.GetMethod(jsonRpcEntity.Method.Split('.')[1],BindingFlags.Public | BindingFlags.Static); - string result = (string)method.Invoke(null, new object[] { jsonRpcEntity.Params }); - - // 将结果序列化为 JSON 字符串 - return result; + var task = method.Invoke(null, new object[] { jsonRpcEntity.Params }) as Task; + JsonRpcResultEntity result = await task; + return JsonConvert.SerializeObject(result); } } } \ No newline at end of file diff --git a/host/llm/Bailian.cs b/host/llm/Bailian.cs new file mode 100644 index 0000000..bd444c7 --- /dev/null +++ b/host/llm/Bailian.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using LinkToolAddin.common; +using LinkToolAddin.host.llm.entity; +using Newtonsoft.Json; + +namespace LinkToolAddin.host.llm; + +public class Bailian : Llm +{ + public string model { get; set; } = "qwen-max"; + public string temperature { get; set; } + public string top_p { get; set; } + public string max_tokens { get; set; } + public string app_id { get; set; } + public string api_key { get; set; } + public IAsyncEnumerable SendChatStreamAsync(string message) + { + throw new System.NotImplementedException(); + } + + public IAsyncEnumerable SendApplicationStreamAsync(string message) + { + throw new System.NotImplementedException(); + } + + public async Task SendChatAsync(LlmJsonContent jsonContent) + { + string url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"; + string responseBody = await HttpRequest.SendPostRequestAsync(url, JsonConvert.SerializeObject(jsonContent), api_key); + LlmChat result = JsonConvert.DeserializeObject(responseBody); + return result.Choices[0].Message.Content; + } + + public async Task SendApplicationAsync(CommonInput commonInput) + { + string url = $"https://dashscope.aliyuncs.com/api/v1/apps/{app_id}/completion"; + string responseBody = await HttpRequest.SendPostRequestAsync(url, JsonConvert.SerializeObject(commonInput), api_key); + ApplicationOutput result = JsonConvert.DeserializeObject(responseBody); + return responseBody; + } +} \ No newline at end of file diff --git a/host/llm/Llm.cs b/host/llm/Llm.cs index 95e11c4..62a11f4 100644 --- a/host/llm/Llm.cs +++ b/host/llm/Llm.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Threading.Tasks; +using LinkToolAddin.host.llm.entity; namespace LinkToolAddin.host.llm; @@ -11,4 +13,6 @@ public interface Llm public IAsyncEnumerable SendChatStreamAsync(string message); public IAsyncEnumerable SendApplicationStreamAsync(string message); + public Task SendChatAsync(LlmJsonContent jsonContent); + public Task SendApplicationAsync(CommonInput commonInput); } \ No newline at end of file diff --git a/host/llm/entity/ApplicationOutput.cs b/host/llm/entity/ApplicationOutput.cs new file mode 100644 index 0000000..94405fa --- /dev/null +++ b/host/llm/entity/ApplicationOutput.cs @@ -0,0 +1,51 @@ +namespace LinkToolAddin.host.llm.entity +{ + using System; + using System.Collections.Generic; + + using System.Globalization; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + + public partial class ApplicationOutput + { + [JsonProperty("output")] + public Output Output { get; set; } + + [JsonProperty("usage")] + public Usage Usage { get; set; } + + [JsonProperty("request_id")] + public Guid RequestId { get; set; } + } + + public partial class Output + { + [JsonProperty("finish_reason")] + public string FinishReason { get; set; } + + [JsonProperty("session_id")] + public string SessionId { get; set; } + + [JsonProperty("text")] + public string Text { get; set; } + } + + public partial class Usage + { + [JsonProperty("models")] + public List Models { get; set; } + } + + public partial class Model + { + [JsonProperty("output_tokens")] + public long OutputTokens { get; set; } + + [JsonProperty("model_id")] + public string ModelId { get; set; } + + [JsonProperty("input_tokens")] + public long InputTokens { get; set; } + } +} \ No newline at end of file diff --git a/host/llm/entity/CommonInput.cs b/host/llm/entity/CommonInput.cs new file mode 100644 index 0000000..6d1da54 --- /dev/null +++ b/host/llm/entity/CommonInput.cs @@ -0,0 +1,31 @@ +namespace LinkToolAddin.host.llm.entity +{ + using System; + using System.Collections.Generic; + + using System.Globalization; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + + public partial class CommonInput + { + [JsonProperty("input")] + public Input Input { get; set; } + + [JsonProperty("parameters")] + public Debug Parameters { get; set; } + + [JsonProperty("debug")] + public Debug Debug { get; set; } + } + + public partial class Debug + { + } + + public partial class Input + { + [JsonProperty("prompt")] + public string Prompt { get; set; } + } +} \ No newline at end of file diff --git a/host/llm/entity/KnowldgeResult.cs b/host/llm/entity/KnowldgeResult.cs new file mode 100644 index 0000000..6480853 --- /dev/null +++ b/host/llm/entity/KnowldgeResult.cs @@ -0,0 +1,42 @@ +namespace LinkToolAddin.host.llm.entity +{ + using System; + using System.Collections.Generic; + + using System.Globalization; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + + public partial class KnowledgeResult + { + [JsonProperty("rewriteQuery")] + public string RewriteQuery { get; set; } + + [JsonProperty("chunkList")] + public List ChunkList { get; set; } + } + + public partial class ChunkList + { + [JsonProperty("score")] + public double Score { get; set; } + + [JsonProperty("imagesUrl")] + public List ImagesUrl { get; set; } + + [JsonProperty("documentName")] + public string DocumentName { get; set; } + + [JsonProperty("titcontent", NullValueHandling = NullValueHandling.Ignore)] + public string Titcontent { get; set; } + + [JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)] + public string Title { get; set; } + + [JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)] + public string Content { get; set; } + + [JsonProperty("conten_score_with_weight:0.6082842946052551\n【\ue000正\ue000文\ue000】\ue000:输\ue000出\ue000数\ue000据\ue000集\ue000将\ue000包\ue000含\ue000一\ue000个\ue000 BUFF_DIST 字\ue000段\ue000,\ue000该\ue000字\ue000段\ue000包\ue000含\ue000用\ue000于\ue000缓\ue000冲\ue000各\ue000要\ue000素\ue000的\ue000缓\ue000冲\ue000距\ue000离\ue000(\ue000使\ue000用\ue000输\ue000入\ue000要\ue000素\ue000坐\ue000标\ue000系\ue000的\ue000线\ue000性\ue000单\ue000位\ue000)\ue000。\ue000 如\ue000果\ue000已\ue000设\ue000置\ue000输\ue000出\ue000坐\ue000标\ue000系\ue000,\ue000则\ue000 BUFF_DIST 单\ue000位\ue000将\ue000位\ue000于\ue000该\ue000坐\ue000标\ue000系\ue000当\ue000中\ue000。\ue000输\ue000出\ue000ST 单\ue000位\ue000将\ue000位\ue000于\ue000该\ue000坐\ue000标\ue000系\ue000当\ue000中\ue000。\ue000 如\ue000果\ue000字\ue000段\ue000在\ue000输\ue000出\ue000中\ue000已\ue000存\ue000在\ue000,\ue000系\ue000统\ue000会\ue000在\ue000字\ue000段\ue000名\ue000称\ue000的\ue000结\ue000尾\ue000追\ue000加\ue000一\ue000个\ue000数\ue000字\ue000以\ue000确\ue000保\ue000其\ue000唯\ue000一\ue000性\ue000(\ue000例\ue000如\ue000,\ue000BUFF_DIST1)\ue000。\ue000您\ue000可\ue000以\ue000执\ue000行\ue000以\ue000下\ue000一\ue000项\ue000或\ue000多\ue000项\ue000操\ue000作\ue000来\ue000提\ue000高\ue000创\ue000建\ue000缓\ue000冲\ue000区\ue000工\ue000具\ue000的\ue000性\ue000能\ue000。\ue000设\ue000置\ue000范\ue000围\ue000环\ue000境\ue000,\ue000以\ue000便\ue000仅\ue000分\ue000析\ue000感\ue000兴\ue000趣\ue000的\ue000数\ue000据\ue000。\ue000使\ue000分\ue000析\ue000运\ue000行\ue000的\ue000位\ue000置\ue000。\ue000此\ue000地\ue000理\ue000处理工具由 ArcGIS GeoAnalytics Server 作为支持。 GeoAnalytics Server 上的分析已完成,结果将存储在 ArcGIS Enterprise 的内容中。当运行 GeoAnalytics Server 工具时,GeoAnalytics Server 上的分析已完成。entName", NullValueHandling = NullValueHandling.Ignore)] + public string ContenScoreWithWeight06082842946052551正文输出数据集将包含一个BuffDist字段该字段包含用于缓冲各要素的缓冲距离使用输入要素坐标系的线性单位如果已设置输出坐标系则BuffDist单位将位于该坐标系当中输出St单位将位于该坐标系当中如果字段在输出中已存在系统会在字段名称的结尾追加一个数字以确保其唯一性例如BuffDist1您可以执行以下一项或多项操作来提高创建缓冲区工具的性能设置范围环境以便仅分析感兴趣的数据使分析运行的位置此地理处理工具由ArcGisGeoAnalyticsServer作为支持GeoAnalyticsServer上的分析已完成结果将存储在ArcGisEnterprise的内容中当运行GeoAnalyticsServer工具时GeoAnalyticsServer上的分析已完成EntName { get; set; } + } +} diff --git a/host/llm/entity/LlmChat.cs b/host/llm/entity/LlmChat.cs new file mode 100644 index 0000000..d354865 --- /dev/null +++ b/host/llm/entity/LlmChat.cs @@ -0,0 +1,69 @@ +namespace LinkToolAddin.host.llm.entity +{ + using System; + using System.Collections.Generic; + + using System.Globalization; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + + public partial class LlmChat + { + [JsonProperty("choices")] + public List Choices { get; set; } + + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("usage")] + public Usage Usage { get; set; } + + [JsonProperty("created")] + public long Created { get; set; } + + [JsonProperty("system_fingerprint")] + public object SystemFingerprint { get; set; } + + [JsonProperty("model")] + public string Model { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + } + + public partial class Choice + { + [JsonProperty("message")] + public Message Message { get; set; } + + [JsonProperty("finish_reason")] + public string FinishReason { get; set; } + + [JsonProperty("index")] + public long Index { get; set; } + + [JsonProperty("logprobs")] + public object Logprobs { get; set; } + } + + public partial class Usage + { + [JsonProperty("prompt_tokens")] + public long PromptTokens { get; set; } + + [JsonProperty("completion_tokens")] + public long CompletionTokens { get; set; } + + [JsonProperty("total_tokens")] + public long TotalTokens { get; set; } + + [JsonProperty("prompt_tokens_details")] + public PromptTokensDetails PromptTokensDetails { get; set; } + } + + public partial class PromptTokensDetails + { + [JsonProperty("cached_tokens")] + public long CachedTokens { get; set; } + } +} \ No newline at end of file diff --git a/host/llm/entity/LlmJsonContent.cs b/host/llm/entity/LlmJsonContent.cs new file mode 100644 index 0000000..5b53edf --- /dev/null +++ b/host/llm/entity/LlmJsonContent.cs @@ -0,0 +1,38 @@ +namespace LinkToolAddin.host.llm.entity +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public partial class LlmJsonContent + { + [JsonProperty("model")] + public string Model { get; set; } + + [JsonProperty("messages")] + public List Messages { get; set; } + + [JsonProperty("stream")] + public bool Stream { get; set; } = false; + + [JsonProperty("temperature")] + public double Temperature { get; set; } = 0.7; + + [JsonProperty("top_p")] + public double TopP { get; set; } = 1.0; + + [JsonProperty("max_tokens")] + public int MaxTokens { get; set; } = 2048; + + [JsonProperty("top_k")] + public int TopK { get; set; } = 40; + } + + public partial class Message + { + [JsonProperty("role")] + public string Role { get; set; } + + [JsonProperty("content")] + public string Content { get; set; } + } +} \ No newline at end of file diff --git a/resource/DocDb.cs b/resource/DocDb.cs index 3164327..1487b5e 100644 --- a/resource/DocDb.cs +++ b/resource/DocDb.cs @@ -1,235 +1,54 @@ -// -// -// To parse this JSON data, add NuGet 'System.Text.Json' then do: -// -// using QuickType; -// -// var welcome = Welcome.FromJson(jsonString); -#nullable enable -#pragma warning disable CS8618 -#pragma warning disable CS8601 -#pragma warning disable CS8603 +using System.Collections.Generic; +using System.Threading.Tasks; +using LinkToolAddin.host.llm; +using LinkToolAddin.host.llm.entity; +using Newtonsoft.Json; -namespace QuickType +namespace LinkToolAddin.resource; + +public class DocDb { - using System; - using System.Collections.Generic; - - using System.Text.Json; - using System.Text.Json.Serialization; - using System.Globalization; - - public partial class DocDb - { - [JsonPropertyName("Code")] - public string Code { get; set; } - - [JsonPropertyName("Data")] - public Data Data { get; set; } - - [JsonPropertyName("Message")] - public string Message { get; set; } - - [JsonPropertyName("RequestId")] - public string RequestId { get; set; } - - [JsonPropertyName("Status")] - public long Status { get; set; } - - [JsonPropertyName("Success")] - public bool Success { get; set; } - } - - public partial class Data - { - [JsonPropertyName("Nodes")] - public List Nodes { get; set; } - } - - public partial class Node - { - [JsonPropertyName("Metadata")] - public Metadata Metadata { get; set; } - - [JsonPropertyName("Score")] - public double Score { get; set; } - - [JsonPropertyName("Text")] - public string Text { get; set; } - } - - public partial class Metadata - { - [JsonPropertyName("parent")] - public string Parent { get; set; } - - [JsonPropertyName("file_path")] - public Uri FilePath { get; set; } - - [JsonPropertyName("image_url")] - public List ImageUrl { get; set; } - - [JsonPropertyName("nid")] - public string Nid { get; set; } - - [JsonPropertyName("title")] - public string Title { get; set; } - - [JsonPropertyName("doc_id")] - public string DocId { get; set; } - - [JsonPropertyName("content")] - public string Content { get; set; } - - [JsonPropertyName("workspace_id")] - public string WorkspaceId { get; set; } - - [JsonPropertyName("hier_title")] - public string HierTitle { get; set; } - - [JsonPropertyName("doc_name")] - public string DocName { get; set; } - - [JsonPropertyName("pipeline_id")] - public string PipelineId { get; set; } - - [JsonPropertyName("_id")] - public string Id { get; set; } - } - - public partial class Welcome - { - public static Welcome FromJson(string json) => JsonSerializer.Deserialize(json, QuickType.Converter.Settings); - } - - public static class Serialize - { - public static string ToJson(this Welcome self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings); - } - - internal static class Converter - { - public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General) - { - Converters = - { - new DateOnlyConverter(), - new TimeOnlyConverter(), - IsoDateTimeOffsetConverter.Singleton - }, - }; - } + public string appId {get;set;} + public string apiKey {get;set;} - public class DateOnlyConverter : JsonConverter + public DocDb(string apiKey,KnowledgeBase knowledgeBaseEnum) { - private readonly string serializationFormat; - public DateOnlyConverter() : this(null) { } - - public DateOnlyConverter(string? serializationFormat) - { - this.serializationFormat = serializationFormat ?? "yyyy-MM-dd"; - } - - public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var value = reader.GetString(); - return DateOnly.Parse(value!); - } - - public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) - => writer.WriteStringValue(value.ToString(serializationFormat)); + this.apiKey = apiKey; + appId = knowledgeBase[knowledgeBaseEnum]; } - public class TimeOnlyConverter : JsonConverter + public enum KnowledgeBase { - private readonly string serializationFormat; - - public TimeOnlyConverter() : this(null) { } - - public TimeOnlyConverter(string? serializationFormat) - { - this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff"; - } - - public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var value = reader.GetString(); - return TimeOnly.Parse(value!); - } - - public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options) - => writer.WriteStringValue(value.ToString(serializationFormat)); + ArcGISProHelpDoc, + ArcGISProToolDoc, + TaskPlanningDoc, + ArcGISProApplicantExample } - internal class IsoDateTimeOffsetConverter : JsonConverter + public Dictionary knowledgeBase = new Dictionary { - public override bool CanConvert(Type t) => t == typeof(DateTimeOffset); - - private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; - - private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; - private string? _dateTimeFormat; - private CultureInfo? _culture; - - public DateTimeStyles DateTimeStyles + {KnowledgeBase.ArcGISProHelpDoc,"6a77c5a68de64f469b79fcdcde9d5001"} + }; + + public async Task Retrieve(string query) + { + Llm bailian = new Bailian { - get => _dateTimeStyles; - set => _dateTimeStyles = value; - } - - public string? DateTimeFormat + api_key = apiKey, + app_id = appId, + }; + var commonInput = new CommonInput { - get => _dateTimeFormat ?? string.Empty; - set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; - } - - public CultureInfo Culture - { - get => _culture ?? CultureInfo.CurrentCulture; - set => _culture = value; - } - - public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) - { - string text; - - - if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal - || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal) - { - value = value.ToUniversalTime(); - } - - text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture); - - writer.WriteStringValue(text); - } - - public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - string? dateText = reader.GetString(); - - if (string.IsNullOrEmpty(dateText) == false) - { - if (!string.IsNullOrEmpty(_dateTimeFormat)) - { - return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles); - } - else - { - return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles); - } - } - else - { - return default(DateTimeOffset); - } - } - - - public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter(); + Input = new Input + { + Prompt = query + }, + Parameters = new Debug(), + Debug = new Debug() + }; + string responseBody = await bailian.SendApplicationAsync(commonInput); + ApplicationOutput result = JsonConvert.DeserializeObject(responseBody); + KnowledgeResult knowledgeResult = JsonConvert.DeserializeObject(result.Output.Text); + return knowledgeResult; } -} -#pragma warning restore CS8618 -#pragma warning restore CS8601 -#pragma warning restore CS8603 +} \ No newline at end of file diff --git a/server/CallArcGISPro.cs b/server/CallArcGISPro.cs index a86ba63..39f5ef0 100644 --- a/server/CallArcGISPro.cs +++ b/server/CallArcGISPro.cs @@ -1,23 +1,23 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; +using ArcGIS.Desktop.Core.Geoprocessing; using ArcGIS.Desktop.Framework.Dialogs; +using ArcGIS.Desktop.Framework.Threading.Tasks; namespace LinkToolAddin.server; public class CallArcGISPro { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(CallArcGISPro)); - public static JsonRpcResultEntity CallArcGISProTool(string methodName, List methodParams) + public async static Task CallArcGISProTool(string toolName, List toolParams) { - // Simulate a call to ArcGIS Pro and return a success response - var successResponse = new JsonRpcSuccessEntity + var results = await Geoprocessing.ExecuteToolAsync(toolName, toolParams); + log.Info($"CallArcGISProTool: {toolName} | {toolParams}"); + return new JsonRpcSuccessEntity() { - Jsonrpc = "2.0", Id = 1, - Result = $"ArcGIS Pro {methodName} method called successfully" + Result = results.ToString() }; - log.Info($"ArcGIS Pro {methodName} method called successfully"); - MessageBox.Show($"ArcGIS Pro {methodName} method called successfully", "Test JsonRpc"); - return successResponse; } } \ No newline at end of file diff --git a/ui/dockpane/DialogDockpane.xaml.cs b/ui/dockpane/DialogDockpane.xaml.cs index 0196a6c..2e2d6b6 100644 --- a/ui/dockpane/DialogDockpane.xaml.cs +++ b/ui/dockpane/DialogDockpane.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Net.Http; @@ -10,11 +11,16 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using System.Text.Json; using System.Threading; +using ArcGIS.Desktop.Core.Geoprocessing; +using LinkToolAddin.host.llm; +using LinkToolAddin.host.llm.entity; +using LinkToolAddin.resource; using log4net; using log4net.Appender; using log4net.Config; using log4net.Layout; using ModelContextProtocol.Server; +using Newtonsoft.Json; namespace LinkToolAddin.ui.dockpane { @@ -30,12 +36,45 @@ namespace LinkToolAddin.ui.dockpane InitLogger(); InitializeComponent(); } + + public void CallBack(string str,object obj) + { + log.Info($"CallBack {str}"); + } private async void TestServer_OnClick(object sender, RoutedEventArgs e) { log.Info("TestServer Clicked"); - string jsonRpcString = @"{""jsonrpc"":""2.0"",""method"":""CallArcGISPro.CallArcGISProTool"",""params"":{""toolName"":""Testbbb"",""toolParams"":""[\""aa\"",\""bbb\""]""},""id"":1}"; - LinkToolAddin.host.CallMcp.CallInnerMcpTool(jsonRpcString); + // string jsonRpcString = @"{""jsonrpc"":""2.0"",""method"":""CallArcGISPro.CallArcGISProTool"",""params"":{""toolName"":""analysis.Buffer"",""toolParams"":""[\""D:/01_Development/02_ArcGIS_Pro_Project/20250319_GisAi/Test.gdb/河流\"",\""D:/01_Development/02_ArcGIS_Pro_Project/20250319_GisAi/Test.gdb/河流buffer\"",\""100\""]""},""id"":1}"; + DocDb docDb = new DocDb("sk-db177155677e438f832860e7f4da6afc", DocDb.KnowledgeBase.ArcGISProHelpDoc); + string query = "缓冲区"; + KnowledgeResult knowledgeResult = await docDb.Retrieve(query); + log.Info(JsonConvert.SerializeObject(knowledgeResult.ChunkList)); + } + + private async void Request_Bailian_Test() + { + Llm bailian = new Bailian + { + api_key = "sk-db177155677e438f832860e7f4da6afc", + app_id = "6a77c5a68de64f469b79fcdcde9d5001", + }; + string reponse = await bailian.SendChatAsync(new LlmJsonContent() + { + Model = "qwen-max", + Messages = new List() + { + new Message() + { + Role = "user", + Content = "你是谁" + } + }, + Temperature = 0.7, + TopP = 1, + MaxTokens = 1000, + }); + log.Info(reponse); } protected void InitLogger() @@ -51,7 +90,7 @@ namespace LinkToolAddin.ui.dockpane // 2. 创建文件滚动输出器(按大小滚动) var fileAppender = new RollingFileAppender { - File = Path.Combine("Logs", "app.log"), // 日志文件路径 + File = Path.Combine("Logs", "linktool_app.log"), // 日志文件路径 AppendToFile = true, // 追加模式 RollingStyle = RollingFileAppender.RollingMode.Size, // 按文件大小滚动 MaxSizeRollBackups = 10, // 保留 10 个历史文件