ripred

Untitled

Feb 20th, 2025
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. ### Setting Up a Custom GPT with `server.py`, `instructions.txt`, and `openai.yaml`
  2.  
  3. This guide will help you set up and run a Custom GPT using OpenAI's "Custom GPT" feature by hosting your own API endpoint using `server.py` with `uvicorn` and `ngrok`.
  4.  
  5. #### 1. **Place Your Files**
  6. Ensure the following files are properly set up:
  7.  
  8. - **`server.py`** – Your FastAPI-based server that serves as the backend for the GPT actions.
  9. - **`instructions.txt`** – Custom instructions that define how the GPT should behave.
  10. - **`openai.yaml`** – The configuration file that specifies API endpoint details.
  11.  
  12. Keep these files in a dedicated project directory.
  13.  
  14. #### 2. **Run `server.py` Locally**
  15. You'll need to start your FastAPI server using `uvicorn`:
  16.  
  17. 1. Install dependencies (if not already installed):
  18.  
  19. ```bash
  20. pip install fastapi uvicorn
  21. ```
  22.  
  23. 2. Run the server:
  24.  
  25. ```bash
  26. uvicorn server:app --host 0.0.0.0 --port 8000
  27. ```
  28.  
  29. This will start the API server locally at `http://127.0.0.1:8000`.
  30.  
  31. #### 3. **Expose the Server Using Ngrok**
  32. To make your local server accessible to OpenAI’s API, use `ngrok`:
  33.  
  34. 1. Install `ngrok` (if not installed):
  35.  
  36. ```bash
  37. brew install ngrok # macOS
  38. sudo apt install ngrok # Debian/Ubuntu
  39. ```
  40.  
  41. Or download it from [ngrok.com](https://ngrok.com/).
  42.  
  43. 2. Start `ngrok` to expose port 8000:
  44.  
  45. ```bash
  46. ngrok http 8000
  47. ```
  48.  
  49. This will generate a public URL like `https://xyz.ngrok.io/`.
  50.  
  51. #### 4. **Update `openai.yaml`**
  52. Edit your `openai.yaml` file and set the `base_url` to the ngrok-generated URL:
  53.  
  54. ```yaml
  55. base_url: "https://xyz.ngrok.io"
  56. ```
  57.  
  58. Replace `https://xyz.ngrok.io` with your actual `ngrok` URL.
  59.  
  60. #### 5. **Upload `openai.yaml` and `instructions.txt`**
  61. - Open OpenAI's [Custom GPT](https://platform.openai.com/gpts).
  62. - Click **Create** or **Edit** a Custom GPT.
  63. - Upload `instructions.txt` and `openai.yaml` under **Advanced Settings**.
  64.  
  65. #### 6. **Test Your Custom GPT**
  66. - After uploading, test interactions in the OpenAI interface.
  67. - Ensure API calls to your `server.py` are working correctly.
  68.  
  69. #### Notes:
  70. - Each time you restart `ngrok`, the public URL changes—update `openai.yaml` accordingly.
  71. - Consider using an `ngrok` authtoken to maintain a stable URL.
  72.  
  73. This setup ensures your Custom GPT can call external actions via your locally hosted FastAPI server. 🚀
Advertisement
Add Comment
Please, Sign In to add comment