feat: 初始化NewLife Studio项目,完成基础框架与数据管理模块
何炳宏
authored at
2026-05-26 12:09:09
NewLife.Studio
using System.Text.Json.Serialization;
namespace NewLife.Studio.AI.Models;
public class ChatMessage
{
[JsonPropertyName("role")]
public string Role { get; set; } = "";
[JsonPropertyName("content")]
public string? Content { get; set; }
[JsonPropertyName("tool_calls")]
public List<ToolCall>? ToolCalls { get; set; }
[JsonPropertyName("tool_call_id")]
public string? ToolCallId { get; set; }
}
public class ChatRequest
{
[JsonPropertyName("model")]
public string Model { get; set; } = "gpt-4o";
[JsonPropertyName("messages")]
public List<ChatMessage> Messages { get; set; } = [];
[JsonPropertyName("tools")]
public List<ToolDefinition>? Tools { get; set; }
[JsonPropertyName("max_tokens")]
public int MaxTokens { get; set; } = 4096;
[JsonPropertyName("temperature")]
public double Temperature { get; set; } = 0.1;
}
public class ChatResponse
{
[JsonPropertyName("choices")]
public List<ChatChoice> Choices { get; set; } = [];
[JsonPropertyName("usage")]
public ChatUsage? Usage { get; set; }
}
public class ChatChoice
{
[JsonPropertyName("message")]
public ChatMessage Message { get; set; } = new();
[JsonPropertyName("finish_reason")]
public string? FinishReason { get; set; }
}
public class ChatUsage
{
[JsonPropertyName("prompt_tokens")]
public int PromptTokens { get; set; }
[JsonPropertyName("completion_tokens")]
public int CompletionTokens { get; set; }
}
public class ToolCall
{
[JsonPropertyName("id")]
public string Id { get; set; } = "";
[JsonPropertyName("type")]
public string Type { get; set; } = "function";
[JsonPropertyName("function")]
public FunctionCall Function { get; set; } = new();
}
public class FunctionCall
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("arguments")]
public string Arguments { get; set; } = "";
}
public class ToolDefinition
{
[JsonPropertyName("type")]
public string Type { get; set; } = "function";
[JsonPropertyName("function")]
public FunctionDef Function { get; set; } = new();
}
public class FunctionDef
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("description")]
public string Description { get; set; } = "";
[JsonPropertyName("parameters")]
public object? Parameters { get; set; }
}
public class ToolResult
{
public string ToolCallId { get; set; } = "";
public string? Output { get; set; }
public string? Error { get; set; }
}
|