# I am unable to adjust the generated text length

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%3E%5C
**Category:** Beginners\
**Created:** [September 25, 2024, 12:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583 "2024-09-25T12:28:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoMoney03](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@NoMoney03](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNoMoney03)%5C
**Post date:** [September 25, 2024, 12:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F1 "2024-09-25T12:28:30Z")

</div>

The text I am generating from a prompt is less than 80 words even with parameters. What am I doing wrong?

````async
	const response = await fetch(
		"/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fmeta-llama%2FMeta-Llama-3-8B-Instruct",
    
		{
			headers: {
				Authorization: `Bearer ${hfToken}`,
				"Content-Type": "application/json",
			},
			method: "POST",
			body: JSON.stringify(data),
      
		}
	);
	const result = await response.json();
	return result;
}

query({"inputs": "What did the US markets looked in august 2024?", parameters: { 
  "max_length": 200}}).then((response) => {
  console.log(JSON.stringify(response));
});```
````

---

<div class="post-metadata">

**Author:** ![NoMoney03](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@NoMoney03](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNoMoney03)%5C
**Post date:** [September 25, 2024, 12:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F2 "2024-09-25T12:32:05Z")

</div>

I followed this solution [How to set minimum length of generated text in hosted API - #2 by Narsil](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-set-minimum-length-of-generated-text-in-hosted-api%2F3893%2F2). But this is from 2021, has there been any change in the method. I may have missed it in the documentation if it exists, but I didn’t see anything so far.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [September 25, 2024, 3:21pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F3 "2024-09-25T15:21:27Z")

</div>

> “max\_length”: 200

Not sure if it’s because of this option, but isn’t 200 too short? If you’re having trouble with the content, you’ll usually get better results if you don’t specify the option. Also, changing the model may work fine.

---

<div class="post-metadata">

**Author:** ![NoMoney03](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@NoMoney03](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNoMoney03)%5C
**Post date:** [September 25, 2024, 3:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F4 "2024-09-25T15:41:37Z")

</div>

I set to 1 and then set it to 2000, there was no difference in length in either case.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [September 25, 2024, 3:45pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F5 "2024-09-25T15:45:01Z")

</div>

Maybe it’s the max\_tokens you should be setting?

> **[Inference](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client#huggingface_hub.InferenceClient.chat_completion)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![NoMoney03](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@NoMoney03](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNoMoney03)%5C
**Post date:** [September 25, 2024, 4:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F6 "2024-09-25T16:16:47Z")

</div>

No, still did not work.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [September 25, 2024, 4:30pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F7 "2024-09-25T16:30:08Z")

</div>

> **[Chat Completion](https://huggingface.co/docs/api-inference/tasks/chat-completion?code=js)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Well, I can read JavaScript at least, but I’m not used to it. Try to follow this newish sample, which is very different even from 2023 and 2024, with OpenAI compatibility and the recommendation of InferenceClient / AsyncInferenceClient over simple POST requests.

---

<div class="post-metadata">

**Author:** ![NoMoney03](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@NoMoney03](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FNoMoney03)%5C
**Post date:** [September 26, 2024, 11:16am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F8 "2024-09-26T11:16:53Z")

</div>

Okay, so I did found something that worked (sort of).

```auto
query({"inputs": "What did the US markets looked in august 2018?", parameters: { 
  max_new_tokens: 400, return_full_text : true}}).then((response) => {
  console.log(JSON.stringify(response));

```

I added the `return_full_text : true` and I started getting longer generated texts however, if I increase the `max_new_tokens: 400` to anything above 400, it gives the error,  
`{"error":"Model too busy, unable to get response in less than 60 second(s)"}`.

So this is where I am now.

Also I tried using different models, some worked but some of them were cold, so therefore I added wait-for-model.

```auto
				Authorization: `Bearer ${hfToken}`,
				"Content-Type": "application/json",
        "x-wait-for-model": "true"
			}, 

```

But the model never loaded, after some time I got a timeout error.

Honestly a breeze working with AI. /s

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [September 26, 2024, 11:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fi-am-unable-to-adjust-the-generated-text-length%2F108583%2F9 "2024-09-26T11:43:36Z")

</div>

As you know, the models are much bigger this year than last year. Therefore, many of them are no longer usable because the servers and internal programs for the Serverless Inference API have not been able to keep up. Now, if it says “warm” on it, it’s just about usable.  
For commercial services, I guess you can use the Endpoint API, but for personal hobbies, it’s a lot of work.  
We have to kind of, well, search by hand for a configuration that the server will answer to.
