-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Use Batch Api for embeddings (#14)
- Loading branch information
1 parent
6afbef9
commit 2cf05f6
Showing
22 changed files
with
319 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace AIAssistant.Dtos; | ||
|
||
public class GetBatchEmbeddingResult(IList<IList<double>> embeddings, int totalTokensCount, decimal totalCost) | ||
{ | ||
public IList<IList<double>> Embeddings { get; } = embeddings; | ||
public int TotalTokensCount { get; } = totalTokensCount; | ||
public decimal TotalCost { get; } = totalCost; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
namespace AIAssistant.Dtos; | ||
|
||
public record GetEmbeddingResult(IList<double> Embeddings, int TotalTokensCount, decimal TotalCost); | ||
public record GetEmbeddingResult( | ||
IList<IList<double>> Embeddings, // Multiple embeddings for batch | ||
int TotalTokensCount, | ||
decimal TotalCost | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace AIAssistant.Models; | ||
|
||
/// <summary> | ||
/// Represents a batch of files and their chunks to be processed in a single embedding request. | ||
/// </summary> | ||
public class FileBatch | ||
{ | ||
public IList<FileChunkGroup> Files { get; set; } = new List<FileChunkGroup>(); | ||
public int TotalTokens { get; set; } | ||
|
||
/// <summary> | ||
/// Combines all chunked inputs for this batch into a single list for API calls. | ||
/// </summary> | ||
public IList<string> GetBatchInputs() | ||
{ | ||
return Files.SelectMany(file => file.Chunks).ToList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using TreeSitter.Bindings.CustomTypes.TreeParser; | ||
|
||
namespace AIAssistant.Models; | ||
|
||
/// <summary> | ||
/// Represents a file and its associated chunks for embedding. | ||
/// </summary> | ||
public class FileChunkGroup(CodeFileMap file, List<string> chunks) | ||
{ | ||
public CodeFileMap File { get; } = file; | ||
public IList<string> Chunks { get; } = chunks; | ||
|
||
public string Input => string.Join("\n", Chunks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.