Skip to content

OpenAI.ChatCompletion.GenerateNext

Andrew Lambert edited this page Jul 14, 2024 · 6 revisions

OpenAI.ChatCompletion.GenerateNext

Method signature

Function GenerateNext(Role As String, Content As String, Model As OpenAI.Model = Nil) As OpenAI.ChatCompletion

Parameters

Name Type Comment
Role String One of "user", "assistant", or "system", identifying the speaker of the message.
Content String The message that the speaker is sending to the chat.
Model Model Optional. An AI model to use for the request. If not specified then gpt-3.5-turbo is used.

Return value

A new instance of ChatCompletion containing the AI's reply to the message.

Remarks

Pass the user's next chat message to generate the AI assistant's reply to that message. The AI is provided with a complete transcript of the chat so far to give it the necessary context.

Example

This example demonstrates how to use this method to carry on a chat conversation:

  OpenAI.APIKey = "YOUR API KEY"
  Dim reply As OpenAI.ChatCompletion = OpenAI.ChatCompletion.Create("user", "Hello, I've come here looking for an argument.")
  Dim chatresult As String = reply.GetResult() ' assistant: No you haven't!
  
  reply = reply.GenerateNext("user", "Yes I have!")
  chatresult = reply.GetResult() ' assistant: Sorry, is this the 5 minute argument, or the whole half hour?
  
  reply = reply.GenerateNext("user", "What?")
  chatresult = reply.GetResult() ' assistant: Are you here for the whole half hour?
  
  'etc.
Clone this wiki locally