Skip to content

Commit

Permalink
feat: ✨ Add CodeDiffType, CodeAssistType, Temperature to command options
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Nov 24, 2024
1 parent 9e15799 commit 6afbef9
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 325 deletions.
42 changes: 42 additions & 0 deletions src/AIAssistant/.aiassistignore
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,45 @@ temp/
aiassist-config.json
.aiassistignore
.gitignore

# Ignore common image file types
*.jpg
*.jpeg
*.png
*.gif
*.bmp
*.tiff
*.tif
*.webp
*.ico
*.svg

# Ignore common video file types
*.mp4
*.mov
*.avi
*.mkv
*.flv
*.wmv
*.webm
*.mpeg
*.mpg
*.m4v
*.3gp
*.3g2

# Ignore common document file types
*.doc
*.docx
*.xls
*.xlsx
*.ppt
*.pptx
*.pdf
*.txt
*.rtf
*.odt
*.ods
*.odp
*.csv
*.tsv
2 changes: 0 additions & 2 deletions src/AIAssistant/AIAssistant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<None Remove="Prompts\Templates\code-block.template"/>
<None Remove="Prompts\Templates\code-assistant-unified-diff.template"/>
<None Remove="Prompts\Templates\code-assistant-code-block-diff.template" />
<None Remove="Prompts\Templates\code-assist-merge-conflict-diff.template" />
<None Remove="Prompts\Templates\code-embedding.template"/>
<None Remove="Prompts\Templates\ask-more-context.template" />
<None Remove="Prompts\Templates\code-assist-search-replace-diff.template" />
Expand All @@ -39,7 +38,6 @@
<ItemGroup>
<EmbeddedResource Include="Prompts\Templates\code-assistant-unified-diff.template" />
<EmbeddedResource Include="Prompts\Templates\code-assistant-code-block-diff.template" />
<EmbeddedResource Include="Prompts\Templates\code-assist-merge-conflict-diff.template" />
<EmbeddedResource Include="Prompts\Templates\code-block.template" />
<EmbeddedResource Include="Prompts\Templates\code-embedding.template" />
<EmbeddedResource Include="Prompts\Templates\ask-more-context.template" />
Expand Down
63 changes: 37 additions & 26 deletions src/AIAssistant/Commands/CodeAssistCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public sealed class Settings : CommandSettings
[Description("[grey] llm model for chatting with ai. for example llama3.1.[/].")]
public string? ChatModel { get; set; }

[CommandOption("-t|--code-assist-type <code-assist-type>")]
[Description("[grey] the type of code assist. it can be `embedding` or `summary`.[/].")]
public CodeAssistType? CodeAssistType { get; set; }

[CommandOption("-e|--embedding-model <embedding-model>")]
[Description("[grey] llm model for embedding purpose. for example mxbai_embed_large.[/].")]
public string? EmbeddingModel { get; set; }
Expand All @@ -59,10 +55,24 @@ public sealed class Settings : CommandSettings

[CommandOption("-d|--diff <diff-type>")]
[Description(
"[grey] the diff tool for showing changes. it can be `unifieddiff`, `codeblockdiff` and `mergeconflictdiff`.[/]."
"[grey] the diff tool for showing changes. it can be `unified-diff`, `code-block-diff` and `search-replace-diff`.[/]."
)]
public CodeDiffType? CodeDiffType { get; set; }

[CommandOption("-t|--code-assist-type <code-assist-type>")]
[Description("[grey] the type of code assist. it can be `embedding` or `summary`.[/].")]
public CodeAssistType? CodeAssistType { get; set; }

[CommandOption("--threshold <threshold")]
[Description("[grey] the threshold is a value for using in the `embedding`.[/].")]
public decimal? Threshold { get; set; }

[CommandOption("--temperature <temperature")]
[Description(
"[grey] the temperature is a value for controlling creativity or randomness on the llm response.[/]."
)]
public decimal? Temperature { get; set; }

[CommandOption("--chat-api-key <key>")]
[Description("[grey] the chat model api key.[/].")]
public string? ChatModelApiKey { get; set; }
Expand Down Expand Up @@ -245,32 +255,33 @@ private void SetupOptions(Settings settings)
if (settings.CodeDiffType is not null)
{
ArgumentException.ThrowIfNullOrEmpty(_llmOptions.ChatModel);
var model = cacheModels.GetModel(_llmOptions.ChatModel);

switch (settings.CodeDiffType)
{
case CodeDiffType.UnifiedDiff:
model.ModelOption.CodeDiffType = CodeDiffType.UnifiedDiff;
break;
case CodeDiffType.CodeBlockDiff:
model.ModelOption.CodeDiffType = CodeDiffType.CodeBlockDiff;
break;
}
var chatModel = cacheModels.GetModel(_llmOptions.ChatModel);
chatModel.ModelOption.CodeDiffType = settings.CodeDiffType.Value;
}

