danielmonettelli / dotnetmaui-chatgpt-app-oss

ChatGPT is an open-source chat application developed with .NET MAUI, employing OpenAI technologies to replicate functionality similar to ChatGPT. The application generates chat responses using these OpenAI technologies.
MIT License
95 stars 22 forks source link

Pass the instruction in the first request #7

Open erossini opened 1 month ago

erossini commented 1 month ago

I'm creating an application with ChatGPT and I saw your project. My project for university is to create a simple English teacher that speaks with the user. To do that, I understood, I have to pass the instruction to ChatGPT like

var request = new CreateAssistantRequest(Model.GPT4o);
Assistant = await ChatGPTClient.AssistantsEndpoint.CreateAssistantAsync(
    new CreateAssistantRequest(
        name: $"English Teacher",
        instructions: $"You are a personal English Teacher. Help me learn English by interacting with me " + 
                      "based on my questions and interests.",
        model: Model.GPT4o));

Looking at your code, I didn't understand if and where I can add these instructions. Can you point me in the right direction?

I really appreciate any help you can provide. Enrico

danielmonettelli commented 1 month ago

Hi @erossini, first of all, thank you for your interest in my project. I've updated the project to Chat Completion, including the current model for both requests and responses. To add instructions for the assistant bot, you'll need to do so in the system role's content, located in OpenAIService.cs. For modifying the tokens, you can adjust them in the Usage class found in CompletionResponse.cs I've included the code where you can change these parameters. Let me know if you encounter any errors so I can improve the code. Thanks!

public async Task<string> AskQuestion(string query)
{
    var completion = new CompletionRequest
    {
        Model = "gpt-4o-mini",
        Messages = new List<MessageRequest>
        {
            new MessageRequest
            {
                Role = "system",
                Content = "You are a helpful assistant."
            },
            new MessageRequest
            {
                Role = "user",
                Content = query
            }
        }
    };

    // ...
}
public class CompletionResponse
{
    public string Id { get; set; }

    public List<Choice> Choices { get; set; }

    public Usage Usage { get; set; }
}

public class Usage
{
    public int Prompt_Tokens { get; set; } = 9;

    public int Completion_Tokens { get; set; } = 12;

    public int Total_Tokens { get; set; } = 21;
}
erossini commented 1 month ago

Thank you so much for your code!