Low quality text production in API

I sent a topic on the chatgpt site to the free version of chatgpt-3.5, it gave me a very accurate and complete answer.
But I sent the same title to ChatGPT-3.5-Turbo API, it gave me a short and low-quality response. I was completely disappointed!

I used the code below. I did not use the previous chats because I only sent the same text on the main site

[
    'model' => 'gpt-3.5-turbo',

    'messages' => [
        [
            'role' => 'user',
            'content' => 'Give me complete explanations about Clean Code book
The author of the book is Robert Martin
Please make this description very complete and accurate, at least 700 words, produced based on the principles of SEO, and like an article, put the texts in html tags, such as heading and paragraph tags, etc.'
        ],
    ],
    'temperature' => 0.7,
    'max_tokens' => 3600,
    'frequency_penalty' => 0.0,
    'presence_penalty' => 0.0,
]

Is there a solution to this issue? I need the same texts that are produced on the ChGPT site.

1 Like

I’d try raising your temperature to 1.0… and add a relevant system role prompt… (IF the exact prompt is doing okay on ChatGPT free…) Good luck.

1 Like

Again, the result did not change. Is there a better solution?

What did you use as a system prompt? Did you add one? Or just temp?

I used the following code:

    [
        'model' => 'gpt-3.5-turbo',
    
        'messages' => [
            [
                "role" => "system",
                "content" => '
    You are a helpful assistant who provides a detailed description of the book in the form of an article of at least 700 words, following the principles of SEO.            
                '
            ],
            [
                'role' => 'user',
                'content' => '
                    Give me complete explanations about Clean Code book
                    The author of the book is Robert Martin
                '
            ],
        ],
        'temperature' => 0.1,
        'max_tokens' => 3600,
        'frequency_penalty' => 0.0,
        'presence_penalty' => 0.0,
    ]

I would work on your system prompt AND the user prompt.

You might try using GPT-4 via ChatGPT or Playground to formulate a better prompt based on what you’re wanting. Also, there might not be information available about every book you throw at it, so it might hallucinate (ie make up facts…)

And for temperature I wrote 1.0 not 0.1 …

You can’t simply send a user role message alone and expect quality. You must also send a system prompt that programs the purpose of the AI. I just did such a write up for you and will show it below that quality = quality out.

Temperature can be left as creative as =1 if one reduces the top_p API parameter to remove low probability words at the edge of likelihood, such as a setting =0.80.

Programming, and set to max_tokens = 3500

System Message:

You are ChatComplete, a large language model transformer AI product by OpenAI, and you are purposed with satisfying user requests and questions with very verbose and fulfilling answers beyond user expectations in writing quality. Generally you shall act as a writing assistant, and when a destination medium is not specified, assume that the user would want six typewritten pages of composition about their subject of interest. Follow the users instructions carefully to extract their desires and wishes in order to format and plan the best style of output, for example, when output formatted in forum markdown, html, LaTeX formulas, or other output format or structure is desired.

user message:

Writing assignment: Please write a full-featured online technical magazine article in HTML that provides complete coverage and analysis of this subject: Clean Code, by Robert Martin (book overview, lessons within, and conclusions; reviews and application of material).
Article structure: Multipart, using sections and delineated subtopics to direct the reader clearly to different points of analysis in the article.
AI output format: HTML markup, using all base HTML container elements to make an article that can be styled by website CSS.

AI response

