Skip to content

A powerful OpenAI playground for pro-users and developers

License

Notifications You must be signed in to change notification settings

brackendev/OpenAI-Pharo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI-Pharo

A powerful OpenAI playground for pro-users and developers.

  • Chat
    • Interact with unlimited chatbots using different models
      • Programatically and GUI
    • Use responses within the live Pharo environment
      • Inspect and evaluate responses to objects
    • Export chats as JSON
  • Image Generation
    • Generate images with different sizes
      • Programatically and GUI
    • Use images within the live Pharo environment
    • Export images as PNGs
  • Bonus!

Requirements

Installation

  1. Go to https://platform.openai.com/account/api-keys to set up an API key.
  2. In a Pharo 11 Playground, Do it:
Metacello new 
  repository: 'github://brackendev/OpenAI-Pharo/src';
  baseline: 'OpenAI';
  load.

Example Usage

(An examples package is also included.)

"Lists the currently available models"

(OpenAISDK createWithAPIKey: 'API_KEY') listModels.
"Programatically use a chat session"

sdk := OpenAISDK createWithAPIKey: 'API_KEY'.
chatSession := OpenAIChatSession startWithSDK: sdk.
chatSession model: 'gpt-4'. "Optional. Default is gpt-3.5-turbo"
chatSession submitSystemPrompt: 'You are a chatbot named OMM 0000.'.
chatSession submitUserPrompt: 'Who are you?'.
chatSession lastChat inspect. "Inspects the response: I am OMM 0000..."
chatSession submitUserPrompt: 'Show me Pharo code to add numbers to your name. Respond with only Pharo code, no other text, no code block.'.
chatSession lastChat inspect. "Inspects the Pharo code response"
chatSession lastChat evaluate inspect. "Inspects the Pharo code evaluated"
"Programtically generate images"

sdk := OpenAISDK createWithAPIKey: 'API_KEY'.
sdk createImageWithPrompt: 'An elephant drinking water on the moon' number: 2 size: '1024x1024'.
"Open a chat session GUI"

sdk := OpenAISDK createWithAPIKey: 'API_KEY'.
OpenAIChatGUI openWithSDK: sdk.
"Open an image generation GUI"

sdk := OpenAISDK createWithAPIKey: 'API_KEY'.
OpenAIImageGUI openWithSDK: sdk.
"Update any class comment with the generated Class Responsibility Collaborator (based on class definitions and source code)"

sdk := OpenAISDK createWithAPIKey: 'API_KEY'.
AnyClassYouWant updateCommentWithOpenAICRCWithSDK: sdk.

Documentation

Extension Methods

TODO

  • More testing for errors, token limits, etc.
  • Add more documentation and examples

Acknowledgements

This project makes use of the following third-party libraries and utilities:

Author

Bracken Spencer

License

OpenAI-Pharo is released under the MIT license. See the LICENSE file for more info.