Skip to content

A PHP DigitalOcean App Platform based port of jtsang4/claude-to-chatgpt; it adapts Anthropic's Claude API to match OpenAI's Chat API format.

License

Notifications You must be signed in to change notification settings

samestrin/claude-to-chatgpt-digitalocean

Repository files navigation

claude-to-chatgpt-digitalocean

Star on GitHub Fork on GitHub Watch on GitHub

Version 0.0.1 License: MIT Built with PHP

A PHP DigitalOcean App Platform based port of jtsang4/claude-to-chatgpt's cloudflare-worker.js. This project converts the API of Anthropic's Claude model to the OpenAI Chat API format.

DigitalOcean App Platform offers more resources than Cloudflare Workers and will be more performant in most use cases.

A Node.js port, designed to deploy on Netlify, is available samestrin/claude-to-chatgpt-netlify here.

Dependencies

  • PHP: Server-side scripting language (PHP 8.0 or later recommended).
  • nikic/fast-route: A fast request router for PHP, used for efficient routing of API requests.

Features

  • API Compatibility: Enables Claude model integration by mimicking the OpenAI ChatGPT API structure.
  • Streaming Support: Facilitates real-time interaction with the Claude model through streaming responses.
  • Model Flexibility: Supports various configurations of Claude models including claude-instant-1 and claude-2.
  • Performance Optimization: Utilizes the enhanced capabilities of DigitalOcean's infrastructure for improved performance over alternatives like Cloudflare Workers.

Deploy to DigitalOcean

Click this button to deploy the project to your DigitalOcean account:

Deploy to DO

DigitalOcean App Platform Setup

  1. Navigate to your project in the DigitalOcean App Platform.
  2. Go to the "Commands" section.
  3. Under "Run Command", enter the following:
heroku-nginx -C nginx.conf .

Endpoints

Chat Completion

Endpoint: /v1/chat/completions
Method: POST

Simulate ChatGPT-like interaction by sending a message to the Claude model.

Parameters

  • model: The OpenAI model (e.g., 'gpt-3.5-turbo') or Claude model (e.g.,'claude-instant-1') to use. (OpenAI models are automatically mapped to Claude models.)
  • messages: An array of message objects where each message has a role ('user' or 'assistant') and content.

Example Usage

Use a tool like Postman or curl to make a request:

curl -X POST http://localhost:[PORT]/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
    "model": "claude-instant-1",
    "messages": [
        {"role": "user", "content": "Hello, how are you?"}
    ]
}'

The server will process the request and return the model's response in JSON format.

Model Information

Endpoint: /v1/models
Method: GET

Retrieve information about the available models.

Example Usage

Use curl to make a request:

curl http://localhost:[PORT]/v1/models

The server will return a list of available models and their details in JSON format.

CORS Pre-flight Request

Endpoint: /
Method: OPTIONS

Handle pre-flight requests for CORS (Cross-Origin Resource Sharing). This endpoint provides necessary headers in response to pre-flight checks performed by browsers to ensure that the server accepts requests from allowed origins.

Example Usage

This is typically used by browsers automatically before sending actual requests, but you can manually test CORS settings using curl:

curl -X OPTIONS http://localhost:[PORT]/ \
-H "Access-Control-Request-Method: POST" \
-H "Origin: http://example.com"

The server responds with appropriate CORS headers such as Access-Control-Allow-Origin.

Options

This application can be configured with various options through environment variables:

  • CLAUDE_API_KEY: Your API key for accessing Claude API.
  • CLAUDE_BASE_URL: The endpoint URL for the Claude API.

Contribute

Contributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Share

Twitter Facebook LinkedIn

About

A PHP DigitalOcean App Platform based port of jtsang4/claude-to-chatgpt; it adapts Anthropic's Claude API to match OpenAI's Chat API format.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages