import json import requests Server address server = "127.0.0.1" Generation parameters…
- User
import json import requests
Server address
server = "127.0.0.1"
Generation parameters
Reference: https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.GenerationConfig
params = { 'max_new_tokens': 200, 'do_sample': True, 'temperature': 0.5, 'top_p': 0.9, 'typical_p': 1, 'repetition_penalty': 1.05, 'encoder_repetition_penalty': 1.0, 'top_k': 0, 'min_length': 0, 'no_repeat_ngram_size': 0, 'num_beams': 1, 'penalty_alpha': 0, 'length_penalty': 1, 'early_stopping': False, 'seed': -1, }
Input prompt
prompt = "What I would like to say is the following: "
payload = json.dumps([prompt, params])
response = requests.post(f"http://{server}:7861/run/textgen", json={ "data": [ payload ] }).json() reply = response["data"][0] print(reply)
I'm getting this error: (llm) I:\AI-TOOLS\LLM\Auto-Ooba>python request_test.py Traceback (most recent call last): File "I:\AI-TOOLS\LLM\Auto-Ooba\request_test.py", line 38, in reply = response["data"][0] ~~~~~~~~^^^^^^^^ KeyError: 'data'
- Assistant
It seems the response from the server doesn't contain the "data" key, which is causing the KeyError. To debug this issue, you can print the entire server response to check its content.
Here's an updated version of the code that prints the server response:
import json import requests # Server address server = "127.0.0.1" # Generation parameters # Reference: https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.GenerationConfig params = { 'max_new_tokens': 200, 'do_sample': True, 'temperature': 0.5, 'top_p': 0.9, 'typical_p': 1, 'repetition_penalty': 1.05, 'encoder_repetition_penalty': 1.0, 'top_k': 0, 'min_length': 0, 'no_repeat_ngram_size': 0, 'num_beams': 1, 'penalty_alpha': 0, 'length_penalty': 1, 'early_stopping': False, 'seed': -1, } # Input prompt prompt = "What I would like to say is the following: " payload = json.dumps([prompt, params]) response = requests.post(f"http://{server}:7861/run/textgen", json={ "data": [ payload ] }).json() print("Server response:", response) # Print the server response if "data" in response: reply = response["data"][0] print("Generated text:", reply) else: print("The 'data' key is missing from the server response") - User
'This app has no endpoint /api/textgen/.'
- Assistant
It seems that the server does not have the
/api/textgen/endpoint available, which is why the response does not contain the expected data.Please make sure that the server you're connecting to is running the correct application and that the specified endpoint exists. If you have control over the server-side code, you can check if the right route for text generation is defined.
Alternatively, if you're using someone else's server or a public API, consult their documentation to find the correct endpoint for text generation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.