Skip to content

Commit 1e23e96

Browse files
committed
feat: implement application call api
1 parent d3b95b4 commit 1e23e96

21 files changed

+475
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// One reference for application output.
5+
/// </summary>
6+
/// <param name="IndexId">The index id of the doc.</param>
7+
/// <param name="Title">Text slice title.</param>
8+
/// <param name="DocId">Unique id of the doc been referenced.</param>
9+
/// <param name="DocName">Name of the doc been referenced.</param>
10+
/// <param name="Text">Referenced content.</param>
11+
/// <param name="Images">Image URLs beed referenced.</param>
12+
/// <param name="PageNumber">Page numbers of referenced content belongs to.</param>
13+
public record ApplicationDocReference(
14+
string IndexId,
15+
string Title,
16+
string DocId,
17+
string DocName,
18+
string Text,
19+
List<string>? Images,
20+
List<int>? PageNumber);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Inputs for application call.
5+
/// </summary>
6+
public class ApplicationInput
7+
{
8+
/// <summary>
9+
/// The prompt for model to generate response upon. Optional when <see cref="Messages"/> has been set.
10+
/// </summary>
11+
/// <remarks>
12+
/// Prompt will be appended to <see cref="Messages"/> when both set.
13+
/// </remarks>
14+
public string? Prompt { get; set; } = null;
15+
16+
/// <summary>
17+
/// The session id for conversation history. This will be ignored if <see cref="Messages"/> has been set.
18+
/// </summary>
19+
public string? SessionId { get; set; } = null;
20+
21+
/// <summary>
22+
/// The conversation history.
23+
/// </summary>
24+
public IEnumerable<ApplicationMessage>? Messages { get; set; } = null;
25+
26+
/// <summary>
27+
/// The id of memory when enabled.
28+
/// </summary>
29+
public string? MemoryId { get; set; } = null;
30+
31+
/// <summary>
32+
/// List of image urls for inputs.
33+
/// </summary>
34+
public IEnumerable<string>? ImageList { get; set; }
35+
}
36+
37+
/// <summary>
38+
/// Inputs for application call.
39+
/// </summary>
40+
/// <typeparam name="TBizContent">User defined custom content.</typeparam>
41+
public class ApplicationInput<TBizContent> : ApplicationInput
42+
where TBizContent : class
43+
{
44+
/// <summary>
45+
/// User defined content.
46+
/// </summary>
47+
public TBizContent? Content { get; set; } = null;
48+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// A single message for application call.
5+
/// </summary>
6+
/// <param name="Role">The role of this message belongs to.</param>
7+
/// <param name="Content">The content of the message.</param>
8+
public record ApplicationMessage(string Role, string Content)
9+
{
10+
/// <summary>
11+
/// Creates a user message.
12+
/// </summary>
13+
/// <param name="content">Content of the message.</param>
14+
/// <returns></returns>
15+
public static ApplicationMessage User(string content) => new("user", content);
16+
17+
/// <summary>
18+
/// Creates a system message.
19+
/// </summary>
20+
/// <param name="content">Content of the message.</param>
21+
/// <returns></returns>
22+
public static ApplicationMessage System(string content) => new("system", content);
23+
24+
/// <summary>
25+
/// Creates a assistant message.
26+
/// </summary>
27+
/// <param name="content">Content of the message.</param>
28+
/// <returns></returns>
29+
public static ApplicationMessage Assistant(string content) => new("assistant", content);
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Token usages for one model.
5+
/// </summary>
6+
/// <param name="ModelId">The id of the model.</param>
7+
/// <param name="InputTokens">Total input tokens of this model.</param>
8+
/// <param name="OutputTokens">Total output tokens from this model.</param>
9+
public record ApplicationModelUsage(string ModelId, int InputTokens, int OutputTokens);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// The output of application call.
5+
/// </summary>
6+
/// <param name="Text">Output text from application.</param>
7+
/// <param name="FinishReason">Finish reason from application.</param>
8+
/// <param name="SessionId">Unique id of current session.</param>
9+
/// <param name="Thoughts">Thoughts from application.</param>
10+
/// <param name="DocReferences">Doc references from application output.</param>
11+
public record ApplicationOutput(
12+
string Text,
13+
string FinishReason,
14+
string SessionId,
15+
List<ApplicationOutputThought>? Thoughts,
16+
List<ApplicationDocReference>? DocReferences);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// The model thought output.
5+
/// </summary>
6+
/// <param name="Thought">The thought content of the model.</param>
7+
/// <param name="ActionType">Type of the action. e.g. <c>agentRag</c>, <c>reasoning</c>.</param>
8+
/// <param name="ActionName">The name of the action.</param>
9+
/// <param name="Action">The action been executed.</param>
10+
/// <param name="ActionInputStream">The streaming result of action input.</param>
11+
/// <param name="ActionInput">The input of the action.</param>
12+
/// <param name="Observation">Lookup or plugin output.</param>
13+
/// <param name="ReasoningContent">Reasoning output when using DeepSeek-R1.</param>
14+
/// <param name="Arguments">Arguments of the action.</param>
15+
public record ApplicationOutputThought(
16+
string? Thought,
17+
string? ActionType,
18+
string? ActionName,
19+
string? Action,
20+
string? ActionInputStream,
21+
string? ActionInput,
22+
string? Observation,
23+
string? ReasoningContent,
24+
string? Arguments);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Parameters for application call.
5+
/// </summary>
6+
public class ApplicationParameters : IIncrementalOutputParameter, ISeedParameter, IProbabilityParameter
7+
{
8+
/// <inheritdoc />
9+
public bool? IncrementalOutput { get; set; }
10+
11+
/// <summary>
12+
/// Output format for flow application. Can be <c>full_thoughts</c> or <c>agent_format</c>. Defaults to <c>full_thoughts</c>.
13+
/// </summary>
14+
public string? FlowStreamMode { get; set; }
15+
16+
/// <summary>
17+
/// Options for RAG applications.
18+
/// </summary>
19+
public ApplicationRagOptions? RagOptions { get; set; }
20+
21+
/// <inheritdoc />
22+
public ulong? Seed { get; set; }
23+
24+
/// <inheritdoc />
25+
public float? TopP { get; set; }
26+
27+
/// <inheritdoc />
28+
public int? TopK { get; set; }
29+
30+
/// <inheritdoc />
31+
public float? Temperature { get; set; }
32+
33+
/// <summary>
34+
/// Controls whether output contains think block.
35+
/// </summary>
36+
public bool? HasThoughts { get; set; }
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Text.Json;
2+
3+
namespace Cnblogs.DashScope.Core;
4+
5+
/// <summary>
6+
/// Options for RAG application.
7+
/// </summary>
8+
public class ApplicationRagOptions
9+
{
10+
/// <summary>
11+
/// The pipelines to search from.
12+
/// </summary>
13+
public IEnumerable<string>? PipelineIds { get; set; }
14+
15+
/// <summary>
16+
/// The ids of file to reference from.
17+
/// </summary>
18+
public IEnumerable<string>? FileIds { get; set; }
19+
20+
/// <summary>
21+
/// Metadata filter for non-structured files.
22+
/// </summary>
23+
public JsonElement? MetadataFilter { get; set; }
24+
25+
/// <summary>
26+
/// Tag filter for non-structured files.
27+
/// </summary>
28+
public IEnumerable<string>? Tags { get; set; }
29+
30+
/// <summary>
31+
/// Filter for structured files.
32+
/// </summary>
33+
public JsonElement? StructuredFilter { get; set; }
34+
35+
/// <summary>
36+
/// File ids for current session.
37+
/// </summary>
38+
public IEnumerable<string>? SessionFileIds { get; set; }
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Request body for an application all.
5+
/// </summary>
6+
public class ApplicationRequest
7+
{
8+
/// <summary>
9+
/// Content of this call.
10+
/// </summary>
11+
public required ApplicationInput Input { get; init; }
12+
13+
/// <summary>
14+
/// Optional configurations.
15+
/// </summary>
16+
public required ApplicationParameters? Parameters { get; init; }
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Cnblogs.DashScope.Core;
2+
3+
/// <summary>
4+
/// Response of application call.
5+
/// </summary>
6+
/// <param name="RequestId">Unique id of this request.</param>
7+
/// <param name="Code">Error code. Null when request is successful.</param>
8+
/// <param name="Message">Error message. Null when request is successful.</param>
9+
/// <param name="Output">The output of application call.</param>
10+
/// <param name="Usage">Token usage of this application call.</param>
11+
public record ApplicationResponse(
12+
string RequestId,
13+
string? Code,
14+
string? Message,
15+
ApplicationOutput Output,
16+
ApplicationUsage Usage);

0 commit comments

Comments
 (0)