...
This commit is contained in:
@@ -7,6 +7,7 @@ package aia;
|
||||
|
||||
service aiAssistance {
|
||||
rpc SendQuestion (aiaRequest) returns (aiaReply);
|
||||
rpc imageAnalize (aiaRequest) returns (aiaReply);
|
||||
}
|
||||
|
||||
message aiaRequest {
|
||||
|
@@ -27,9 +27,10 @@ namespace AIAss.Protos {
|
||||
"CglhaWEucHJvdG8SA2FpYSJdCgphaWFSZXF1ZXN0EhAKCHF1ZXN0aW9uGAEg",
|
||||
"ASgJEg8KB3Byb21wdHMYAiABKAkSDQoFbW9kZWwYAyABKAkSEAoIYXBpdG9r",
|
||||
"ZW4YBCABKAkSCwoDdXJsGAUgASgJIhsKCGFpYVJlcGx5Eg8KB21lc3NhZ2UY",
|
||||
"ASABKAkyPgoMYWlBc3Npc3RhbmNlEi4KDFNlbmRRdWVzdGlvbhIPLmFpYS5h",
|
||||
"aWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Qg+qAgxBSUFzcy5Qcm90b3NiBnBy",
|
||||
"b3RvMw=="));
|
||||
"ASABKAkybgoMYWlBc3Npc3RhbmNlEi4KDFNlbmRRdWVzdGlvbhIPLmFpYS5h",
|
||||
"aWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Ei4KDGltYWdlQW5hbGl6ZRIPLmFp",
|
||||
"YS5haWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Qg+qAgxBSUFzcy5Qcm90b3Ni",
|
||||
"BnByb3RvMw=="));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
|
@@ -58,6 +58,14 @@ namespace AIAss.Protos {
|
||||
__Marshaller_aia_aiaRequest,
|
||||
__Marshaller_aia_aiaReply);
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
static readonly grpc::Method<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply> __Method_imageAnalize = new grpc::Method<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(
|
||||
grpc::MethodType.Unary,
|
||||
__ServiceName,
|
||||
"imageAnalize",
|
||||
__Marshaller_aia_aiaRequest,
|
||||
__Marshaller_aia_aiaReply);
|
||||
|
||||
/// <summary>Service descriptor</summary>
|
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
|
||||
{
|
||||
@@ -74,6 +82,12 @@ namespace AIAss.Protos {
|
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
|
||||
}
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::System.Threading.Tasks.Task<global::AIAss.Protos.aiaReply> imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::ServerCallContext context)
|
||||
{
|
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>Client for aiAssistance</summary>
|
||||
@@ -123,6 +137,26 @@ namespace AIAss.Protos {
|
||||
{
|
||||
return CallInvoker.AsyncUnaryCall(__Method_SendQuestion, null, options, request);
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::AIAss.Protos.aiaReply imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
|
||||
{
|
||||
return imageAnalize(request, new grpc::CallOptions(headers, deadline, cancellationToken));
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::AIAss.Protos.aiaReply imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::CallOptions options)
|
||||
{
|
||||
return CallInvoker.BlockingUnaryCall(__Method_imageAnalize, null, options, request);
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual grpc::AsyncUnaryCall<global::AIAss.Protos.aiaReply> imageAnalizeAsync(global::AIAss.Protos.aiaRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
|
||||
{
|
||||
return imageAnalizeAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken));
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual grpc::AsyncUnaryCall<global::AIAss.Protos.aiaReply> imageAnalizeAsync(global::AIAss.Protos.aiaRequest request, grpc::CallOptions options)
|
||||
{
|
||||
return CallInvoker.AsyncUnaryCall(__Method_imageAnalize, null, options, request);
|
||||
}
|
||||
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
protected override aiAssistanceClient NewInstance(ClientBaseConfiguration configuration)
|
||||
@@ -137,7 +171,8 @@ namespace AIAss.Protos {
|
||||
public static grpc::ServerServiceDefinition BindService(aiAssistanceBase serviceImpl)
|
||||
{
|
||||
return grpc::ServerServiceDefinition.CreateBuilder()
|
||||
.AddMethod(__Method_SendQuestion, serviceImpl.SendQuestion).Build();
|
||||
.AddMethod(__Method_SendQuestion, serviceImpl.SendQuestion)
|
||||
.AddMethod(__Method_imageAnalize, serviceImpl.imageAnalize).Build();
|
||||
}
|
||||
|
||||
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic.
|
||||
@@ -148,6 +183,7 @@ namespace AIAss.Protos {
|
||||
public static void BindService(grpc::ServiceBinderBase serviceBinder, aiAssistanceBase serviceImpl)
|
||||
{
|
||||
serviceBinder.AddMethod(__Method_SendQuestion, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(serviceImpl.SendQuestion));
|
||||
serviceBinder.AddMethod(__Method_imageAnalize, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(serviceImpl.imageAnalize));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -38,6 +38,50 @@ namespace AIAss.Services;
|
||||
reponse="خطا در ارتباط سرور ai";
|
||||
}
|
||||
|
||||
return new aiaReply
|
||||
{
|
||||
Message = $" {reponse}"
|
||||
};
|
||||
}
|
||||
public async override Task<aiaReply> imageAnalize(aiaRequest request, ServerCallContext context)
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
client.DefaultRequestHeaders.Authorization =
|
||||
new AuthenticationHeaderValue("Bearer", request.Apitoken);
|
||||
var content = new
|
||||
{
|
||||
model = request.Model,
|
||||
messages = new object[]
|
||||
{
|
||||
new {
|
||||
role = "user",
|
||||
content = new object[]
|
||||
{
|
||||
new { type = "text", text =request.Prompts},
|
||||
new {
|
||||
type = "image_url",
|
||||
image_url = new {
|
||||
url = $"data:image/jpeg;base64,{request.Question}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var response = await client.PostAsync(request.Url,
|
||||
new StringContent(JsonSerializer.Serialize(content), Encoding.UTF8, "application/json"));
|
||||
string reponse = "";
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
reponse = doc.RootElement.GetProperty("choices")[0].GetProperty("message").GetProperty("content").GetString();
|
||||
}
|
||||
else
|
||||
{
|
||||
reponse = "خطا در ارتباط سرور ai";
|
||||
}
|
||||
|
||||
return new aiaReply
|
||||
{
|
||||
Message = $" {reponse}"
|
||||
|
@@ -27,9 +27,10 @@ namespace AIAss.Protos {
|
||||
"CglhaWEucHJvdG8SA2FpYSJdCgphaWFSZXF1ZXN0EhAKCHF1ZXN0aW9uGAEg",
|
||||
"ASgJEg8KB3Byb21wdHMYAiABKAkSDQoFbW9kZWwYAyABKAkSEAoIYXBpdG9r",
|
||||
"ZW4YBCABKAkSCwoDdXJsGAUgASgJIhsKCGFpYVJlcGx5Eg8KB21lc3NhZ2UY",
|
||||
"ASABKAkyPgoMYWlBc3Npc3RhbmNlEi4KDFNlbmRRdWVzdGlvbhIPLmFpYS5h",
|
||||
"aWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Qg+qAgxBSUFzcy5Qcm90b3NiBnBy",
|
||||
"b3RvMw=="));
|
||||
"ASABKAkybgoMYWlBc3Npc3RhbmNlEi4KDFNlbmRRdWVzdGlvbhIPLmFpYS5h",
|
||||
"aWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Ei4KDGltYWdlQW5hbGl6ZRIPLmFp",
|
||||
"YS5haWFSZXF1ZXN0Gg0uYWlhLmFpYVJlcGx5Qg+qAgxBSUFzcy5Qcm90b3Ni",
|
||||
"BnByb3RvMw=="));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
|
@@ -58,6 +58,14 @@ namespace AIAss.Protos {
|
||||
__Marshaller_aia_aiaRequest,
|
||||
__Marshaller_aia_aiaReply);
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
static readonly grpc::Method<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply> __Method_imageAnalize = new grpc::Method<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(
|
||||
grpc::MethodType.Unary,
|
||||
__ServiceName,
|
||||
"imageAnalize",
|
||||
__Marshaller_aia_aiaRequest,
|
||||
__Marshaller_aia_aiaReply);
|
||||
|
||||
/// <summary>Service descriptor</summary>
|
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
|
||||
{
|
||||
@@ -74,6 +82,12 @@ namespace AIAss.Protos {
|
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
|
||||
}
|
||||
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::System.Threading.Tasks.Task<global::AIAss.Protos.aiaReply> imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::ServerCallContext context)
|
||||
{
|
||||
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>Client for aiAssistance</summary>
|
||||
@@ -123,6 +137,26 @@ namespace AIAss.Protos {
|
||||
{
|
||||
return CallInvoker.AsyncUnaryCall(__Method_SendQuestion, null, options, request);
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::AIAss.Protos.aiaReply imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
|
||||
{
|
||||
return imageAnalize(request, new grpc::CallOptions(headers, deadline, cancellationToken));
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual global::AIAss.Protos.aiaReply imageAnalize(global::AIAss.Protos.aiaRequest request, grpc::CallOptions options)
|
||||
{
|
||||
return CallInvoker.BlockingUnaryCall(__Method_imageAnalize, null, options, request);
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual grpc::AsyncUnaryCall<global::AIAss.Protos.aiaReply> imageAnalizeAsync(global::AIAss.Protos.aiaRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
|
||||
{
|
||||
return imageAnalizeAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken));
|
||||
}
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
public virtual grpc::AsyncUnaryCall<global::AIAss.Protos.aiaReply> imageAnalizeAsync(global::AIAss.Protos.aiaRequest request, grpc::CallOptions options)
|
||||
{
|
||||
return CallInvoker.AsyncUnaryCall(__Method_imageAnalize, null, options, request);
|
||||
}
|
||||
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
|
||||
protected override aiAssistanceClient NewInstance(ClientBaseConfiguration configuration)
|
||||
@@ -137,7 +171,8 @@ namespace AIAss.Protos {
|
||||
public static grpc::ServerServiceDefinition BindService(aiAssistanceBase serviceImpl)
|
||||
{
|
||||
return grpc::ServerServiceDefinition.CreateBuilder()
|
||||
.AddMethod(__Method_SendQuestion, serviceImpl.SendQuestion).Build();
|
||||
.AddMethod(__Method_SendQuestion, serviceImpl.SendQuestion)
|
||||
.AddMethod(__Method_imageAnalize, serviceImpl.imageAnalize).Build();
|
||||
}
|
||||
|
||||
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic.
|
||||
@@ -148,6 +183,7 @@ namespace AIAss.Protos {
|
||||
public static void BindService(grpc::ServiceBinderBase serviceBinder, aiAssistanceBase serviceImpl)
|
||||
{
|
||||
serviceBinder.AddMethod(__Method_SendQuestion, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(serviceImpl.SendQuestion));
|
||||
serviceBinder.AddMethod(__Method_imageAnalize, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::AIAss.Protos.aiaRequest, global::AIAss.Protos.aiaReply>(serviceImpl.imageAnalize));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user