Skip to content

OpenAI.Request

Andrew Lambert edited this page Jan 22, 2024 · 17 revisions

OpenAI.Request

Class Declaration

 Protected Class Request

Remarks

This class represents an API request. Set the appropriate properties of this class to build your request, then pass it to the factory method that corresponds to the API endpoint you want to make the request of.

Most properties are not valid for all endpoints. Refer to the OpenAI documentation for the endpoint you're interacting with to determine which properties are mandatory, which are optional, and which are invalid. If a Request has invalid properties set then an exception will be raised when it gets rejected by the endpoint.

You may encounter situations where you need to set a request parameter that is either not wrapped by one of this class's properties, or where the property doesn't support the datatype you want to set for the parameter. For example, on some endpoints the Input parameter can optionally be an array of strings instead of just a single string. In such cases you can use the Set() method to manually set the parameter value. Care must be taken when doing this; the parameter name must be exactly right and the parameter datatype must be something that can be serialized by a JSONItem.

Example

This example builds a ChatCompletion request:

  OpenAI.APIKey = "YOUR API KEY"
  Dim request As New OpenAI.Request
  request.Model = "gpt-4"
  Dim chatlog As New OpenAI.ChatCompletionData
  chatlog.AddMessage("user", "What is the airspeed velocity of an unladen European swallow?")
  request.Messages = chatlog
 ' the request is now ready to be sent
  Dim result As OpenAI.Response = OpenAI.ChatCompletion.Create(request)
  Dim answer As String = result.GetResult()

Methods

Properties

Clone this wiki locally