Skip to content

Commit 05c5bea

Browse files
committed
TextInput, BackendType
1 parent b6ac7f6 commit 05c5bea

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.4.8</Version>
3+
<Version>0.5.1</Version>
44
<Company>TensorStack</Company>
55
<Copyright>TensorStack - 2026</Copyright>
66
<RepositoryUrl>https://github.com/TensorStack-AI/TensorStack</RepositoryUrl>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TensorStack.Common.Common
2+
{
3+
public enum BackendType
4+
{
5+
OnnxRuntime = 0,
6+
Pytorch = 10
7+
}
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.IO;
2+
using System.Text;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace TensorStack.Common
7+
{
8+
public class TextInput
9+
{
10+
private readonly string _sourceFile;
11+
12+
public TextInput(string textInput)
13+
{
14+
Text = textInput;
15+
}
16+
17+
public TextInput(string filename, Encoding encoding)
18+
: this(File.ReadAllText(filename, encoding))
19+
{
20+
_sourceFile = filename;
21+
}
22+
23+
public string Text { get; set; }
24+
25+
public string SourceFile => _sourceFile;
26+
public int Length => Text?.Length ?? 0;
27+
28+
29+
public int Beam { get; set; }
30+
public float Score { get; set; }
31+
public float PenaltyScore { get; set; }
32+
33+
34+
35+
public void Save(string filename)
36+
{
37+
File.WriteAllText(filename, Text);
38+
}
39+
40+
public async Task SaveAsync(string filename)
41+
{
42+
await File.WriteAllTextAsync(filename, Text);
43+
}
44+
45+
public static async Task<TextInput> CreateAsync(string filename, Encoding encoding, CancellationToken cancellationToken = default)
46+
{
47+
return new TextInput(await File.ReadAllTextAsync(filename, encoding, cancellationToken));
48+
}
49+
}
50+
51+
}

0 commit comments

Comments
 (0)