Work in Progress
parent
824bdd034b
commit
021210a74e
|
@ -2,5 +2,6 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../ln.http" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,7 +8,7 @@ public class AiAssistantCli
|
|||
public static void Main(string[] arguments)
|
||||
{
|
||||
if (arguments.Length < 2) {
|
||||
Console.Error.WriteLine("usage: AiAssistantCli <username> <password>");
|
||||
Console.Error.WriteLine("usage: AiAssistantCli <identity.db> <username> [ <password> ]");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ln.http\ln.http\ln.http.csproj" />
|
||||
<ProjectReference Include="..\ln.ai.assistant\ln.ai.assistant.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.ai.assistant", "ln.ai.assistant\ln.ai.assistant.csproj", "{B232F124-4775-408D-A684-06D5A1E1E6C0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.http", "..\dotnet\ln.http\ln.http\ln.http.csproj", "{25931030-FE87-422A-9210-175432F26D3B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.ai.assistant.cli", "ln.ai.assistant.cli\ln.ai.assistant.cli.csproj", "{AE1BABE3-0BDC-481C-86F7-BEB11FCBCBE6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.http", "..\ln.http\ln.http\ln.http.csproj", "{8E7C84A0-AC21-49C6-A868-E594BAFD3E32}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -16,13 +16,13 @@ Global
|
|||
{B232F124-4775-408D-A684-06D5A1E1E6C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B232F124-4775-408D-A684-06D5A1E1E6C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B232F124-4775-408D-A684-06D5A1E1E6C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{25931030-FE87-422A-9210-175432F26D3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{25931030-FE87-422A-9210-175432F26D3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{25931030-FE87-422A-9210-175432F26D3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{25931030-FE87-422A-9210-175432F26D3B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AE1BABE3-0BDC-481C-86F7-BEB11FCBCBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AE1BABE3-0BDC-481C-86F7-BEB11FCBCBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AE1BABE3-0BDC-481C-86F7-BEB11FCBCBE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AE1BABE3-0BDC-481C-86F7-BEB11FCBCBE6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8E7C84A0-AC21-49C6-A868-E594BAFD3E32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8E7C84A0-AC21-49C6-A868-E594BAFD3E32}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8E7C84A0-AC21-49C6-A868-E594BAFD3E32}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8E7C84A0-AC21-49C6-A868-E594BAFD3E32}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -15,6 +15,9 @@ public class CertificateAuthority
|
|||
{
|
||||
StoragePath = storagePath;
|
||||
Name = caName;
|
||||
|
||||
if (!Directory.Exists(StoragePath))
|
||||
Directory.CreateDirectory(StoragePath);
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,17 @@ public class CompletionApi : HttpEndpointController
|
|||
public HttpResponse PostChatCompletion(HttpPrincipal principal,
|
||||
[JsonBody] api.openai.ChatCompletionRequest chatCompletionRequest)
|
||||
{
|
||||
for (int n=0;n<chatCompletionRequest.Messages.Count; n++)
|
||||
{
|
||||
var message = chatCompletionRequest.Messages[n];
|
||||
if (message.Role.Equals("file"))
|
||||
{
|
||||
message.Content = String.Format("Datei: {0}\n{1}", chatCompletionRequest.Messages[n].Name, chatCompletionRequest.Messages[n].Content);
|
||||
chatCompletionRequest.Messages[n] = message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var completionTask = new CompletionTask<ChatCompletionResponse>(principal.UniqueId, () =>
|
||||
{
|
||||
var result = _completionProvider.ChatCompletion(chatCompletionRequest);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
using System.Reflection;
|
||||
using ln.ai.assistant.api.toolcall;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ln.ai.assistant;
|
||||
|
||||
public class JsonMethodSignatures
|
||||
{
|
||||
|
||||
public static string CreateMethodSignature(MethodInfo methodInfo, string? description, Dictionary<string, string> parameterDescriptions = null)
|
||||
{
|
||||
var toolDefinition = new ToolDefinition()
|
||||
{
|
||||
Type = "function",
|
||||
Function = new Function
|
||||
{
|
||||
Name = methodInfo.Name,
|
||||
Description = description ?? methodInfo.Name,
|
||||
Parameters = new Parameters
|
||||
{
|
||||
Type = "object",
|
||||
Properties = new Dictionary<string, Property>(),
|
||||
Required = new List<string>()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var parameters = methodInfo.GetParameters();
|
||||
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
var parameterName = parameter.Name;
|
||||
var parameterType = parameter.ParameterType.FullName;
|
||||
var parameterDescription = parameterDescriptions != null && parameterDescriptions.TryGetValue(parameterName, out var desc) ? desc : null;
|
||||
|
||||
var property = new Property
|
||||
{
|
||||
Type = parameterType,
|
||||
};
|
||||
if (parameterDescription is string)
|
||||
property.Description = parameterDescription;
|
||||
|
||||
toolDefinition.Function.Parameters.Properties.Add(parameterName, property);
|
||||
|
||||
if (!parameter.HasDefaultValue)
|
||||
toolDefinition.Function.Parameters.Required.Add(parameterName);
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(toolDefinition, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
using System.Reflection;
|
||||
using System.Text;
|
||||
using ln.ai.assistant.api.openai;
|
||||
using ln.http;
|
||||
using ln.patterns;
|
||||
using Newtonsoft.Json;
|
||||
using HttpClient = ln.http.client.HttpClient;
|
||||
using HttpMethod = ln.http.HttpMethod;
|
||||
|
||||
namespace ln.ai.assistant;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using ln.ai.assistant.api.toolcall;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ln.ai.assistant.api.openai
|
||||
|
@ -27,6 +28,8 @@ namespace ln.ai.assistant.api.openai
|
|||
|
||||
[JsonProperty("stop",NullValueHandling = NullValueHandling.Ignore)]
|
||||
public List<string> Stop;
|
||||
|
||||
[JsonProperty("tools")] public List<Function> Tools = new List<Function>();
|
||||
}
|
||||
|
||||
public struct ChatCompletionResponse
|
||||
|
@ -50,6 +53,7 @@ namespace ln.ai.assistant.api.openai
|
|||
{
|
||||
[JsonProperty("role")] public string Role;
|
||||
[JsonProperty("content")] public string Content;
|
||||
[JsonProperty("name")] public string Name;
|
||||
}
|
||||
|
||||
public struct Usage
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
namespace ln.ai.assistant.api.toolcall;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class ToolDefinition
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty("function")]
|
||||
public Function Function { get; set; }
|
||||
}
|
||||
|
||||
public class Function
|
||||
{
|
||||
[JsonProperty("name")] public string Name { get; set; }
|
||||
[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] public string Description { get; set; }
|
||||
[JsonProperty("parameters")] public Parameters Parameters { get; set; }
|
||||
}
|
||||
|
||||
public class Parameters
|
||||
{
|
||||
[JsonProperty("type")] public string Type { get; set; } = "object";
|
||||
[JsonProperty("properties")] public Dictionary<string, Property> Properties { get; set; }
|
||||
[JsonProperty("required")] public List<string> Required { get; set; }
|
||||
}
|
||||
|
||||
public class Property
|
||||
{
|
||||
[JsonProperty("type")] public string Type { get; set; }
|
||||
[JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] public string Description { get; set; }
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\dotnet\ln.http\ln.http\ln.http.csproj" />
|
||||
<ProjectReference Include="..\..\ln.http\ln.http\ln.http.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using ln.ai.assistant.auth;
|
||||
using ln.bootstrap;
|
||||
using ln.http;
|
||||
|
||||
|
@ -8,6 +9,10 @@ namespace ln.ai.assistant
|
|||
{
|
||||
static void Main(string[] arguments)
|
||||
{
|
||||
var m = typeof(LoginIdentity).GetMethod("ValidateResponse");
|
||||
Console.WriteLine(JsonMethodSignatures.CreateMethodSignature(m, "Validate the response to a authentication challenge"));
|
||||
return;
|
||||
|
||||
Bootstrap.Debug = true;
|
||||
Bootstrap
|
||||
.DefaultInstance
|
||||
|
|
Loading…
Reference in New Issue