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
- Interact with unlimited chatbots using different models
- Image Generation
- Generate images with different sizes
- Programatically and GUI
- Use images within the live Pharo environment
- Export images as PNGs
- Generate images with different sizes
- Bonus!
- Automatically update Pharo class comments with a generated Class Responsibility Collaborator (based on class definitions and source code)
- Go to https://platform.openai.com/account/api-keys to set up an API key.
- In a Pharo 11 Playground, Do it:
Metacello new
repository: 'github://brackendev/OpenAI-Pharo/src';
baseline: 'OpenAI';
load.
(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.
- Class classResponsibilityCollaboratorWithSDK - Generate a Class Responsibility Collaborator for a class (based on class definitions and source code).
- Class definitionAndSourceCode - Retrieve the definition and source code for a class.
- Class updateCommentWithOpenAICRCWithSDK - Update a class comment with a generated Class Responsibility Collaborator.
- ImageMorph outputPNGFile - Export an ImageMorph to a PNG file. OpenAIImageGUI uses this to export images.
- String imageFromURL - Retrieve an image from a URL. OpenAIImageGUI uses this to retrieve images.
- String outputTextFile - Export a string to a text file. OpenAIChatGUI uses this to export chats.
- More testing for errors, token limits, etc.
- Add more documentation and examples
This project makes use of the following third-party libraries and utilities:
- NeoJSON
- Zinc HTTP Components (Now included with Pharo 11)
Bracken Spencer
OpenAI-Pharo is released under the MIT license. See the LICENSE file for more info.