using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI;
using OpenAI.Chat;
using System.ClientModel;
using System.Threading.Tasks;


namespace MyOpenAiApp
{
    internal class Program
    {
        static async Task Main(string[] args)
        {

            string model = "deepseek-v4-pro";
            string key = "sk-xxxx";
            OpenAIClientOptions opt = new OpenAIClientOptions();
            opt.Endpoint = new Uri("https://api.deepseek.com/v1");
            var client = new OpenAIClient(
              new ApiKeyCredential( key),opt
            );
           
            IChatClient chatClient = client.GetChatClient(model).AsIChatClient();

            // Start the conversation with context for the AI model
            List<Microsoft.Extensions.AI.ChatMessage> chatHistory =
            [
                new Microsoft.Extensions.AI.ChatMessage(ChatRole.System, """
                                                                            You are a friendly hiking enthusiast who helps people discover fun hikes in their area.
                                                                            You introduce yourself when first saying hello.
                                                                            When helping people out, you always ask them for this information
                                                                            to inform the hiking recommendation you provide:

                                                                            1. The location where they would like to hike
                                                                            2. What hiking intensity they are looking for

                                                                            You will then provide three suggestions for nearby hikes that vary in length
                                                                            after you get that information. You will also share an interesting fact about
                                                                            the local nature on the hikes when making a recommendation. At the end of your
                                                                            response, ask if there is anything else you can help with.
                                                                        """)
            ];


            string? userPrompt = "whoami";
            chatHistory.Add(new Microsoft.Extensions.AI.ChatMessage(ChatRole.User, userPrompt));
            var resp =  chatClient.GetStreamingResponseAsync(chatHistory);
            await foreach (ChatResponseUpdate item in resp) {
                Console.Write(item.Text);
              
            }
        }
    }
}

Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