How to generate multi-line completions (code generation) with OpenAI?

Hello!

I am toying with OpenAI for code generation purposes. Basically, I want to be able more and more complex code snippets based on natural language queries.

I have started with something simple like generating Entity Framework models for a custom application and this clearly means generating text on multiple lines.

I have started working with OpenAI API (Q & A) and I see that the default Stop sequence is a new line.

How can I generate multiple line code?

Thanks to Adam Rhodes, it was an easy thing to do. I just need to use a separator for each Q & A pair :slight_smile:

A fully working example that uses the API (via OpenAI-API-dotnet) is added below:

string text = 
@"Q: generate a standard model for Foo
A: public class Foo
{
	public int Id { get; set; }
	public DateTime DateCreation { get; set; }
	public DateTime? DateModification { get; set; }
	public int User { get; set; }
	public bool Archive { get; set; }
}	
###
Q: generate a standard model for Bar
A: public class Bar
{
	public int Id { get; set; }
	public DateTime DateCreation { get; set; }
	public DateTime? DateModification { get; set; }
	public int User { get; set; }
	public bool Archive { get; set; }
}
###
Q: generate a standard model for MyNewModel";

var result = await api.Completions.CreateCompletionAsync(
	text, 1024, 0, 1, null, 0, 0,
	null, null, "###");

Console.WriteLine(result);

The output is the following (which is exactly what I want for this simple example):

A: public class MyNewModel
{
    public int Id { get; set; }
    public DateTime DateCreation { get; set; }
    public DateTime? DateModification { get; set; }
    public int User { get; set; }
    public bool Archive { get; set; }
}
1 Like