完成在线向量知识库的接入
This commit is contained in:
parent
c05f19b313
commit
0f0f2e5a92
@ -98,6 +98,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AlibabaCloud.SDK.Bailian20231229" Version="2.0.6" />
|
||||||
<PackageReference Include="log4net" Version="3.1.0-preview.3" />
|
<PackageReference Include="log4net" Version="3.1.0-preview.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.3.25171.5" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0-preview.3.25171.5" />
|
||||||
<PackageReference Include="ModelContextProtocol" Version="0.1.0-preview.12" />
|
<PackageReference Include="ModelContextProtocol" Version="0.1.0-preview.12" />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using LinkToolAddin.server;
|
using LinkToolAddin.server;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -6,10 +7,10 @@ namespace LinkToolAddin.client;
|
|||||||
|
|
||||||
public class CallArcGISPro
|
public class CallArcGISPro
|
||||||
{
|
{
|
||||||
public static string CallArcGISProTool(Dictionary<string,string> parameters)
|
public async static Task<string> CallArcGISProTool(Dictionary<string,string> parameters)
|
||||||
{
|
{
|
||||||
// Call the ArcGIS Pro method and get the result
|
// Call the ArcGIS Pro method and get the result
|
||||||
var result = server.CallArcGISPro.CallArcGISProTool(parameters["toolName"], JsonConvert.DeserializeObject<List<string>>(parameters["toolParams"]));
|
var result = await server.CallArcGISPro.CallArcGISProTool(parameters["toolName"], JsonConvert.DeserializeObject<List<string>>(parameters["toolParams"]));
|
||||||
|
|
||||||
// Serialize the result back to a JSON string
|
// Serialize the result back to a JSON string
|
||||||
return JsonConvert.SerializeObject(result);
|
return JsonConvert.SerializeObject(result);
|
||||||
|
|||||||
21
common/HttpRequest.cs
Normal file
21
common/HttpRequest.cs
Normal file
@ -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<string> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,17 +13,16 @@ namespace LinkToolAddin.host
|
|||||||
public class CallMcp
|
public class CallMcp
|
||||||
{
|
{
|
||||||
private static readonly ILog log = LogManager.GetLogger(typeof(CallMcp));
|
private static readonly ILog log = LogManager.GetLogger(typeof(CallMcp));
|
||||||
public static string CallInnerMcpTool(string jsonRpcString)
|
public static async Task<string> CallInnerMcpTool(string jsonRpcString)
|
||||||
{
|
{
|
||||||
log.Info("通过反射调用内部MCP工具");
|
log.Info("通过反射调用内部MCP工具");
|
||||||
var jsonRpcEntity = JsonConvert.DeserializeObject<JsonRpcEntity>(jsonRpcString);
|
var jsonRpcEntity = JsonConvert.DeserializeObject<JsonRpcEntity>(jsonRpcString);
|
||||||
|
|
||||||
Type type = Type.GetType("LinkToolAddin.client."+jsonRpcEntity.Method.Split('.')[0]);
|
Type type = Type.GetType("LinkToolAddin.client."+jsonRpcEntity.Method.Split('.')[0]);
|
||||||
MethodInfo method = type.GetMethod(jsonRpcEntity.Method.Split('.')[1],BindingFlags.Public | BindingFlags.Static);
|
MethodInfo method = type.GetMethod(jsonRpcEntity.Method.Split('.')[1],BindingFlags.Public | BindingFlags.Static);
|
||||||
string result = (string)method.Invoke(null, new object[] { jsonRpcEntity.Params });
|
var task = method.Invoke(null, new object[] { jsonRpcEntity.Params }) as Task<JsonRpcResultEntity>;
|
||||||
|
JsonRpcResultEntity result = await task;
|
||||||
// 将结果序列化为 JSON 字符串
|
return JsonConvert.SerializeObject(result);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
host/llm/Bailian.cs
Normal file
45
host/llm/Bailian.cs
Normal file
@ -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<string> SendChatStreamAsync(string message)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAsyncEnumerable<string> SendApplicationStreamAsync(string message)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> 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<LlmChat>(responseBody);
|
||||||
|
return result.Choices[0].Message.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> 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<ApplicationOutput>(responseBody);
|
||||||
|
return responseBody;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LinkToolAddin.host.llm.entity;
|
||||||
|
|
||||||
namespace LinkToolAddin.host.llm;
|
namespace LinkToolAddin.host.llm;
|
||||||
|
|
||||||
@ -11,4 +13,6 @@ public interface Llm
|
|||||||
|
|
||||||
public IAsyncEnumerable<string> SendChatStreamAsync(string message);
|
public IAsyncEnumerable<string> SendChatStreamAsync(string message);
|
||||||
public IAsyncEnumerable<string> SendApplicationStreamAsync(string message);
|
public IAsyncEnumerable<string> SendApplicationStreamAsync(string message);
|
||||||
|
public Task<string> SendChatAsync(LlmJsonContent jsonContent);
|
||||||
|
public Task<string> SendApplicationAsync(CommonInput commonInput);
|
||||||
}
|
}
|
||||||
51
host/llm/entity/ApplicationOutput.cs
Normal file
51
host/llm/entity/ApplicationOutput.cs
Normal file
@ -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<Model> 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
31
host/llm/entity/CommonInput.cs
Normal file
31
host/llm/entity/CommonInput.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
42
host/llm/entity/KnowldgeResult.cs
Normal file
42
host/llm/entity/KnowldgeResult.cs
Normal file
@ -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> ChunkList { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class ChunkList
|
||||||
|
{
|
||||||
|
[JsonProperty("score")]
|
||||||
|
public double Score { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("imagesUrl")]
|
||||||
|
public List<object> 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
69
host/llm/entity/LlmChat.cs
Normal file
69
host/llm/entity/LlmChat.cs
Normal file
@ -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<Choice> 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
38
host/llm/entity/LlmJsonContent.cs
Normal file
38
host/llm/entity/LlmJsonContent.cs
Normal file
@ -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<Message> 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,235 +1,54 @@
|
|||||||
// <auto-generated />
|
using System.Collections.Generic;
|
||||||
//
|
using System.Threading.Tasks;
|
||||||
// To parse this JSON data, add NuGet 'System.Text.Json' then do:
|
using LinkToolAddin.host.llm;
|
||||||
//
|
using LinkToolAddin.host.llm.entity;
|
||||||
// using QuickType;
|
using Newtonsoft.Json;
|
||||||
//
|
|
||||||
// var welcome = Welcome.FromJson(jsonString);
|
|
||||||
#nullable enable
|
|
||||||
#pragma warning disable CS8618
|
|
||||||
#pragma warning disable CS8601
|
|
||||||
#pragma warning disable CS8603
|
|
||||||
|
|
||||||
namespace QuickType
|
namespace LinkToolAddin.resource;
|
||||||
|
|
||||||
|
public class DocDb
|
||||||
{
|
{
|
||||||
using System;
|
public string appId {get;set;}
|
||||||
using System.Collections.Generic;
|
public string apiKey {get;set;}
|
||||||
|
|
||||||
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<Node> 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<Uri> 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<Welcome>(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 class DateOnlyConverter : JsonConverter<DateOnly>
|
public DocDb(string apiKey,KnowledgeBase knowledgeBaseEnum)
|
||||||
{
|
{
|
||||||
private readonly string serializationFormat;
|
this.apiKey = apiKey;
|
||||||
public DateOnlyConverter() : this(null) { }
|
appId = knowledgeBase[knowledgeBaseEnum];
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TimeOnlyConverter : JsonConverter<TimeOnly>
|
public enum KnowledgeBase
|
||||||
{
|
{
|
||||||
private readonly string serializationFormat;
|
ArcGISProHelpDoc,
|
||||||
|
ArcGISProToolDoc,
|
||||||
public TimeOnlyConverter() : this(null) { }
|
TaskPlanningDoc,
|
||||||
|
ArcGISProApplicantExample
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
|
public Dictionary<KnowledgeBase, string> knowledgeBase = new Dictionary<KnowledgeBase, string>
|
||||||
{
|
{
|
||||||
public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
|
{KnowledgeBase.ArcGISProHelpDoc,"6a77c5a68de64f469b79fcdcde9d5001"}
|
||||||
|
};
|
||||||
private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
|
|
||||||
|
public async Task<KnowledgeResult> Retrieve(string query)
|
||||||
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
|
{
|
||||||
private string? _dateTimeFormat;
|
Llm bailian = new Bailian
|
||||||
private CultureInfo? _culture;
|
|
||||||
|
|
||||||
public DateTimeStyles DateTimeStyles
|
|
||||||
{
|
{
|
||||||
get => _dateTimeStyles;
|
api_key = apiKey,
|
||||||
set => _dateTimeStyles = value;
|
app_id = appId,
|
||||||
}
|
};
|
||||||
|
var commonInput = new CommonInput
|
||||||
public string? DateTimeFormat
|
|
||||||
{
|
{
|
||||||
get => _dateTimeFormat ?? string.Empty;
|
Input = new Input
|
||||||
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
|
{
|
||||||
}
|
Prompt = query
|
||||||
|
},
|
||||||
public CultureInfo Culture
|
Parameters = new Debug(),
|
||||||
{
|
Debug = new Debug()
|
||||||
get => _culture ?? CultureInfo.CurrentCulture;
|
};
|
||||||
set => _culture = value;
|
string responseBody = await bailian.SendApplicationAsync(commonInput);
|
||||||
}
|
ApplicationOutput result = JsonConvert.DeserializeObject<ApplicationOutput>(responseBody);
|
||||||
|
KnowledgeResult knowledgeResult = JsonConvert.DeserializeObject<KnowledgeResult>(result.Output.Text);
|
||||||
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
|
return knowledgeResult;
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma warning restore CS8618
|
|
||||||
#pragma warning restore CS8601
|
|
||||||
#pragma warning restore CS8603
|
|
||||||
@ -1,23 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ArcGIS.Desktop.Core.Geoprocessing;
|
||||||
using ArcGIS.Desktop.Framework.Dialogs;
|
using ArcGIS.Desktop.Framework.Dialogs;
|
||||||
|
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
||||||
|
|
||||||
namespace LinkToolAddin.server;
|
namespace LinkToolAddin.server;
|
||||||
|
|
||||||
public class CallArcGISPro
|
public class CallArcGISPro
|
||||||
{
|
{
|
||||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(CallArcGISPro));
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(CallArcGISPro));
|
||||||
public static JsonRpcResultEntity CallArcGISProTool(string methodName, List<string> methodParams)
|
public async static Task<JsonRpcResultEntity> CallArcGISProTool(string toolName, List<string> toolParams)
|
||||||
{
|
{
|
||||||
// Simulate a call to ArcGIS Pro and return a success response
|
var results = await Geoprocessing.ExecuteToolAsync(toolName, toolParams);
|
||||||
var successResponse = new JsonRpcSuccessEntity
|
log.Info($"CallArcGISProTool: {toolName} | {toolParams}");
|
||||||
|
return new JsonRpcSuccessEntity()
|
||||||
{
|
{
|
||||||
Jsonrpc = "2.0",
|
|
||||||
Id = 1,
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@ -10,11 +11,16 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using ArcGIS.Desktop.Core.Geoprocessing;
|
||||||
|
using LinkToolAddin.host.llm;
|
||||||
|
using LinkToolAddin.host.llm.entity;
|
||||||
|
using LinkToolAddin.resource;
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Appender;
|
using log4net.Appender;
|
||||||
using log4net.Config;
|
using log4net.Config;
|
||||||
using log4net.Layout;
|
using log4net.Layout;
|
||||||
using ModelContextProtocol.Server;
|
using ModelContextProtocol.Server;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace LinkToolAddin.ui.dockpane
|
namespace LinkToolAddin.ui.dockpane
|
||||||
{
|
{
|
||||||
@ -30,12 +36,45 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
InitLogger();
|
InitLogger();
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CallBack(string str,object obj)
|
||||||
|
{
|
||||||
|
log.Info($"CallBack {str}");
|
||||||
|
}
|
||||||
|
|
||||||
private async void TestServer_OnClick(object sender, RoutedEventArgs e)
|
private async void TestServer_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
log.Info("TestServer Clicked");
|
log.Info("TestServer Clicked");
|
||||||
string jsonRpcString = @"{""jsonrpc"":""2.0"",""method"":""CallArcGISPro.CallArcGISProTool"",""params"":{""toolName"":""Testbbb"",""toolParams"":""[\""aa\"",\""bbb\""]""},""id"":1}";
|
// 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}";
|
||||||
LinkToolAddin.host.CallMcp.CallInnerMcpTool(jsonRpcString);
|
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<Message>()
|
||||||
|
{
|
||||||
|
new Message()
|
||||||
|
{
|
||||||
|
Role = "user",
|
||||||
|
Content = "你是谁"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Temperature = 0.7,
|
||||||
|
TopP = 1,
|
||||||
|
MaxTokens = 1000,
|
||||||
|
});
|
||||||
|
log.Info(reponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void InitLogger()
|
protected void InitLogger()
|
||||||
@ -51,7 +90,7 @@ namespace LinkToolAddin.ui.dockpane
|
|||||||
// 2. 创建文件滚动输出器(按大小滚动)
|
// 2. 创建文件滚动输出器(按大小滚动)
|
||||||
var fileAppender = new RollingFileAppender
|
var fileAppender = new RollingFileAppender
|
||||||
{
|
{
|
||||||
File = Path.Combine("Logs", "app.log"), // 日志文件路径
|
File = Path.Combine("Logs", "linktool_app.log"), // 日志文件路径
|
||||||
AppendToFile = true, // 追加模式
|
AppendToFile = true, // 追加模式
|
||||||
RollingStyle = RollingFileAppender.RollingMode.Size, // 按文件大小滚动
|
RollingStyle = RollingFileAppender.RollingMode.Size, // 按文件大小滚动
|
||||||
MaxSizeRollBackups = 10, // 保留 10 个历史文件
|
MaxSizeRollBackups = 10, // 保留 10 个历史文件
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user