if (settings.CodeAssistType is not null)
{
ArgumentException.ThrowIfNullOrEmpty(_llmOptions.ChatModel);
var model = cacheModels.GetModel(_llmOptions.ChatModel);
switch (settings.CodeAssistType)
{
case CodeAssistType.Embedding:
model.ModelOption.CodeAssistType = CodeAssistType.Embedding;
break;
case CodeAssistType.Summary:
model.ModelOption.CodeAssistType = CodeAssistType.Summary;
break;
}
var chatModel = cacheModels.GetModel(_llmOptions.ChatModel);
chatModel.ModelOption.CodeAssistType = settings.CodeAssistType.Value;
}

if (settings.Threshold is not null)
{
ArgumentException.ThrowIfNullOrEmpty(_llmOptions.EmbeddingsModel);
var embeddingsModel = cacheModels.GetModel(_llmOptions.EmbeddingsModel);
embeddingsModel.ModelOption.Threshold = settings.Threshold.Value;
}

if (settings.Temperature is not null)
{
ArgumentException.ThrowIfNullOrEmpty(_llmOptions.ChatModel);
var chatModel = cacheModels.GetModel(_llmOptions.ChatModel);
chatModel.ModelOption.Temperature = settings.Temperature.Value;

ArgumentException.ThrowIfNullOrEmpty(_llmOptions.EmbeddingsModel);
var embeddingsModel = cacheModels.GetModel(_llmOptions.EmbeddingsModel);
embeddingsModel.ModelOption.Temperature = settings.Temperature.Value;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/AIAssistant/Contracts/IContextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IContextService
Context GetContext();
IList<FileItemContext> GetAllFiles();
IList<FileItemContext> GetFiles(IList<string>? filesRelativePath);
void ValidateLoadedFilesLimit();
void AddContextFolder(string contextFolder);
void AddOrUpdateFolder(IList<string>? foldersRelativePath);
void AddOrUpdateFiles(IList<string>? filesRelativePath);
Expand Down
6 changes: 5 additions & 1 deletion src/AIAssistant/Contracts/ILLMClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public interface ILLMClientManager
string? systemPrompt,
CancellationToken cancellationToken = default
);
Task<GetEmbeddingResult> GetEmbeddingAsync(string input, CancellationToken cancellationToken = default);
Task<GetEmbeddingResult> GetEmbeddingAsync(
string input,
string? path,
CancellationToken cancellationToken = default
);
}
2 changes: 1 addition & 1 deletion src/AIAssistant/Contracts/IPromptManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IPromptManager
void AddPrompt(string embeddedResourceName, CommandType commandType, CodeDiffType? diffType);
string GetPrompt(CommandType commandType, CodeDiffType? diffType, object? parameters);
string AddCodeBlock(string treeSitterCode);
string AddEmbeddingInputString(string treeSitterCode);
string GetEmbeddingInputString(string treeSitterCode);
string CreateLLMContext(IEnumerable<string> codeBlocks);
string FilesAddedToChat(IEnumerable<string> fullFileContents);
string? GetSystemPrompt(IList<string>? codes, CodeAssistType codeAssistType, CodeDiffType diffType);
Expand Down
108 changes: 0 additions & 108 deletions src/AIAssistant/Diff/MergeConflictCodeDiffParser.cs

This file was deleted.

2 changes: 2 additions & 0 deletions src/AIAssistant/Models/Options/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public class AppOptions
public string ContextWorkingDirectory { get; set; } = default!;
public bool AutoContextEnabled { get; set; } = true;
public IList<string> Files { get; set; } = new List<string>();
public int NumberOfFilesLimit { get; set; } = 500;
public int TreeLevel { get; set; }
}
2 changes: 1 addition & 1 deletion src/AIAssistant/Prompts/PromptManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public string AddCodeBlock(string treeSitterCode)
return renderBlock;
}

public string AddEmbeddingInputString(string treeSitterCode)
public string GetEmbeddingInputString(string treeSitterCode)
{
return RenderPromptTemplate(
AIAssistantConstants.Prompts.CodeEmbeddingTemplate,
Expand Down
Loading

0 comments on commit 6afbef9

Please sign in to comment.