Skip to content

Commit e6dee77

Browse files
committed
Add FileUpload APIs
1 parent 18904d0 commit e6dee77

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using ServiceStack;
3+
using ServiceStack.Host;
4+
using Test.ServiceModel;
5+
6+
namespace Test.ServiceInterface;
7+
8+
public class FileUploadServices : Service
9+
{
10+
public object Any(SpeechToText request)
11+
{
12+
if (Request?.Files == null || Request.Files.Length == 0)
13+
{
14+
throw new ArgumentNullException(nameof(request.Audio));
15+
}
16+
17+
var to = new GenerationResponse();
18+
19+
var bytes = request.Audio.ReadFully();
20+
to.TextOutputs =
21+
[
22+
new() { Text = $"{nameof(request.Audio)} {bytes.Length}" },
23+
new() { Text = $"{nameof(request.Tag)} {request.Tag}" },
24+
new() { Text = $"{nameof(request.RefId)} {request.RefId}" },
25+
];
26+
27+
return to;
28+
}
29+
30+
public object Any(TestFileUploads request)
31+
{
32+
if (Request?.Files == null || Request.Files.Length == 0)
33+
{
34+
throw new ArgumentNullException(nameof(Request.Files));
35+
}
36+
37+
var to = new TestFileUploadsResponse
38+
{
39+
Id = request.Id,
40+
RefId = request.RefId,
41+
};
42+
43+
foreach (var file in Request.Files)
44+
{
45+
to.Files.Add(new UploadInfo
46+
{
47+
Name = file.Name,
48+
FileName = file.FileName,
49+
ContentLength = file.ContentLength,
50+
ContentType = file.ContentType,
51+
});
52+
}
53+
54+
return to;
55+
}
56+
}

Test.ServiceModel/FileUploads.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#nullable enable
2+
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using ServiceStack;
6+
using ServiceStack.DataAnnotations;
7+
8+
namespace Test.ServiceModel;
9+
10+
public interface IGeneration
11+
{
12+
string? RefId { get; set; }
13+
string? Tag { get; set; }
14+
}
15+
16+
[Description("Output object for generated artifacts")]
17+
public class ArtifactOutput
18+
{
19+
[ApiMember(Description = "URL to access the generated image")]
20+
[Description("URL to access the generated image")]
21+
public string? Url { get; set; }
22+
23+
[ApiMember(Description = "Filename of the generated image")]
24+
[Description("Filename of the generated image")]
25+
public string? FileName { get; set; }
26+
27+
[ApiMember(Description = "Provider used for image generation")]
28+
[Description("Provider used for image generation")]
29+
public string? Provider { get; set; }
30+
}
31+
32+
[Description("Output object for generated text")]
33+
public class TextOutput
34+
{
35+
[ApiMember(Description = "The generated text")]
36+
[Description("The generated text")]
37+
public string? Text { get; set; }
38+
}
39+
40+
[Description("Response object for generation requests")]
41+
public class GenerationResponse
42+
{
43+
[ApiMember(Description = "List of generated outputs")]
44+
[Description("List of generated outputs")]
45+
public List<ArtifactOutput>? Outputs { get; set; }
46+
47+
[ApiMember(Description = "List of generated text outputs")]
48+
[Description("List of generated text outputs")]
49+
public List<TextOutput>? TextOutputs { get; set; }
50+
51+
[ApiMember(Description = "Detailed response status information")]
52+
[Description("Detailed response status information")]
53+
public ResponseStatus? ResponseStatus { get; set; }
54+
}
55+
56+
[ValidateApiKey]
57+
[Tag("AI")]
58+
[Api("Convert speech to text")]
59+
[Description("Transcribe audio content to text")]
60+
[SystemJson(UseSystemJson.Response)]
61+
public class SpeechToText : IGeneration, IReturn<GenerationResponse>
62+
{
63+
[ApiMember(Description = "The audio stream containing the speech to be transcribed")]
64+
[Description("The audio stream containing the speech to be transcribed")]
65+
[Required]
66+
[Input(Type = "file")]
67+
public Stream Audio { get; set; }
68+
69+
[ApiMember(Description = "Optional client-provided identifier for the request")]
70+
[Description("Optional client-provided identifier for the request")]
71+
public string? RefId { get; set; }
72+
73+
[ApiMember(Description = "Tag to identify the request")]
74+
[Description("Tag to identify the request")]
75+
public string? Tag { get; set; }
76+
}
77+
78+
public class UploadInfo
79+
{
80+
public string Name { get; set; }
81+
public string FileName { get; set; }
82+
public long ContentLength { get; set; }
83+
public string ContentType { get; set; }
84+
}
85+
86+
public class TestFileUploads : IReturn<TestFileUploadsResponse>
87+
{
88+
public int? Id { get; set; }
89+
public string? RefId { get; set; }
90+
}
91+
92+
public class TestFileUploadsResponse
93+
{
94+
public int? Id { get; set; }
95+
public string? RefId { get; set; }
96+
public List<UploadInfo> Files { get; set; } = [];
97+
public ResponseStatus? ResponseStatus { get; set; }
98+
}

0 commit comments

Comments
 (0)