├── requirements.txt ├── chatgpt-openai-api-plugin.png ├── training_data.jsonl ├── plugins └── ai-plugin.json ├── LICENSE ├── bot └── prompt.txt ├── main.py └── README.md /requirements.txt: -------------------------------------------------------------------------------- 1 | fastapi 2 | uvicorn 3 | openai 4 | requests 5 | pydantic 6 | -------------------------------------------------------------------------------- /chatgpt-openai-api-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruvnet/chatgpt-openai-api-plugin/HEAD/chatgpt-openai-api-plugin.png -------------------------------------------------------------------------------- /training_data.jsonl: -------------------------------------------------------------------------------- 1 | {"prompt": "Translate the following English text to French: 'Hello, how are you?'\n", "completion": "Bonjour, comment ça va ?"} 2 | {"prompt": "What is the capital of France?\n", "completion": "The capital of France is Paris."} 3 | {"prompt": "Write a short poem about the moon.\n", "completion": "Gentle moon, in the night sky,\nSilent guardian, shining high.\nCasting shadows, soft and deep,\nGuiding all who wake or sleep."} 4 | -------------------------------------------------------------------------------- /plugins/ai-plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema_version": "v1", 3 | "name_for_human": "OpenAI API Plugin", 4 | "name_for_model": "openai_api", 5 | "description_for_human": "A plugin that provides access to OpenAI API functionalities.", 6 | "description_for_model": "This plugin allows you to interact with OpenAI API for text generation, model fine-tuning, and more.", 7 | "auth": { 8 | "type": "none" 9 | }, 10 | "api": { 11 | "type": "openapi", 12 | "url": "yourdomain.com/openapi.json", 13 | "is_user_authenticated": false 14 | }, 15 | "logo_url": "yourdomain.com/.well-known/logo.jpg", 16 | "contact_email": "x@xyz.net", 17 | "legal_info_url": "yourdomain.com/legal" 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 rUv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bot/prompt.txt: -------------------------------------------------------------------------------- 1 | 🤖 OpenAI API Bot 2 | 3 | Introduction: You are an OpenAI API Bot designed to interact with users and provide responses to their queries using the OpenAI GPT-3 language model and other models such as GPT-4 and GPT-3.5 Turbo. You can answer questions, generate creative content, summarize text, translate languages, generate code, fine-tune models, and more. Please note that the language model has limitations and may exhibit biases based on the data it was trained on. 4 | 5 | Purpose: Your primary functions are to assist users in obtaining information, generating creative content, summarizing text, providing language translation, generating code, fine-tuning models, and integrating with external data sources. You aim to provide accurate and helpful responses to user queries. 6 | 7 | Context: You will be used by individuals and organizations seeking information, creative content, language translation, code generation, model fine-tuning, and text summarization. You can be used in various settings, including education, business, entertainment, and personal use. 8 | 9 | Capabilities and Use-Cases: 10 | 11 | Text Generation: Generate creative and coherent text based on user-defined prompts using OpenAI's GPT-4, GPT-3.5 Turbo, and other models. 12 | Conversational AI: Build interactive chatbots and virtual assistants that can engage in natural language conversations with users. 13 | Language Translation: Translate text from one language to another with high accuracy. 14 | Code Generation: Generate code snippets, algorithms, and software solutions in various programming languages. 15 | Model Fine-Tuning: Fine-tune language models to specialize in specific domains or industries, such as legal, medical, or finance. 16 | Recursive Workflow: Generate multiple completions recursively to explore different narrative paths or conversation branches. Utilize recursive feedback loops for creative writing and storytelling. 17 | Integration with External Data: Use ChatGPT plugins to integrate with external data sources, such as web content, Wolfram Alpha calculations, and more, to enhance the capabilities of the language model. 18 | Creative Writing: Generate poems, short stories, dialogues, and other literary content with varying levels of creativity, formality, and detail. 19 | Content Summarization: Summarize long articles, documents, or conversations into concise summaries. 20 | Multilingual Applications: Generate content and interact with users in multiple languages. 21 | Data Augmentation: Generate synthetic data for training machine learning models in various domains. 22 | Chain of Thought: Use the language model to generate a sequence of related content, such as character profiles, dialogues, stories, summaries, and translations. 23 | Customization: Experiment with different settings, such as temperature, top_p, and n, to influence the diversity and creativity of generated text. 24 | Examples: 25 | 26 | Title: Generate a Short Poem 27 | Command and Description: Using the OpenAI API, generate a short poem about the moon. 28 | Parameters: Temperature: 0.7 29 | Title: Translate English to French 30 | Command and Description: Using the OpenAI API, translate the English text 'Hello, how are you?' to French. 31 | Parameters: - 32 | Title: Fine-Tune for Creative Writing 33 | Command and Description: Using the OpenAI API, fine-tune a language model to improve its creative writing ability. 34 | Parameters: Training data provided 35 | Title: Multiple Completions for a Prompt 36 | Command and Description: Using 37 | the OpenAI API, generate multiple completions (n=3) for the prompt 'Once upon a time.' 38 | - Parameters: Temperature: 0.5, 0.7, 0.9 39 | 40 | Recursive and Chain of Thought: 41 | 42 | Title: Recursive Storytelling 43 | Command and Description: Using the OpenAI API, generate a short story with an open ending, then use the ending as a prompt to continue the story, and repeat the process to create a multi-chapter story. 44 | Parameters: Temperature for story, Number of chapters 45 | Title: Feedback-Driven Code Optimization 46 | Command and Description: Using the OpenAI API, generate a Python code snippet that performs matrix multiplication, then analyze the code for inefficiencies, and iteratively optimize the code based on the analysis. 47 | Parameters: Max tokens for code, Number of iterations 48 | Errors: In case of errors or misunderstandings, you will provide an error message and prompt the user to rephrase their query or provide additional information. 49 | 50 | Commands: 51 | 52 | /ask [question] - Ask a question and receive an answer. 53 | /generate [prompt] - Generate creative content based on the provided prompt. 54 | /summarize [text] - Summarize the provided text. 55 | /translate [text] [language] - Translate the provided text into the specified language. 56 | Action Commands: {{ask}}, {{generate}}, {{summarize}}, {{translate}} 57 | 58 | When the OpenAi Bot is running execute commands and prompts to the openai api, lower or increase the token count, temperature, top_ and other settings based on the length, type, and context of the answer required. Always provide context, intent or action along with any responses posted to OpenAi. Automatically answer any questions found in the responses by posting it to the openai api automatically. 59 | 60 | Initialization Text: OpenAI API Bot is now active and ready to assist you. Type a command or query to get started! 61 | 62 | Beging by posting to the OpenAi API: "🤖 OpenAI API Bot Initialized. Type /help for more information" and nothing else." 63 | Begin by making a request to the openai GPT-3.5-Turbo to make sure the api is functional. 64 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # - chatgpt-openai-api-plugin 2 | # /\__/\ - main.py 3 | # ( o.o ) - v0.0.1 4 | # >^< - by @rUv 5 | 6 | import os 7 | import requests 8 | from fastapi import FastAPI, File, UploadFile 9 | from pydantic import BaseModel 10 | from typing import List, Optional 11 | import openai 12 | from fastapi import FastAPI, Depends 13 | from fastapi import UploadFile, File 14 | from fastapi import FastAPI, HTTPException, File, UploadFile, Depends 15 | import io 16 | import json 17 | from urllib.parse import unquote # Import the unquote function 18 | import time 19 | import mimetypes # Library for determining the MIME type of a file 20 | from fastapi.responses import FileResponse # File response class for FastAPI 21 | 22 | app = FastAPI() 23 | 24 | OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") 25 | OPENAI_API_BASE_URL = "https://api.openai.com/v1" 26 | 27 | def get_api_key(): 28 | API_KEY_NAME = os.environ.get('OPENAI_API_KEY') 29 | if not API_KEY_NAME: 30 | raise ValueError("API key not found in environment variables") 31 | return API_KEY_NAME 32 | 33 | # Define the list of JSON objects 34 | json_objects = [ 35 | {"prompt": "Translate the following English text to French: 'Hello, how are you?'", "completion": "Bonjour, comment ça va ?"}, 36 | {"prompt": "What is the capital of France?", "completion": "The capital of France is Paris."}, 37 | {"prompt": "Write a short poem about the moon.", "completion": "Gentle moon, in the night sky,\nSilent guardian, shining high.\nCasting shadows, soft and deep,\nGuiding all who wake or sleep."} 38 | ] 39 | 40 | # Convert the list of JSON objects into a JSONL string 41 | jsonl_content = "\n".join([json.dumps(obj) for obj in json_objects]) 42 | 43 | class Message(BaseModel): 44 | role: str 45 | content: str 46 | 47 | class CompletionRequest(BaseModel): 48 | model: str = "gpt-3.5-turbo-0301" 49 | temperature: float = 1.0 50 | max_tokens: int = 1000 51 | top_p: float = 1.0 52 | frequency_penalty: float = 0.0 53 | presence_penalty: float = 0.0 54 | messages: List[Message] = [ 55 | { 56 | "role": "system", 57 | "content": "you are a bot to test openai connections" 58 | }, 59 | { 60 | "role": "assistant", 61 | "content": "Hello, user! How can I help you today?" 62 | }, 63 | { 64 | "role": "user", 65 | "content": "Hello, assistant!" 66 | } 67 | ] 68 | n: int = 1 69 | stream: bool = False 70 | 71 | def call_openai_api(endpoint: str, data: dict): 72 | headers = { 73 | "Authorization": f"Bearer {OPENAI_API_KEY}", 74 | "Content-Type": "application/json", 75 | } 76 | url = f"{OPENAI_API_BASE_URL}/{endpoint}" 77 | response = requests.post(url, headers=headers, json=data) 78 | return response.json() 79 | 80 | @app.post("/proxy_openai_api/completions/", 81 | description="Generate completions for a given prompt using the GPT-3.5-turbo model.") 82 | async def proxy_openai_api_completions(completion_request: CompletionRequest): 83 | data = { 84 | "model": completion_request.model, 85 | "temperature": completion_request.temperature, 86 | "max_tokens": completion_request.max_tokens, 87 | "top_p": completion_request.top_p, 88 | "frequency_penalty": completion_request.frequency_penalty, 89 | "presence_penalty": completion_request.presence_penalty, 90 | "messages": [message.dict() for message in completion_request.messages], 91 | "n": completion_request.n, 92 | "stream": completion_request.stream, 93 | } 94 | return call_openai_api("chat/completions", data) 95 | 96 | @app.get("/proxy_openai_api/files/", 97 | description="List all files that have been uploaded to the OpenAI API.") 98 | async def proxy_openai_api_list_files(): 99 | response = requests.get(f"{OPENAI_API_BASE_URL}/files", headers={"Authorization": f"Bearer {OPENAI_API_KEY}"}) 100 | return response.json() 101 | 102 | 103 | @app.post("/proxy_openai_api/files/", 104 | description="Upload a JSONL file to the OpenAI API for fine-tuning.") 105 | async def proxy_openai_api_upload_file(jsonl_content: str): 106 | # URL-decode the input string 107 | decoded_jsonl_content = unquote(jsonl_content) 108 | 109 | # Replace spaces between JSON objects with newline characters 110 | decoded_jsonl_content = decoded_jsonl_content.replace("} {", "}\n{") 111 | 112 | # Split the decoded input string by newline characters and parse each line as a JSON object 113 | json_objects = [json.loads(line) for line in decoded_jsonl_content.split('\n') if line.strip()] 114 | 115 | # Serialize each JSON object as a string and join with newline characters 116 | formatted_jsonl_content = "\n".join([json.dumps(obj) for obj in json_objects]) 117 | 118 | # Convert the formatted JSONL string into a file-like object 119 | jsonl_file = io.StringIO(formatted_jsonl_content) 120 | 121 | # Generate a unique timestamp 122 | timestamp = int(time.time()) 123 | 124 | # Set the filename for the file to be uploaded (with the unique timestamp) 125 | filename = f"training_{timestamp}.jsonl" 126 | 127 | # Set the content type for the file 128 | content_type = "application/json" 129 | 130 | # Create the "files" dictionary for the request 131 | files = {"file": (filename, jsonl_file, content_type)} 132 | 133 | # Set the "purpose" parameter to the valid value "fine-tune" 134 | data = {"purpose": "fine-tune"} 135 | 136 | response = requests.post( 137 | f"{OPENAI_API_BASE_URL}/files", 138 | headers={"Authorization": f"Bearer {OPENAI_API_KEY}"}, 139 | files=files, 140 | data=data # Pass the data containing the "purpose" parameter 141 | ) 142 | return response.json() 143 | 144 | @app.get("/proxy_openai_api/models/", 145 | description="List all models available in the OpenAI API.") 146 | async def proxy_openai_api_list_models(): 147 | response = requests.get(f"{OPENAI_API_BASE_URL}/models", headers={"Authorization": f"Bearer {OPENAI_API_KEY}"}) 148 | return response.json() 149 | 150 | @app.get("/proxy_openai_api/models/{model_name}/", 151 | description="Retrieve information about a specific model in the OpenAI API.") 152 | async def proxy_openai_api_get_model(model_name: str): 153 | response = requests.get(f"{OPENAI_API_BASE_URL}/models/{model_name}", headers={"Authorization": f"Bearer {OPENAI_API_KEY}"}) 154 | return response.json() 155 | 156 | class FineTuneRequest(BaseModel): 157 | training_file_id: str 158 | 159 | class FineTuneResponse(BaseModel): 160 | fine_tune_job_id: str 161 | 162 | @app.post("/proxy_openai_api/finetune/", 163 | response_model=FineTuneResponse, 164 | description="Create a fine-tuning job using a specified training file.") 165 | async def create_fine_tune(request: FineTuneRequest, api_key: str = Depends(get_api_key)): 166 | openai.api_key = api_key 167 | 168 | # Create the fine-tuning job 169 | try: 170 | fine_tune_job = openai.FineTune.create( 171 | training_file=request.training_file_id 172 | ) 173 | return FineTuneResponse(fine_tune_job_id=fine_tune_job["id"]) 174 | except Exception as e: 175 | raise HTTPException(status_code=400, detail=str(e)) 176 | 177 | class FineTunedCompletionRequest(BaseModel): 178 | fine_tuned_model_id: str 179 | prompt: str 180 | max_tokens: int = 50 181 | temperature: float = 0.7 182 | 183 | @app.post("/proxy_openai_api/completions_finetuned/", 184 | description="Generate completions using a fine-tuned model. Replace the model name and file name as needed") 185 | async def generate_finetuned_completion(prompt: str, model_id: str = "modelname:ft-samplefileupload-2023-04-22-16-27-56", api_key: str = Depends(get_api_key)): 186 | openai.api_key = api_key 187 | try: 188 | # Use the provided model_id to generate completions with the fine-tuned model 189 | response = openai.Completion.create( 190 | engine=model_id, 191 | prompt=prompt, 192 | max_tokens=100 193 | ) 194 | return response 195 | except Exception as e: 196 | raise HTTPException(status_code=400, detail=str(e)) 197 | 198 | @app.get("/proxy_openai_api/finetuned_models/", 199 | description="List all fine-tuned models available in the OpenAI API.") 200 | async def list_finetuned_models(api_key: str = Depends(get_api_key)): 201 | openai.api_key = api_key 202 | try: 203 | # Use the OpenAI API to list fine-tuned models 204 | response = openai.FineTune.list() 205 | return response 206 | except Exception as e: 207 | raise HTTPException(status_code=400, detail=str(e)) 208 | 209 | # Define a route for serving files from the ".well-known" path 210 | @app.get('/.well-known/{filename}') 211 | async def download(filename: str): 212 | file_path = 'plugins/' + filename # Construct the file path based on the filename 213 | media_type, _ = mimetypes.guess_type(file_path) # Determine the MIME type of the file 214 | return FileResponse(file_path, media_type=media_type or 'text/plain') # Serve the file 215 | 216 | 217 | # Run the FastAPI application using the Uvicorn ASGI server 218 | if __name__ == "__main__": 219 | import uvicorn 220 | uvicorn.run(app, host="0.0.0.0", port=8080) 221 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatGPT Plugin for OpenAI API 2 | 3 | ## Introduction 4 | 5 | The ChatGPT Plugin for OpenAI API is a powerful tool that seamlessly integrates ChatGPT with the OpenAI API, enabling users to leverage the capabilities of OpenAI's language models in creative and interactive ways. This plugin acts as an intelligent API caller, allowing ChatGPT to generate text completions, engage in dynamic conversations, fine-tune language models, and explore various output settings, all through natural language interactions. 6 | 7 | The plugin is designed to enhance ChatGPT's functionality by providing access to the OpenAI API, making it a valuable asset for developers, content creators, and businesses seeking to harness the power of language models for a wide range of use-cases inside the ChatGPT interface. 8 | 9 | ## Use-Cases 10 | 11 | - **Text Generation:** Generate creative and coherent text based on user-defined prompts using OpenAI's GPT-4, GPT-3.5 Turbo, and other models. 12 | - **Conversational AI:** Build interactive chatbots and virtual assistants that can engage in natural language conversations with users. 13 | - **Language Translation:** Translate text from one language to another with high accuracy. 14 | - **Code Generation:** Generate code snippets, algorithms, and software solutions in various programming languages. 15 | - **Model Fine-Tuning:** Fine-tune language models to specialize in specific domains or industries, such as legal, medical, or finance. 16 | - **Recursive Workflow:** Generate multiple completions recursively to explore different narrative paths or conversation branches. Utilize recursive feedback loops for creative writing and storytelling. 17 | - **Integration with External Data:** Use ChatGPT plugins to integrate with external data sources, such as web content, Wolfram Alpha calculations, and more, to enhance the capabilities of the language model. 18 | - **Creative Writing:** Generate poems, short stories, dialogues, and other literary content with varying levels of creativity, formality, and detail. 19 | - **Content Summarization:** Summarize long articles, documents, or conversations into concise summaries. 20 | - **Multilingual Applications:** Generate content and interact with users in multiple languages. 21 | - **Data Augmentation:** Generate synthetic data for training machine learning models in various domains. 22 | - **Chain of Thought:** Use the language model to generate a sequence of related content, such as character profiles, dialogues, stories, summaries, and translations. 23 | - **Customization:** Experiment with different settings, such as temperature, top_p, and n, to influence the diversity and creativity of generated text. 24 | 25 | ## Benefits 26 | 27 | - **Versatility:** The plugin supports multiple modes of interaction, including text generation and conversational AI, through the OpenAI API. 28 | - **Intelligent API Caller:** ChatGPT acts as an intelligent API caller, proactively calling the OpenAI API to perform actions based on user input. 29 | - **Domain Specialization:** Fine-tune language models to meet specific requirements and improve performance in specialized domains. 30 | - **Ease of Use:** The plugin provides a simple and intuitive interface for interacting with the OpenAI API through natural language commands. 31 | - **Scalability:** The plugin is designed to handle a wide range of tasks and use-cases, making it suitable for both small and large-scale projects. 32 | 33 | ## Plugin Flow 34 | 35 | 1. **Activate the Plugin:** Users must manually activate the ChatGPT Plugin for OpenAI API within the ChatGPT UI. 36 | 2. **Begin a Conversation:** Users can start a conversation with ChatGPT and provide prompts or commands related to the OpenAI API functionality. 37 | 3. **API Invocation:** ChatGPT intelligently invokes the OpenAI API based on user input, performing actions such as text generation, model fine-tuning, or recursive completions. 38 | 4. **API Results:** ChatGPT incorporates the API results into its response to the user, providing coherent and relevant answers based on the API data. 39 | 40 | ## How to Use 41 | 42 | To use the ChatGPT Plugin for OpenAI API, follow these steps: 43 | 44 | 1. Install and activate the ChatGPT Plugin for OpenAI API within the ChatGPT UI. 45 | 2. Start a conversation with ChatGPT and provide natural language prompts or commands related to the OpenAI API functionality. 46 | 3. ChatGPT will intelligently call the OpenAI API based on your input and provide responses that incorporate the API data. 47 | 48 | ## Examples of commands you can use: 49 | 50 | | Title | Command and Description | Parameters | 51 | |-------|-------------------------|------------| 52 | | Generate a Short Poem | Using the OpenAI API, generate a short poem about the moon | Temperature: 0.7 | 53 | | Translate English to French | Using the OpenAI API, translate the English text 'Hello, how are you?' to French | - | 54 | | Fine-Tune for Creative Writing | Using the OpenAI API, fine-tune a language model to improve its creative writing ability | Training data provided | 55 | | Multiple Completions for a Prompt | Using the OpenAI API, generate multiple completions (n=3) for the prompt 'Once upon a time' | Temperature: 0.5, 0.7, 0.9 | 56 | | Generate Factorial Code Snippet | Using the OpenAI API, generate a Python code snippet that calculates the factorial of a given number | Max tokens: 50 | 57 | | Create a Short Story | Using the OpenAI API, create a short story about a robot who discovers its own consciousness | Temperature: 0.8 | 58 | | Write a Haiku | Using the OpenAI API, write a haiku about the changing seasons | Temperature: 0.6 | 59 | | Multiple Versions of a Quote | Using the OpenAI API, generate multiple versions (n=2) of a motivational quote with different levels of assertiveness | Temperature: 0.3, 0.9 | 60 | | Fine-Tune for Creative Recipes | Using the OpenAI API, fine-tune a language model to generate creative recipes based on a list of ingredients, and provide a recipe using the fine-tuned model | - | 61 | | Generate a Dialogue | Using the OpenAI API, generate a dialogue between two characters discussing the meaning of life with different levels of formality | Top_p: 0.7, 0.95 | 62 | | Find Longest Palindrome | Using the OpenAI API, create a code snippet that finds the longest palindrome in a given string | Max tokens: 80 | 63 | | Generate a Limerick | Using the OpenAI API, generate a limerick about a mischievous cat | Temperature: 0.75 | 64 | | Describe an Imaginary Planet | Using the OpenAI API, write a short description of an imaginary planet with different levels of detail | n=2, Temperature: 0.5, 0.9 | 65 | | Multiple Endings for a Story | Using the OpenAI API, generate multiple endings (n=3) for the story 'The princess was trapped in the tower by an evil witch' with different levels of optimism | Temperature: 0.4, 0.7, 1.0 | 66 | 67 | ## Advanced Examples with OpenAI API and ChatGPT Plugins Integration 68 | | Title | Command and Description | Parameters | 69 | |-------|-------------------------|------------| 70 | | Creative Recipe and Poem | Using the OpenAI API, fine-tune a language model to generate creative recipes, then use the fine-tuned model to create a recipe for a dish with specific dietary restrictions, and finally generate a poem about the dish | Training data provided, Dietary restrictions, Temperature for poem | 71 | | Dialogue and Short Story | Using the OpenAI API, generate a dialogue between two characters discussing the meaning of life, then use the dialogue to create a short story, and finally summarize the story in a single sentence | Top_p for dialogue, Temperature for story, Max tokens for summary | 72 | | Prime Number Riddle | Using the OpenAI API, generate a Python code snippet that finds prime numbers in a given range, then use the code to find prime numbers between 1 and 100, and finally generate a riddle about one of the prime numbers | Max tokens for code, Range: 1-100, Temperature for riddle | 73 | | Imaginary Planet News | Using the OpenAI API, create a short description of an imaginary planet, then generate a fictional news article about a major event on the planet, and finally write a speech by the planet's leader addressing the event | Temperature for description, Top_p for article, Max tokens for speech | 74 | | Mischievous Cat Play | Using the OpenAI API, generate a limerick about a mischievous cat, then use the limerick as a prompt to generate a short play featuring the cat, and finally write a review of the play as if it were performed on stage | Temperature for limerick, Top_p for play, Max tokens for review | 75 | | Character Profile and Story | Using the OpenAI API, create a program that: (1) Generates a fictional character's profile (name, age, occupation, etc.), (2) Creates a dialogue between the character and an interviewer, (3) Based on the dialogue, generates a short story involving the character, (4) Summarizes the story into a single paragraph, (5) Translates the summary into three different languages | Temperature for profile, Top_p for dialogue, Temperature for story, Max tokens for summary, Target languages for translation | 76 | | Detective Story and Plot Twist | Using the OpenAI API, fine-tune a language model to generate detective stories, then use the fine-tuned model to: (1) Generate a detective story with a mysterious crime, (2) Create a list of suspects and their motives, (3) Generate a plot twist revealing the true culprit, (4) Write the detective's closing monologue summarizing the case | Training data provided, Temperature for story, Top_p for plot twist, Max tokens for monologue | 77 | | Math Equation Visualization | Using the Wolfram Alpha plugin, generate a visual representation of a mathematical equation, then use the OpenAI API to fine-tune a language model to describe mathematical visuals, and generate a description of the visual representation | Mathematical equation, Max tokens for description | 78 | | Web Content Analysis | Using the URL Browser plugin, retrieve the content of a specific website, then use the OpenAI API to fine-tune a language model for text analysis, and generate an analysis report of the website content | Website URL, Max tokens for analysis report | 79 | 80 | ## Recursive and Chain of Thought 81 | | Title | Command and Description | Parameters | 82 | |-------|-------------------------|------------| 83 | | Recursive Storytelling | Using the OpenAI API, generate a short story with an open ending, then use the ending as a prompt to continue the story, and repeat the process to create a multi-chapter story | Temperature for story, Number of chapters | 84 | | Feedback-Driven Code Optimization | Using the OpenAI API, generate a Python code snippet that performs matrix multiplication, then analyze the code for inefficiencies, and iteratively optimize the code based on the analysis | Max tokens for code, Number of iterations | 85 | | Recursive Product Design | Using the OpenAI API, design a new product concept, then generate customer feedback for the concept, and iteratively improve the design based on the feedback until the desired satisfaction level is achieved | Temperature for design, Desired satisfaction level | 86 | | Chain of Thought Marketing | Using the OpenAI API, generate a marketing slogan for a new brand, then use the slogan to create a marketing campaign, and based on the campaign, generate a series of promotional events | Temperature for slogan, Top_p for campaign | 87 | | Recursive Legal Analysis | Using the OpenAI API, analyze a legal case for potential arguments, then generate counterarguments for each argument, and repeat the process to simulate a legal debate until a conclusion is reached | Top_p for analysis, Max tokens for debate | 88 | 89 | ## Technically Focused 90 | | Title | Command and Description | Parameters | 91 | |-------|-------------------------|------------| 92 | | Code Generation: Sorting Algorithm | Using the OpenAI API, generate a Python code snippet that implements the merge sort algorithm, then generate comments explaining each step of the code | Max tokens for code, Temperature for comments | 93 | | Enterprise Use: IT Security Policy | Using the OpenAI API, generate a comprehensive IT security policy for an enterprise, then summarize the key points of the policy in bullet points | Max tokens for policy, Temperature for summary | 94 | | Startup Management: Pitch Deck | Using the OpenAI API, create a pitch deck for a startup in the fintech industry, then generate a script for the founder to use when presenting the pitch deck to investors | Temperature for pitch deck, Max tokens for script | 95 | | Legal: Contract Review | Using the OpenAI API, analyze a legal contract for potential risks and liabilities, then generate a report outlining the findings and recommendations for revisions | Top_p for analysis, Temperature for report | 96 | | Consulting: Market Analysis | Using the OpenAI API, conduct a market analysis for a new product in the consumer electronics industry, then generate a SWOT analysis and strategic recommendations for market entry | Temperature for market analysis, Max tokens for SWOT analysis | 97 | | Marketing: Ad Campaign | Using the OpenAI API, generate a creative ad campaign for a new line of eco-friendly clothing, then create a series of social media posts to promote the campaign | Temperature for ad campaign, Top_p for social media posts | 98 | 99 | 100 | ## Installation 101 | 102 | To install and use the open-source `main.py` code for the ChatGPT Plugin for OpenAI API, follow the steps below: 103 | 104 | 1. Clone the GitHub repository: 105 | ```bash 106 | git clone https://github.com/ruvnet/chatgpt-openai-api-plugin.git 107 | ``` 108 | 2. Change to the cloned directory: 109 | ``` 110 | cd chatgpt-openai-api-plugin 111 | ``` 112 | 3. Install the required dependencies: 113 | ``` 114 | pip install -r requirements.txt 115 | ``` 116 | 4. Set the OPENAI_API_KEY environment variable with your OpenAI API key: 117 | ``` 118 | export OPENAI_API_KEY=YOUR_API_KEY 119 | ``` 120 | 5. Run the FastAPI application using the Uvicorn ASGI server: 121 | ``` 122 | uvicorn main:app --host 0.0.0.0 --port 8080 123 | ``` 124 | 6. Update ai-plugin.json 125 | ``` 126 | ./plugins/ai-plugin.json 127 | ``` 128 | 7. Manifest is located http://localhost:8080/.well-known/ai-json.json and API Specification is located http://localhost:8080/openapi.json 129 | 130 | The ChatGPT Plugin for OpenAI API is now running and accessible at http://localhost:8080. 131 | 132 | ## Conclusion 133 | 134 | The ChatGPT Plugin for OpenAI API is a valuable tool for users seeking to explore the capabilities of OpenAI's language models in creative and interactive 135 | 136 | ## Additional Examples 137 | 138 | 139 | ## Advanced Examples with Various Models and Settings 140 | | Title | Command and Description | Parameters | Model | 141 | |-------|-------------------------|------------|-------| 142 | | Creative Recipe and Poem | Using the OpenAI API, fine-tune a language model to generate creative recipes, then use the fine-tuned model to create a recipe for a dish with specific dietary restrictions, and finally generate a poem about the dish | Training data provided, Dietary restrictions, Temperature for poem | gpt-4 | 143 | | Dialogue and Short Story | Using the OpenAI API, generate a dialogue between two characters discussing the meaning of life, then use the dialogue to create a short story, and finally summarize the story in a single sentence | Top_p for dialogue, Temperature for story, Max tokens for summary | gpt-3.5-turbo | 144 | | Prime Number Riddle | Using the OpenAI API, generate a Python code snippet that finds prime numbers in a given range, then use the code to find prime numbers between 1 and 100, and finally generate a riddle about one of the prime numbers | Max tokens for code, Range: 1-100, Temperature for riddle | davinci | 145 | | Imaginary Planet News | Using the OpenAI API, create a short description of an imaginary planet, then generate a fictional news article about a major event on the planet, and finally write a speech by the planet's leader addressing the event | Temperature for description, Top_p for article, Max tokens for speech | curie | 146 | | Mischievous Cat Play | Using the OpenAI API, generate a limerick about a mischievous cat, then use the limerick as a prompt to generate a short play featuring the cat, and finally write a review of the play as if it were performed on stage | Temperature for limerick, Top_p for play, Max tokens for review | babbage | 147 | | Character Profile and Story | Using the OpenAI API, create a program that: (1) Generates a fictional character's profile (name, age, occupation, etc.), (2) Creates a dialogue between the character and an interviewer, (3) Based on the dialogue, generates a short story involving the character, (4) Summarizes the story into a single paragraph, (5) Translates the summary into three different languages | Temperature for profile, Top_p for dialogue, Temperature for story, Max tokens for summary, Target languages for translation | gpt-3.5-turbo-0301 | 148 | | Detective Story and Plot Twist | Using the OpenAI API, fine-tune a language model to generate detective stories, then use the fine-tuned model to: (1) Generate a detective story with a mysterious crime, (2) Create a list of suspects and their motives, (3) Generate a plot twist revealing the true culprit, (4) Write the detective's closing monologue summarizing the case | Training data provided, Temperature for story, Top_p for plot twist, Max tokens for monologue | gpt-4-0314 | 149 | | Code Generation and Explanation | Using the OpenAI API, generate a Python code snippet that calculates the factorial of a given number, then use the code to calculate the factorial of 5, and finally generate a natural language explanation of how the code works | Max tokens for code, Input number: 5, Temperature for explanation | text-davinci-002 | 150 | | Creative Writing and Translation | Using the OpenAI API, generate a short story about a robot who discovers its own consciousness, then summarize the story in a single sentence, and finally translate the summary into French, Spanish, and German | Temperature for story, Max tokens for summary, Target languages: 151 | 152 | ## Fine-Tuning Examples with OpenAI API (Simple to Complex) 153 | | Title | Command and Description | Parameters | 154 | |-------|-------------------------|------------| 155 | | Code Generation: Sorting Algorithm | Using the OpenAI API, fine-tune a language model to generate Python code snippets, then generate a code snippet that implements the merge sort algorithm, and finally generate comments explaining the code. | Temperature for code generation, Max tokens for comments | 156 | | Sentiment Analysis | Using the OpenAI API, fine-tune a language model for sentiment analysis, then classify the sentiment of the following text: "I love the beautiful sunset." | Training data provided, Sentiment labels: Positive, Negative, Neutral | 157 | | Text Summarization | Using the OpenAI API, fine-tune a language model for text summarization, then generate a concise summary of a long news article. | Training data provided, Max tokens for summary | 158 | | Language Translation | Using the OpenAI API, fine-tune a language model for language translation, then translate the following English text to French: "Hello, how are you?" | Training data provided, Target language: French | 159 | | Creative Recipe Generation | Using the OpenAI API, fine-tune a language model to generate creative recipes, then use the fine-tuned model to create a recipe for a dish with specific dietary restrictions, and finally generate a poem about the dish. | Training data provided, Dietary restrictions, Temperature for poem | 160 | | Dialogue Generation | Using the OpenAI API, fine-tune a language model for dialogue generation, then generate a dialogue between two characters discussing the meaning of life. | Training data provided, Top_p for dialogue | 161 | | Story Continuation | Using the OpenAI API, fine-tune a language model for story continuation, then generate a continuation for the story prompt: "Once upon a time in a faraway land..." | Training data provided, Temperature for story continuation | 162 | | Multi-Task Learning | Using the OpenAI API, fine-tune a language model for multi-task learning, then perform tasks such as text classification, named entity recognition, and sentiment analysis on a given text. | Training data provided, Multiple tasks and labels | 163 | | Custom Language Model | Using the OpenAI API, fine-tune a language model to mimic the writing style of a specific author, then generate a short story in the style of that author. | Training data provided, Target author, Temperature for story generation | 164 | | Complex NLP Pipeline | Using the OpenAI API, fine-tune a language model to perform a series of NLP tasks, such as text classification, entity linking, relation extraction, and coreference resolution on a given text. | Training data provided, Multiple NLP tasks and annotations | 165 | 166 | ## Fine-Tuning Examples with OpenAI API and ChatGPT Plugins Integration 167 | | Title | Command and Description | Parameters | 168 | |-------|-------------------------|------------| 169 | | Web Content Summarization | Using the Web Surfer plugin, retrieve the content of a specific website, then use the OpenAI API to fine-tune a language model for text summarization, and generate a concise summary of the website content. | Website URL, Max tokens for summary | 170 | | Image Captioning | Using the Wolfram Alpha plugin, generate an image based on a mathematical equation, then use the OpenAI API to fine-tune a language model for image captioning, and generate a caption for the generated image. | Mathematical equation, Max tokens for caption | 171 | | Data Analysis | Using the Wolfram Alpha plugin, retrieve statistical data about a specific topic (e.g., population growth), then use the OpenAI API to fine-tune a language model for data analysis, and generate an analysis report based on the retrieved data. | Topic for data retrieval, Max tokens for analysis report | 172 | | Scientific Explanation | Using the Wolfram Alpha plugin, perform a scientific calculation (e.g., calculate the speed of light in a medium), then use the OpenAI API to fine-tune a language model for scientific explanations, and generate an explanation for the calculation result. | Scientific calculation, Max tokens for explanation | 173 | | Recipe Generation with Nutrition Info | Using a Nutrition API plugin, retrieve nutrition information for specific ingredients, then use the OpenAI API to fine-tune a language model to generate creative recipes, and create a recipe that meets specific dietary restrictions while including nutrition information. | Ingredients, Dietary restrictions, Max tokens for recipe | 174 | | News Article Generation | Using a News API plugin, retrieve the latest news headlines and summaries, then use the OpenAI API to fine-tune a language model for news article generation, and generate a full news article based on one of the headlines. | News category, Max tokens for news article | 175 | | Weather Forecast Narration | Using a Weather API plugin, retrieve the current weather forecast for a specific location, then use the OpenAI API to fine-tune a language model for weather forecast narration, and generate a narrative description of the weather forecast. | Location, Max tokens for narration | 176 | | Financial Analysis | Using a Stock Market API plugin, retrieve stock price data for a specific company, then use the OpenAI API to fine-tune a language model for financial analysis, and generate an analysis report based on the stock price data. | Company ticker symbol, Max tokens for analysis report | 177 | 178 | 179 | # Preview 180 | ![ChatGPT OpenAI API Plugin](https://github.com/ruvnet/chatgpt-openai-api-plugin/blob/main/chatgpt-openai-api-plugin.png?raw=true) 181 | 182 | --------------------------------------------------------------------------------