Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net handlebars限制没有输出预期结果 #6332

Open
TaoPeiLing opened this issue May 19, 2024 · 0 comments
Open

.Net handlebars限制没有输出预期结果 #6332

TaoPeiLing opened this issue May 19, 2024 · 0 comments
Labels
.NET Issue or Pull requests regarding .NET code triage

Comments

@TaoPeiLing
Copy link

TaoPeiLing commented May 19, 2024

您好。我在使用handlebars构建提示词时,尝试使用Instructions: 你会拒绝任何的回答,只回复:不知道。来限制模型的输出,但是,遗憾的时,模型还是给我其他的响应了。
我的代码如下:
public async Task RunHandlebar3Async()
{
// Create a Semantic Kernel template for chat
//var chat = kernel.CreateFunctionFromPrompt(
// @"{{$history}}
//User: {{$request}}
//Assistant: ");
var getIntent = kernel.CreateFunctionFromPrompt(
new()
{
Template = """"
Template = """
Instructions: 你会拒绝任何的回答,只回复:不知道。
{{request}}
Intent:
""",
"""",
TemplateFormat = "handlebars"
},
new HandlebarsPromptTemplateFactory()
);

        ChatHistory history = new ChatHistory();

        // Start the chat loop
        while (true)
        {
            // Get user input
            Console.Write("User > ");
            var request = Console.ReadLine();

            // Invoke prompt
            var intent = await kernel.InvokeAsync(
                getIntent,
                new()
                {
                    { "request", request }
                }
            );

            // Get chat response
            var chatResult = kernel.InvokeStreamingAsync<StreamingChatMessageContent>(
                getIntent,
                new()
                {
                { "request", request },
                { "history", string.Join("\n", history.Select(x => x.Role + ": " + x.Content)) }
                }
            );

            // Stream the response
            string message = "";
            bool isRolePrinted = false;
            await foreach (var chunk in chatResult)
            {
                if (!isRolePrinted&&chunk.Role.HasValue)
                {
                    Console.Write(chunk.Role + " > ");
                    isRolePrinted = true;
                }

                message += chunk;
                Console.Write(chunk);
            }
            Console.WriteLine();

            // Append to history
            history.AddUserMessage(request!);
            history.AddAssistantMessage(message);
        }
    }。

模型回复内容:
image
我使用的是GLM-4
我不知道是否是我在理解上有误差。期待您们的回复。

@moonbox3 moonbox3 changed the title handlebars限制没有输出预期结果 .Net handlebars限制没有输出预期结果 May 21, 2024
@moonbox3 moonbox3 added the .NET Issue or Pull requests regarding .NET code label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code triage
Projects
None yet
Development

No branches or pull requests

3 participants