Public
HTTP (deprecated)
Readme

openAiProxy

Overview

This val is a proxy server that interacts with the OpenAI API to generate responses based on prompts in the request body. The function handles incoming HTTP POST requests, processes the prompt, and returns a response generated by the LLM.

Prerequisites

  • Server-side: (Optional) An active OpenAI API key
  • Client-side: Something that can make POST requests (browser code, Postman, cURL, another Val, etc)

Usage

Endpoint

The primary endpoint for this function is designed to handle HTTP POST requests.

Request

  • Method: POST
  • Content-Type: application/json
  • Body: JSON object containing a prompt field (e.g. {"prompt": "Help me make a boat."})

Example Request

curl -X POST https://ashryanio-openaiproxy.web.val.run -H "Content-Type: application/json" -d '{"prompt": "Hello, OpenAI!"}'

Response

  • Content-Type: application/json
  • Body: JSON object containing the response from the OpenAI language model.

Example Response

{ "llmResponse": "Hi there! How can I assist you today?" }

Error Handling

  • 400 Bad Request: Returned if the prompt field is missing in the request body.
  • 405 Method Not Allowed: Returned if any method other than POST or OPTIONS is used.
  • 500 Internal Server Error: Returned if there is an error processing the request.
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
ashryanio-openaiproxy.web.val.run
July 8, 2024