using PolyglotKernel= Microsoft.DotNet.Interactive.Kernel;// 引入交互式的内核命名空间,以便用户输入 var aiProviderCode = await PolyglotKernel.GetInputAsync("请输入AI服务提供商编码:");
var kernel = GetKernel(aiProviderCode); var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();
using Microsoft.SemanticKernel.Agents; using PolyglotKernel = Microsoft.DotNet.Interactive.Kernel;// 引入交互式的内核命名空间,以便用户输入
ChatCompletionAgent agent = new() { Name = "QA-Agent", Instructions = "Ask me anything!", Kernel = kernel };
ChatHistory chat = [];
// Add a user request to the chat history var userRequest = await PolyglotKernel.GetInputAsync("请输入您的问题:"); ChatMessageContent message = new(AuthorRole.User, userRequest); chat.Add(message);
awaitforeach (ChatMessageContent message in agent.InvokeAsync(chat)) { chat.Add(message); } chat.Display();
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "messages":[ { "role":"system", "content":"Ask me anything!", "name":"QA-Agent" }, { "role":"user", "content":"what's ai agent?" } ], "model":"gpt-4o" }
#pragmawarning disable SKEXP0001 // 由于该插件还在演进当中,不建议在正式环境中使用,包含了一些警告,我们需要禁用警告 #pragmawarning disable SKEXP0050 using Microsoft.SemanticKernel.Plugins.Core;
using Microsoft.SemanticKernel.Agents; using Microsoft.SemanticKernel.Connectors.OpenAI; using PolyglotKernel = Microsoft.DotNet.Interactive.Kernel;// 引入交互式的内核命名空间,以便用户输入
ChatCompletionAgent agent = new() { Name = "Math-Agent", Instructions = "You can answer math question!", Kernel = kernel, Arguments = new KernelArguments( new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() } ) // 配置自动调用插件 };
// 导入插件 var plugin = KernelPluginFactory.CreateFromType<MathPlugin>(); agent.Kernel.Plugins.Add(plugin);
ChatHistory chat = [];
// Add a user request to the chat history var userRequest = await PolyglotKernel.GetInputAsync("请输入您的问题:"); ChatMessageContent message = new(AuthorRole.User, userRequest); chat.Add(message);
awaitforeach (ChatMessageContent message in agent.InvokeAsync(chat)) { chat.Add(message); } chat.Display();
using Microsoft.SemanticKernel.Agents; using Microsoft.SemanticKernel.Connectors.OpenAI; using PolyglotKernel = Microsoft.DotNet.Interactive.Kernel;// 引入交互式的内核命名空间,以便用户输入
ChatCompletionAgent agent = new ( templateConfig: templateConfig, templateFactory : new KernelPromptTemplateFactory()) { Name = "Translate-Agent", Kernel = kernel, Arguments = new KernelArguments(){ { "language", "Chinese" } } };
ChatHistory chat = [];
// Add a user request to the chat history var userRequest = await PolyglotKernel.GetInputAsync("请输入您的问题:"); ChatMessageContent message = new(AuthorRole.User, userRequest); chat.Add(message);
awaitforeach (ChatMessageContent message in agent.InvokeAsync(chat)) { chat.Add(message); } chat.Display();
using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Agents; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; using PolyglotKernel = Microsoft.DotNet.Interactive.Kernel;// 引入交互式的内核命名空间,以便用户输入
ChatCompletionAgent agent = new() { Name = "QA-Agent", Instructions = "Ask me anything!", Kernel = kernel, HistoryReducer = new ChatHistoryTruncationReducer(3) };
ChatHistory chat = [];
// Add a user request to the chat history while(true) { var userRequest = await PolyglotKernel.GetInputAsync("请输入您的问题:"); ChatMessageContent userMessage = new(AuthorRole.User, userRequest); chat.Add(userMessage); Console.WriteLine("User: " + userRequest);
User: what's AI?
Agent: Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think and learn like humans. These systems can perform tasks that typically require human intelligence, such as visual perception, speech recognition, decision-making, language translation, and more. AI technologies utilize algorithms and models to process large datasets and improve their performance over time through techniques like machine learning and deep learning. The ultimate goal of AI is to develop systems that can function autonomously and adaptively in complex environments.
User: What's semantci kernel?
Agent: A semantic kernel typically refers to a computational framework or model that focuses on capturing and utilizing semantic meaning from data, particularly in the context of machine learning and natural language processing. The term can have slightly different meanings depending on the context, but here are some general interpretations:
1. **Kernel Methods in Machine Learning**: In the field of machine learning, particularly in support vector machines (SVMs), a "semantic kernel" could refer to a kernel function designed to capture the semantic relationships in the data. Kernel functions transform data into a higher-dimensional space to make it easier to classify. A semantic kernel would aim to maintain the semantic similarity between data points in this transformation.
2. **Semantic Kernel as a Model**: In natural language processing, semantic kernels could be employed to understand and process the semantic content of text. This involves mapping text data into a semantic space where the relationships between different words or concepts are preserved. Techniques like Latent Semantic Analysis (LSA) or using embeddings like Word2Vec or BERT might be involved in creating these semantic representations.
3. **Kernel Functions for Specific Tasks**: In some contexts, semantic kernels are crafted for specific tasks such as text classification, information retrieval, or semantic similarity measurement, where the goal is to improve the performance of algorithms by incorporating semantic understanding.
Overall, the concept centers on enhancing traditional computational methods by integrating semantic understanding, enabling systems to process and understand data at a more meaningful level.
User: What's autogen?
Agent: "Autogen" can refer to different concepts depending on the context in which it is used. Here are some possible interpretations:
1. **Auto-Generated Code**: In software development, "autogen" can refer to automatically generated code. Tools or scripts might autogenerate parts of the code to simplify repetitive tasks, ensure consistency, or conform to certain standards. This is common in scenarios like API client libraries, where the code is generated based on a specification (e.g., OpenAPI).
2. **Autogen in AI/ML**: In the context of artificial intelligence and machine learning, "autogen" could be shorthand for automatically generating outputs, such as generating text, images, or other types of data. For example, text autogeneration could involve using AI models like GPT to create human-like text.
3. **Trademark or Company Name**: "Autogen" may also be a trademark, product, or company name in various industries. A company or service named Autogen might focus on automatic generation processes in a specific field, such as energy systems, data processing, or other technical areas.
4. **General Use in Technology**: In general technology parlance, "autogen" usually implies some form of automation, where a system generates something without manual intervention, often to enhance efficiency or accuracy.
If you have a specific domain or context in mind, please provide more details for a more precise explanation.