varapiKey=Environment.GetEnvironmentVariable("EDENAI_API_KEY")is{Length:>0}value?value:thrownewAssertInconclusiveException("EDENAI_API_KEY environment variable is not found.");usingvarclient=newEdenAIClient(apiKey);// Create tools for chat, translation, image generation, summarization,// sentiment analysis, and language detection.varchatTool=client.AsChatTool();vartranslateTool=client.AsTranslateTool();vargenerateImageTool=client.AsGenerateImageTool();varsummarizeTool=client.AsSummarizeTool();varsentimentTool=client.AsSentimentAnalysisTool();vardetectLanguageTool=client.AsDetectLanguageTool();// These tools can be passed to any IChatClient that supports function calling.vartools=new[]{chatTool,translateTool,generateImageTool,summarizeTool,sentimentTool,detectLanguageTool};
Chat
Shows how to send a chat message to an AI provider via EdenAI.
1 2 3 4 5 6 7 8 9101112
usingvarclient=newEdenAIClient(apiKey);// Send a chat message through the EdenAI unified API,// specifying one or more providers to route the request to.varresponse=awaitclient.Chat.TextTextChatCreateAsync(request:newTextchatChatRequest{Providers=["openai"],Text="What is the capital of France?",ChatbotGlobalAction="You are a helpful geography assistant.",MaxTokens=100,});
Translation
Shows how to translate text between languages via EdenAI.
1 2 3 4 5 6 7 8 9101112
usingvarclient=newEdenAIClient(apiKey);// Translate text using the EdenAI unified API.// Multiple providers are supported including Google, Amazon, Microsoft, and DeepL.varresponse=awaitclient.AutomaticTranslation.TranslationTranslationAutomaticTranslationCreateAsync(request:newTranslationautomaticTranslationAutomaticTranslationRequest{Providers=["google"],Text="Hello, how are you?",TargetLanguage="fr",});
Image Generation
Shows how to generate images from text descriptions via EdenAI.
1 2 3 4 5 6 7 8 9101112
usingvarclient=newEdenAIClient(apiKey);// Generate images from text descriptions using the EdenAI unified API.// Supported providers include OpenAI (DALL-E), Stability AI, and Amazon.varresponse=awaitclient.Generation.ImageImageGenerationCreateAsync(request:newImagegenerationGenerationRequest{Providers=["openai"],Text="A serene mountain landscape at sunset",Resolution="1024x1024",NumImages=1,});