2
2
using System ;
3
3
using LLama . Exceptions ;
4
4
using LLama . Abstractions ;
5
+ using Microsoft . Extensions . Logging ;
5
6
6
7
namespace LLama
7
8
{
@@ -22,9 +23,10 @@ public sealed class LLamaEmbedder
22
23
/// Create a new embedder (loading temporary weights)
23
24
/// </summary>
24
25
/// <param name="allParams"></param>
26
+ /// <param name="logger"></param>
25
27
[ Obsolete ( "Preload LLamaWeights and use the constructor which accepts them" ) ]
26
- public LLamaEmbedder ( ILLamaParams allParams )
27
- : this ( allParams , allParams )
28
+ public LLamaEmbedder ( ILLamaParams allParams , ILogger ? logger = null )
29
+ : this ( allParams , allParams , logger )
28
30
{
29
31
}
30
32
@@ -33,24 +35,26 @@ public LLamaEmbedder(ILLamaParams allParams)
33
35
/// </summary>
34
36
/// <param name="modelParams"></param>
35
37
/// <param name="contextParams"></param>
38
+ /// <param name="logger"></param>
36
39
[ Obsolete ( "Preload LLamaWeights and use the constructor which accepts them" ) ]
37
- public LLamaEmbedder ( IModelParams modelParams , IContextParams contextParams )
40
+ public LLamaEmbedder ( IModelParams modelParams , IContextParams contextParams , ILogger ? logger = null )
38
41
{
39
42
using var weights = LLamaWeights . LoadFromFile ( modelParams ) ;
40
43
41
44
contextParams . EmbeddingMode = true ;
42
- _ctx = weights . CreateContext ( contextParams ) ;
45
+ _ctx = weights . CreateContext ( contextParams , logger ) ;
43
46
}
44
47
45
48
/// <summary>
46
49
/// Create a new embedder, using the given LLamaWeights
47
50
/// </summary>
48
51
/// <param name="weights"></param>
49
52
/// <param name="params"></param>
50
- public LLamaEmbedder ( LLamaWeights weights , IContextParams @params )
53
+ /// <param name="logger"></param>
54
+ public LLamaEmbedder ( LLamaWeights weights , IContextParams @params , ILogger ? logger = null )
51
55
{
52
56
@params . EmbeddingMode = true ;
53
- _ctx = weights . CreateContext ( @params ) ;
57
+ _ctx = weights . CreateContext ( @params , logger ) ;
54
58
}
55
59
56
60
/// <summary>
@@ -89,7 +93,6 @@ public float[] GetEmbeddings(string text)
89
93
/// <exception cref="RuntimeError"></exception>
90
94
public float [ ] GetEmbeddings ( string text , bool addBos )
91
95
{
92
-
93
96
var embed_inp_array = _ctx . Tokenize ( text , addBos ) ;
94
97
95
98
// TODO(Rinne): deal with log of prompt
0 commit comments