|
| 1 | +using System; |
| 2 | +using Grpc.Net.ClientFactory; |
| 3 | +using Microsoft.Extensions.DependencyInjection; |
| 4 | + |
| 5 | +namespace Devlooped.Grok; |
| 6 | + |
| 7 | +public static class GrokServiceCollectionExtensions |
| 8 | +{ |
| 9 | + public static IServiceCollection AddGrokClient(this IServiceCollection services, Action<GrpcClientFactoryOptions>? configure = null) |
| 10 | + { |
| 11 | + var address = new Uri("https://api.x.ai:443"); |
| 12 | + |
| 13 | + services.AddGrpcClient<Auth.AuthClient>(options => |
| 14 | + { |
| 15 | + options.Address = address; |
| 16 | + configure?.Invoke(options); |
| 17 | + }); |
| 18 | + |
| 19 | + services.AddGrpcClient<Chat.ChatClient>(options => |
| 20 | + { |
| 21 | + options.Address = address; |
| 22 | + configure?.Invoke(options); |
| 23 | + }); |
| 24 | + |
| 25 | + services.AddGrpcClient<Embedder.EmbedderClient>(options => |
| 26 | + { |
| 27 | + options.Address = address; |
| 28 | + configure?.Invoke(options); |
| 29 | + }); |
| 30 | + |
| 31 | + services.AddGrpcClient<Image.ImageClient>(options => |
| 32 | + { |
| 33 | + options.Address = address; |
| 34 | + configure?.Invoke(options); |
| 35 | + }); |
| 36 | + |
| 37 | + services.AddGrpcClient<Models.ModelsClient>(options => |
| 38 | + { |
| 39 | + options.Address = address; |
| 40 | + configure?.Invoke(options); |
| 41 | + }); |
| 42 | + |
| 43 | + services.AddGrpcClient<Sample.SampleClient>(options => |
| 44 | + { |
| 45 | + options.Address = address; |
| 46 | + configure?.Invoke(options); |
| 47 | + }); |
| 48 | + |
| 49 | + services.AddGrpcClient<Tokenize.TokenizeClient>(options => |
| 50 | + { |
| 51 | + options.Address = address; |
| 52 | + configure?.Invoke(options); |
| 53 | + }); |
| 54 | + |
| 55 | + services.AddGrpcClient<Documents.DocumentsClient>(options => |
| 56 | + { |
| 57 | + options.Address = address; |
| 58 | + configure?.Invoke(options); |
| 59 | + }); |
| 60 | + |
| 61 | + return services; |
| 62 | + } |
| 63 | +} |
0 commit comments