charonn0 / Xojo-OpenAI

A Xojo API for interacting with OpenAI
MIT License
16 stars 6 forks source link

Add support for new beta endpoints #3

Closed byt3magic closed 1 year ago

byt3magic commented 1 year ago

https://platform.openai.com/docs/guides/chat

Would be great to have that here :-)

charonn0 commented 1 year ago

Chat's not the only new endpoint. They also added audio transcription and translation 🥇

charonn0 commented 1 year ago

The audio transcription and translation, and chat completion endpoints are now usable.

Examples:

  OpenAI.APIKey = "YOUR KEY HERE"
  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.
  OpenAI.APIKey = "YOUR KEY HERE"
  Dim file As FolderItem = SpecialFolder.Desktop.Child("speech.mp3")
  Dim reply As OpenAI.Response = OpenAI.AudioTranscription.Create(file)
  Dim transcript As String = reply.GetResult()