simple dev understanding

This commit is contained in:
Kosta Petan 2023-11-16 19:59:35 +00:00
parent 31eaa4c3ce
commit 0cd4e32f23
3 changed files with 34 additions and 6 deletions

View File

@ -16,7 +16,7 @@ public class Dev : SemanticPersona, IDevelopCode
protected override string MemorySegment => "dev-memory"; protected override string MemorySegment => "dev-memory";
public Dev([PersistentState("state", "messages")] IPersistentState<SemanticPersonaState> state,IKernel kernel,ISemanticTextMemory memory, ILogger<Dev> logger) : base(state) public Dev([PersistentState("state", "messages")] IPersistentState<SemanticPersonaState> state, IKernel kernel, ISemanticTextMemory memory, ILogger<Dev> logger) : base(state)
{ {
_kernel = kernel; _kernel = kernel;
_memory = memory; _memory = memory;
@ -51,7 +51,7 @@ public class Dev : SemanticPersona, IDevelopCode
return resultMessage; return resultMessage;
} }
catch(Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error generating code"); _logger.LogError(ex, "Error generating code");
return default; return default;
@ -65,8 +65,28 @@ public class Dev : SemanticPersona, IDevelopCode
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<string> BuildUnderstanding(string content) public async Task<UnderstandingResult> BuildUnderstanding(string content)
{ {
throw new NotImplementedException(); var explainFunction = _kernel.CreateSemanticFunction(Developer.Explain, new OpenAIRequestSettings { MaxTokens = 15000, Temperature = 0.8, TopP = 1 });
var consolidateFunction = _kernel.CreateSemanticFunction(Developer.ConsolidateUnderstanding, new OpenAIRequestSettings { MaxTokens = 15000, Temperature = 0.8, TopP = 1 });
var explainContext = new ContextVariables();
explainContext.Set("input", content);
var explainResult = await _kernel.RunAsync(explainContext, explainFunction);
var explainMesage = explainResult.ToString();
var consolidateContext = new ContextVariables();
consolidateContext.Set("input", _state.State.Understanding);
consolidateContext.Set("newUnderstanding", explainMesage);
var consolidateResult = await _kernel.RunAsync(consolidateContext, consolidateFunction);
var consolidateMessage = consolidateResult.ToString();
_state.State.Understanding = consolidateMessage;
await _state.WriteStateAsync();
return new UnderstandingResult {
NewUnderstanding = consolidateMessage,
Explanation = explainMesage
};
} }
} }

View File

@ -34,6 +34,7 @@ public class Ingester : SemanticPersona, IIngestRepo
codeAnalysis.ToList().ForEach(async c => codeAnalysis.ToList().ForEach(async c =>
await _memory.SaveInformationAsync(MemorySegment, c.CodeBlock, Guid.NewGuid().ToString(), c.Meaning)); await _memory.SaveInformationAsync(MemorySegment, c.CodeBlock, Guid.NewGuid().ToString(), c.Meaning));
// TODO: do something with the result
await dev.BuildUnderstanding(file.Content); await dev.BuildUnderstanding(file.Content);
} }
} }

View File

@ -41,9 +41,16 @@ public interface IChatHistory
public interface IUnderstand public interface IUnderstand
{ {
Task<string> BuildUnderstanding(string content); Task<UnderstandingResult> BuildUnderstanding(string content);
} }
[GenerateSerializer]
public class UnderstandingResult {
[Id(0)]
public string NewUnderstanding { get; set; }
[Id(1)]
public string Explanation { get; set; }
}
[Serializable] [Serializable]
public class ChatHistoryItem public class ChatHistoryItem