chatapi / README.md
subhrajit-mohanty's picture
initial commit
62de77b
|
raw
history blame
984 Bytes
metadata
title: Chatapi
emoji: 🔥
colorFrom: purple
colorTo: purple
sdk: docker
pinned: false
license: apache-2.0

How to Use the API using python

Create a Token

import requests

headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json',
}

json_data = {
    "ref_key": "F0eeQ419wvoCSPH7KBmsd9OiVkF0W0DxK1XE9T3BlbkFJ0",
    "expiry_date": "2023-06-15"
}

response = requests.post('http://0.0.0.0:8000/create', headers=headers, json=json_data)
token = response.json()

calling open API (text-davinci-002/gpt-3.5-turbo)

import requests

headers = {
    'accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': 'Bearer TOKEN',
}

json_data = {
    'message': 'write a joke for me',
    "openAI_token": OPENAI_KEY,
    "model_name" : "gpt-3.5-turbo"
}

response = requests.post('http://0.0.0.0:8000/chat', headers=headers, json=json_data)
if response.status_code == 200:
    print(response.json())