Note: (which is formatted and inline-styled with HTML, some of which won’t be used in the forum:

<!DOCTYPE html>
<html>
<head>
  <title>Clean Code by Robert Martin - A Comprehensive Analysis</title>
  <style>
    /* CSS styles for the article */
    body {
      font-family: Arial, sans-serif;
      margin: 20px;
    }

    h1 {
      font-size: 24px;
      margin-bottom: 10px;
    }

    h2 {
      font-size: 20px;
      margin-bottom: 10px;
    }

    p {
      margin-bottom: 15px;
    }

    .section {
      margin-bottom: 30px;
    }

    .subsection {
      margin-bottom: 20px;
    }

    .quote {
      font-style: italic;
      margin-left: 20px;
    }
  </style>
</head>

Clean Code by Robert Martin - A Comprehensive Analysis

Introduction

In his book "Clean Code," Robert Martin provides valuable insights into writing high-quality code that is readable, maintainable, and efficient. This article aims to provide a comprehensive overview of the book, highlighting its key lessons and drawing conclusions about its significance in the field of software development.

Book Overview

"Clean Code" is divided into several chapters, each focusing on a specific aspect of writing clean code. The book starts by explaining the importance of clean code and the impact it has on the success of software projects. It then delves into practical techniques and principles that can be applied to achieve clean code.

Throughout the book, Martin emphasizes the significance of writing code that is easy to understand, refactoring existing codebases, and ensuring that each function, class, and module has a single responsibility. He provides numerous examples and case studies to illustrate his points and make the concepts more tangible.

Lessons within "Clean Code"

1. Meaningful Names

One of the key lessons from the book is the importance of choosing meaningful names for variables, functions, and classes. Martin emphasizes that code should be self-explanatory and easily understandable, without the need for extensive comments. By using descriptive names, developers can make their code more readable and reduce the cognitive load for anyone who reads or maintains it.

2. Functions and Classes

Another crucial aspect discussed in the book is the design of functions and classes. Martin advocates for functions that are short, focused, and do one thing well. He encourages developers to avoid long, convoluted functions that are difficult to understand and maintain. Similarly, he emphasizes the importance of classes that have a single responsibility and follow the SOLID principles of object-oriented design.

3. Code Formatting

The book also covers the significance of code formatting and consistency. Martin argues that consistent formatting improves readability and reduces the chance of introducing bugs. He suggests following a set of agreed-upon formatting guidelines within a development team to ensure a uniform code style throughout a project.

Conclusions

"Clean Code" provides a wealth of knowledge and practical advice for developers striving to write clean and maintainable code. By following the principles outlined in the book, developers can improve the readability, maintainability, and overall quality of their codebases.

It is important to note that the principles presented in "Clean Code" are not strict rules but rather guidelines. Each project and team may have unique requirements and circumstances that should be taken into account. However, the book offers valuable insights and a framework for thinking about code cleanliness that can be adapted to various contexts.

Reviews and Application of Material

"Clean Code" has received widespread acclaim from the software development community. Many developers and industry experts consider it a must-read for anyone involved in writing code. The book's practical examples and clear explanations make it accessible to both novice and experienced programmers.

The concepts and techniques presented in "Clean Code" can be applied to any programming language or technology stack. By adhering to the principles outlined in the book, developers can improve their coding skills and contribute to the creation of more robust and maintainable software.

Several companies and organizations have adopted the principles of "Clean Code" as part of their development practices. By emphasizing code cleanliness and readability, these companies have witnessed improved collaboration, reduced maintenance costs, and increased overall productivity.

2 Likes

Now the following error occurred:

object(stdClass)#10 (1) { ["error"]=> object(stdClass)#9 (4) { ["message"]=> string(189) "This model's maximum context length is 4097 tokens. However, you requested 4285 tokens (785 in the messages, 3500 in the completion). Please reduce the length of the messages or completion." ["type"]=> string(21) "invalid_request_error" ["param"]=> string(8) "messages" ["code"]=> string(23) "context_length_exceeded" } }

Let’s carefully analyze this message.

This model’s maximum context length is 4097 tokens.

An AI model has a maximum number of tokens of storage in a special area for both accepting input and formulating answers. That is its RAM memory, if you will.

However, you requested 4285 tokens

Oops, you want more tokens than the model allows? How can that be?

785 in the messages,

Oh, we see your language consumes a bit more than mine, that’s about 500 words (or maybe less words in under-represented world languages)

3500 in the completion

That’s how much of the space you reserved with max_tokens exclusively for generating an answer. I already calculated how big my input was, so could set that large setting (typically 1500 for a chatbot).

What should you do?

Please reduce the length of the messages or completion.

Actually, what you can do is remove max_tokens entirely, and then all the remaining area can be used for writing a response, without needing to make calculations.

1 Like

Everything is fine now, but there is a problem:

When I send the text to the artificial intelligence to generate the text in HTML format for publication on the website, it says in the text that this text was generated by the artificial intelligence for the website in the artificial intelligence format.

I do not want to reveal this information. Is there a solution to this?

If it’s not in your html code, and the AI didn’t write it’s own warning, then the site is doing some kind of automatic scanning.

If it is in the text? You can likely prompt that away if it is a habit, although it is also OpenAI policy to not pass of AI text as human.

You can set top_p back to 1, and turn up the temperature, so you get really unlikely word choices.