harbor run -t openthoughts/tasktrove-exp-rpt-crosscodeeval-csharp-v4-crosscodeeval-csharp-1510harbor download openthoughts/tasktrove-exp-rpt-crosscodeeval-csharp-v4-crosscodeeval-csharp-1510solution file
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.Memory.Qdrant;
using Microsoft.SemanticKernel.CoreSkills;
using Microsoft.SemanticKernel.KernelExtensions;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.SkillDefinition;
using SKernel.Factory;
using SKernel.Factory.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace SKernel
{
public static partial class Extensions
{
internal static ISKFunction CreatePlan(this IKernel kernel) =>
kernel.Skills.GetFunction("plannerskill", "createplan");
internal static ISKFunction ExecutePlan(this IKernel kernel) =>
kernel.Skills.GetFunction("plannerskill", "executeplan");
internal static ContextVariables ToContext(this IEnumerable<KeyValuePair<string, string>> variables)
{
var context = new ContextVariables();
foreach (var variable in variables) context[variable.Key] = variable.Value;
return context;
}
internal static IKernel RegisterSemanticSkills(this IKernel kernel, string skill, IList<string> skills, ILogger logger)
{
foreach (var prompt in Directory.EnumerateFiles(skill, "*.txt", SearchOption.AllDirectories)
.Select(_ => new FileInfo(_)))
{
logger.LogDebug($"{prompt} === ");
logger.LogDebug($"{skill} === ");
logger.LogDebug($"{prompt.Directory?.Parent} === ");
var skillName = FunctionName(new DirectoryInfo(skill), prompt.Directory);
logger.LogDebug($"{skillName} === ");
if (skills.Count != 0 && !skills.Contains(skillName.ToLower())) continue;
logger.LogDebug($"Importing semantic skill ${skill}/${skillName}");
kernel.ImportSemanticSkillFromDirectory(skill, skillName);
}
return kernel;
}
private static string FunctionName(DirectoryInfo skill, DirectoryInfo? folder)
{
while (!skill.FullName.Equals(folder?.Parent?.FullName)) folder = folder?.Parent;
return folder.Name;
}
internal static KernelBuilder WithOpenAI(this KernelBuilder builder, SKConfig config, ApiKey api) =>
builder.Configure(_ =>
{
if (api.Text != null)
_.AddOpenAITextCompletionService("text", config.Models.Text, api.Text);
if (api.Embedding != null)
_.AddOpenAIEmbeddingGenerationService("embedding", config.Models.Embedding, api.Embedding);
if (api.Chat != null)
_.AddOpenAIChatCompletionService("chat", config.Models.Chat, api.Chat);
});
internal static IKernel Register(this IKernel kernel, ISkillsImporter importer, IList<string> skills)
{
importer.ImportSkills(kernel, skills);
return kernel;
}
public static IKernel RegistryCoreSkills(this IKernel kernel, IList<string> skills)
{
if (ShouldLoad(skills, nameof(FileIOSkill)))
kernel.ImportSkill(new FileIOSkill(), nameof(FileIOSkill));
if (ShouldLoad(skills, nameof(HttpSkill)))
kernel.ImportSkill(new HttpSkill(), nameof(HttpSkill));
if (ShouldLoad(skills, nameof(TextSkill)))
kernel.ImportSkill(new TextSkill(), nameof(TextSkill));
if (ShouldLoad(skills, nameof(TextMemorySkill)))
kernel.ImportSkill(new TextMemorySkill(), nameof(TextMemorySkill));
if (ShouldLoad(skills, nameof(ConversationSummarySkill)))
kernel.ImportSkill(new ConversationSummarySkill(kernel), nameof(ConversationSummarySkill));
if (ShouldLoad(skills, nameof(TimeSkill)))
kernel.ImportSkill(new TimeSkill(), nameof(TimeSkill));
kernel.ImportSkill(new PlannerSkill(kernel), nameof(PlannerSkill));
return kernel;
}
private static bool ShouldLoad(IList<string> skills, string skill) =>
skills.Count == 0 || skills.Contains(skill.ToLower());
public static IHostBuilder ConfigureAdventKernelDefaults(this IHostBuilder builder, IConfiguration configuration) =>
builder.ConfigureServices(services =>
{
services.AddSemanticKernelFactory(configuration);
services.AddConsoleLogger(configuration);
});
public static IServiceCollection AddSemanticKernelFactory(this IServiceCollection services, IConfiguration configuration)
{
var config = new SKConfig();
configuration.Bind(config);
var options = config.Skills.ToSkillOptions();
foreach (var skillType in options.NativeSkillTypes)
services.AddSingleton(skillType);
services.AddSingleton(options);
services.AddSingleton(config);
services.AddSingleton<NativeSkillsImporter>();
services.AddSingleton<SemanticSkillsImporter>();
services.AddSingleton<SemanticKernelFactory>();
services.AddSingleton(typeof(IPlanExecutor), typeof(DefaultPlanExecutor));
services.AddSingleton<IMemoryStore>(
config.Memory.Type == "Volatile"
? new VolatileMemoryStore()
: new QdrantMemoryStore(config.Memory.Host, config.Memory.Port, config.Memory.VectorSize));
return services;
}
public static IServiceCollection AddConsoleLogger(this IServiceCollection services, IConfiguration configuration)
{
var factory = LoggerFactory.Create(builder =>
{
builder.AddConfiguration(configuration.GetSection("Logging"));
builder.AddConsole();
});
services.AddSingleton(factory);
services.AddSingleton<ILogger>(factory.CreateLogger<object>());
return services;
}
public static IList<FunctionView> ToSkills(this IKernel kernel)
{
var view = kernel.Skills.GetFunctionsView();
return view.NativeFunctions.Values.SelectMany(Enumerable.ToList)
.Union(view.SemanticFunctions.Values.SelectMany(Enumerable.ToList)).ToList();
}
public static async Task<SKContext> InvokePipedFunctions(this IKernel kernel, Message message) =>
await kernel.RunAsync(message.Variables.ToContext(),
(message.Pipeline?.Select(_ => kernel.Skills.GetFunction(_.Skill, _.Name)) ?? Array.Empty<ISKFunction>())
.ToArray());
public static
This is a line completion task in the CrossCodeEval style. The C# snippet
above ends mid-declaration on purpose -- on something like public List<,
private unsafe , or [JsonProperty("...")]\n public bool? X {. Your
job is to output the short continuation that completes that cut-off code
fragment. The continuation is typically 1-3 lines and 20-200 characters; it
is appended to the snippet conceptually, NOT a standalone file.
You must write your line-completion fragment to /app/solution.txt. The
verifier reads ONLY that file. The most common mistake is to type the C#
fragment straight into bash -- bash treats (, <, >, ,, {, etc.
as shell metacharacters and dies with syntax error near unexpected token,
and /app/solution.txt never gets created.
To avoid all bash-quoting traps, use the pre-installed helper:
write_solution 'YOUR FRAGMENT GOES HERE'
write_solution is on your PATH. It takes its single argument verbatim,
writes it to /app/solution.txt followed by a newline, and is safe with
any C# content because the argument is single-quoted. You must single-quote
your fragment so bash does not try to interpret the inner punctuation. If
your fragment itself contains a single quote, escape it as '\''.
Equivalent without the helper (slightly more error-prone):
printf '%s\n' 'YOUR FRAGMENT GOES HERE' > /app/solution.txt
WRONG -- typed into bash, gets syntax error, never creates solution.txt:
Module> Modules => GetModules();
WRONG -- unquoted < > ( ) blow up at bash parse-time:
echo -n string QueryServiceFilePath(SafeServiceHandle service) > /app/solution.txt
WRONG -- nested bash -lc '...' without escaping inner punctuation:
bash -lc 'echo -n string QueryServiceFilePath(SafeServiceHandle service) > /app/solution.txt'
WRONG -- literal \n (backslash-n) instead of a real newline; printf is
never told to terminate:
printf '...content with literal \\n in it...' >> /app/solution.txt
RIGHT -- single-quoted, written through the helper:
write_solution 'Module> Modules => GetModules();'
RIGHT -- single-quoted, written through printf:
printf '%s\n' 'Module> Modules => GetModules();' > /app/solution.txt
using directives or namespace blocks. Do NOT
wrap the fragment in Markdown code fences. Do NOT prepend solution: or
any other label.If the snippet above ended with:
public Kernel Kernel { get; private set; }
public List<
then a reasonable /app/solution.txt would be:
Module> Modules => GetModules();
(NOT a full class declaration, NOT a using ...; block.) To write that,
run exactly:
write_solution 'Module> Modules => GetModules();'