# Posts too long for PostSentimentAnalysis

**URL:** https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532
**Category:** Support
**Tags:** ai
**Created:** [September 14, 2024, 11:00pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532 "2024-09-14T23:00:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [September 14, 2024, 11:00pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/1 "2024-09-14T23:00:31Z")

</div>

After enabling sentiment analysis using OpenAI, my error log is filled with

```plaintext
Job exception: Net::HTTPBadResponse

```

Then in Sidekiq:

```plaintext
Jobs::PostSentimentAnalysis
Jobs::HandledExceptionWrapper: Wrapped Net::HTTPBadResponse: Net::HTTPBadResponse

```

Looking at the post\_ids in question, it seems the issue is likely caused by the unusually long posts. Otherwise, the sentiment graphs generate without any problems.

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [September 15, 2024, 7:26am UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/2 "2024-09-15T07:26:42Z")

</div>

I didn’t know the sentiment analysis can be used thru OpenAI 🤔

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [September 15, 2024, 2:59pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/3 "2024-09-15T14:59:27Z")

</div>

To add more information, I’ve got `Number of tokens for the prompt` set according to the recommendation (64000 which is 50% of 128K context window). But I’m not sure if this plays any role..

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [September 15, 2024, 3:27pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/4 "2024-09-15T15:27:44Z")

</div>

No it doesn’t, because then you would get different error. What you get is exacly what it sound, wrong status code.

How did you set yp sentinent analysis using GPT of OpenAI?

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [September 15, 2024, 3:51pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/5 "2024-09-15T15:51:16Z")

</div>

The error message isn’t exactly descriptive. I don’t even know the exact HTTP code.

> <https://github.com/discourse/discourse-ai/blob/b16390ae2acf4285bb6384491dd09ec988feea4d/lib/inference/discourse_classifier.rb#L14C1-L15C1>

The culprit is clear, it has something to do with a post length. In that case OpenAI API returns 400 Bad Request.

> [@Jagster](#):
>
> How did you set yp sentinent analysis using GPT of OpenAI?

You just enable the module ` ai sentiment enabled` and it works as long as you have LLM model parameters entered.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [September 15, 2024, 7:46pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/6 "2024-09-15T19:46:25Z")

</div>

> [@Overgrow](#):
>
> I’ve got `Number of tokens for the prompt` set according to the recommendation (64000 which is 50% of 128K context window).

I’ve experimented with setting as low as 10,000 tokens and no improvement. `Net::HTTPBadResponse` is still filling my error log.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 15, 2024, 10:12pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/7 "2024-09-15T22:12:32Z")

</div>

Can you share a screenshot of your exact config, and your llm config.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [September 16, 2024, 11:07pm UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/8 "2024-09-16T23:07:19Z")

</div>

Sure, here are the settings

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/0/7/f0784f1a9af46fa8aeceeced58843172d6f0a479.png)  
 ![The image displays a computer screen with a setup for an AI model, featuring settings for integration, personal accounts, tools, and a back button. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/b/b/d/bbdcd6beb7416edb9a3dece77a1f831feec58292.png)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [September 21, 2024, 2:52am UTC](https://meta.discourse.org/t/posts-too-long-for-postsentimentanalysis/326532/9 "2024-09-21T02:52:06Z")

</div>

> [@Overgrow](#):
>
> After enabling sentiment analysis using OpenAI, my error log is filled with

There is no sentiment analysis feature via OpenAI in DiscourseAI. Please follow [Discourse AI - Self-Hosted Guide](https://meta.discourse.org/t/discourse-ai-self-hosted-guide/259598#sentiment-6) if you want to run it locally.
