Create new API

This commit is contained in:
oobabooga
2023-04-06 00:42:13 -03:00
parent 9c3a585915
commit 3ac7c9c80a
2 changed files with 7 additions and 32 deletions

View File

@@ -36,6 +36,7 @@ async def run(context):
'early_stopping': False, 'early_stopping': False,
'seed': -1, 'seed': -1,
} }
payload = json.dumps([context, params])
session = random_hash() session = random_hash()
async with websockets.connect(f"ws://{server}:7860/queue/join") as websocket: async with websockets.connect(f"ws://{server}:7860/queue/join") as websocket:
@@ -54,22 +55,7 @@ async def run(context):
"session_hash": session, "session_hash": session,
"fn_index": 12, "fn_index": 12,
"data": [ "data": [
context, payload
params['max_new_tokens'],
params['do_sample'],
params['temperature'],
params['top_p'],
params['typical_p'],
params['repetition_penalty'],
params['encoder_repetition_penalty'],
params['top_k'],
params['min_length'],
params['no_repeat_ngram_size'],
params['num_beams'],
params['penalty_alpha'],
params['length_penalty'],
params['early_stopping'],
params['seed'],
] ]
})) }))
case "process_starts": case "process_starts":

View File

@@ -10,6 +10,8 @@ Optionally, you can also add the --share flag to generate a public gradio URL,
allowing you to use the API remotely. allowing you to use the API remotely.
''' '''
import json
import requests import requests
# Server address # Server address
@@ -38,24 +40,11 @@ params = {
# Input prompt # Input prompt
prompt = "What I would like to say is the following: " prompt = "What I would like to say is the following: "
payload = json.dumps([prompt, params])
response = requests.post(f"http://{server}:7860/run/textgen", json={ response = requests.post(f"http://{server}:7860/run/textgen", json={
"data": [ "data": [
prompt, payload
params['max_new_tokens'],
params['do_sample'],
params['temperature'],
params['top_p'],
params['typical_p'],
params['repetition_penalty'],
params['encoder_repetition_penalty'],
params['top_k'],
params['min_length'],
params['no_repeat_ngram_size'],
params['num_beams'],
params['penalty_alpha'],
params['length_penalty'],
params['early_stopping'],
params['seed'],
] ]
}).json() }).json()