55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LinkToolAddin.host.llm;
|
|
using LinkToolAddin.host.llm.entity;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace LinkToolAddin.resource;
|
|
|
|
public class DocDb
|
|
{
|
|
public string appId {get;set;}
|
|
public string apiKey {get;set;}
|
|
|
|
public DocDb(string apiKey,KnowledgeBase knowledgeBaseEnum)
|
|
{
|
|
this.apiKey = apiKey;
|
|
appId = knowledgeBase[knowledgeBaseEnum];
|
|
}
|
|
|
|
public enum KnowledgeBase
|
|
{
|
|
ArcGISProHelpDoc,
|
|
ArcGISProToolDoc,
|
|
ArcGISProApplicantExample
|
|
}
|
|
|
|
public Dictionary<KnowledgeBase, string> knowledgeBase = new Dictionary<KnowledgeBase, string>
|
|
{
|
|
{KnowledgeBase.ArcGISProHelpDoc,"6a77c5a68de64f469b79fcdcde9d5001"},
|
|
{KnowledgeBase.ArcGISProToolDoc,"080f8925318247ea822a9e12db5cb5cd"},
|
|
{KnowledgeBase.ArcGISProApplicantExample,"eef60f7c879b4e8597138c261578d2a5"}
|
|
};
|
|
|
|
public async Task<KnowledgeResult> Retrieve(string query)
|
|
{
|
|
Llm bailian = new Bailian
|
|
{
|
|
api_key = apiKey,
|
|
app_id = appId,
|
|
};
|
|
var commonInput = new CommonInput
|
|
{
|
|
Input = new Input
|
|
{
|
|
Prompt = query
|
|
},
|
|
Parameters = new Debug(),
|
|
Debug = new Debug()
|
|
};
|
|
string responseBody = await bailian.SendApplicationAsync(commonInput);
|
|
ApplicationOutput result = JsonConvert.DeserializeObject<ApplicationOutput>(responseBody);
|
|
KnowledgeResult knowledgeResult = JsonConvert.DeserializeObject<KnowledgeResult>(result.Output.Text);
|
|
return knowledgeResult;
|
|
}
|
|
} |