Coder Social home page Coder Social logo

aki-api's Introduction

NOTE: This is a research project. Please do not use it commercially and use it responsibly.


WebAI to API

This project implements a web API that offers a unified interface to ChatGPT, Google Gemini, and Claude 3.

Key Features

  • Unified API: Single integration to query ChatGPT, Gemini, and Claude. No juggling multiple APIs.

  • Conversational interface: Text completion, QA, discussions. Put advanced AI to work immediately.

  • Self-hosted: Python/FastAPI enables flexibility to run anywhere. Not locked into proprietary platforms.

  • Streaming support: Real-time responses from ChatGPT and Gemini. Claude streaming coming soon.

  • Lightweight and scalable: Built with FastAPI for high performance.

Status

Google Gemini Web to API integration available now.

Claude-3 Web to API integration is also fully implemented and available.

ChatGPT Web to API integration is fully complete and available now.

ChatGPT to Claude, The new adapter connects the ChatGPT API to Claude. Developers can now build apps using the ChatGPT API to get Claude's AI responses.

🔜 ChatGPT to Gemini, Get ready for next chapter


Image


This repository is up-to-date.
Please don't forget to give a Star ⭐




Prerequisites

Python version >= 3.10

Before using the APIs, sign up for free accounts to get access credentials if you don't already have them:

Then, add your token(s) to the Config.conf file. (see Configuration section).


Note: Claude and Gemini offer Auto Login options - you can either log in through your browser and skip this step.


Installation


Step 1. Clone Repository

git clone https://github.com/Amm1rr/WebAI-to-API.git && cd WebAI-to-API

python -m venv .venv

source .venv/bin/activate  # Linux/macOS
.venv\Scripts\activate     # Windows


pip install -r requirements.txt

Step 2. Start Web Server

Navigate into the src directory, and run the web server:

cd src/

python main.py

Now the API documentation should be available at the following address:

http://127.0.0.1:8000/docs

Available Endpoints:

#---------- Google Gemini

http://127.0.0.1:8000/gemini


#---------- Claude

http://127.0.0.1:8000/claude


#---------- ChatGPT

http://127.0.0.1:8000/chatgpt


#---------- OpenAI ChatGPT JSON Response

http://127.0.0.1:8000/v1/chat/completions


#---------- Claude -> ChatGPT JSON Response

http://127.0.0.1:8000/claude/v1/chat/completions



Input / Output

# Input:
_____

    {
      "message": "Hi, Who are you?",
      "stream": true
    }


--------------------


# Output:
_____

    {
      I am a Chatbot assistant :)
    }


--------------------


# OpenAI Response Output:
_____

# Streaming
  {
    "id": "chatcmpl-123",
    "object": "chat.completion.chunk",
    "created": 1677652288,
    "model": "gpt-3.5-turbo",
    "choices": [{
      "index": 0,
      "delta": {
        "content": "Hello",
      },
      "finish_reason": "stop"
    }]
  }


# Not Streaming
  {
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "model": "gpt-3.5-turbo",
    "choices": [{
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "\n\nHello there, how may I assist you today?",
      },
      "finish_reason": "stop"
    }]
  }




Example

Once you have launched the web server using src\python main.py:

Note: The first argument to run the example determines whether to return streaming or not.

cd examples/


python example_claude.py false
python example_claude.py true

python example_bard.py false
python example_bard.py true

python example_chatgpt1.py false
python example_chatgpt1.py true

python example_chatgpt2.py false
python example_chatgpt2.py true

or try Claude with cURL

run this cURL command in a terminal window:

curl -X 'POST' \
  'http://localhost:8000/claude' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "message": "who are you?",
  "stream": false
}'

Note: The session_id is configured in the Config.conf file. If you send this variable empty, it will use the Config.conf



Usage

How to Find Your Tokens

Note: Claude and Gemini offer two authentication options - you can either log in through your browser and skip this step, or you can follow the instructions below to configure the authentication.

Important: "The auto login by browser issue is caused by using multiple accounts or browser profiles. It will take some time to fully resolve. A future update will address it. For now, if you have problems logging in with your browsers, try logging in with just one browser or manually copy sessions and cookies as a workaround, as described in the instructions below."


First you need to add your tokens to the Config.conf file (see Configuration section).


Gemini

Image

Method 1:
For Gemini, all you need to do is login to your account using your web browser. (Firefox, Chrome, Safari, Edge...)

Method 2:
Google Gemini: Please obtain the cookies mentioned here from an authorized session on gemini.google.com. The cookies can be used to send POST requests to the /gemini endpoint along with a message in a JSON payload. It is important that the session_id, which is your __Secure-1PSID cookie, and the session_idts and session_idcc, which is your Secure-1PSIDTS and Secure-1PSIDCC cookie, are included in the request. (Screenshot)

Name Session Name
session_id __Secure-1PSID
session_idts __Secure-1PSIDTS
session_idcc __Secure-1PSIDCC
  1. Login to gemini.google.com
  2. Open Developer Tools (Press F12)
  3. Go to Application Tab
  4. Go to Cookies Tab
  5. Copy the content of __Secure-1PSID and __Secure-1PSIDTS and __Secure-1PSIDCC. Copy the value of those cookie.
  6. Set in Config.conf file.



Claude

Image

Method 1:
For Claude, all you need to do is login to your account using your web browser. (Firefox, Chrome, Safari, Edge...)

Method 2:
Claude: You can get cookie from the browser's developer tools network tab ( see for any claude.ai requests check out cookie ,copy whole value ) or storage tab ( You can find cookie of claude.ai ,there will be four values ) (Screenshot)

  1. Login to claude.ai
  2. Open Developer Tools (Press F12)
  3. Go to Network Tab
  4. Select an ajax request (like step 3 in picture)
  5. Copy the content of Cookie
  6. Set in Config.conf file.




ChatGPT

Image

ChatGPT: Please obtain the sessions mentioned here from an authorized session on chat.openai.com. The sessions can be used to send POST requests to the /chatgpt endpoint along with a message in a JSON payload. It is important that the session_id, which is your Authorization header session, is included in the request. (Screenshot)

  1. Login to chat.openai.com
  2. at least ask any question.
  3. Open Developer Tools (Press F12)
  4. Go to Network Tab
  5. Select an ajax request (like step 4 in picture)
  6. Copy the content of Authorization
  7. Set in Config.conf file.



Configuration

How to Find Your Tokens

Note: Claude and Gemini present Auto Login options - logging in through your browser or configuring Claude and Gemini using the provided config file.

Config File Path:

  • WebAI-to-API\src\Config.conf
# Case-Sensative

[Claude]
COOKIE=[YOURS]

[Gemini]
SESSION_ID=[YOURS]
SESSION_IDTS=[YOURS]
SESSION_IDCC=[YOURS]

[ChatGPT]
ACCESS_TOKEN=[YOURS]


Licensing

This project is licensed under the MIT License. Feel free to use it however you like.


aki-api's People

Contributors

pctechkid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.