<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muhammad Ibrahim on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Ibrahim on Medium]]></description>
        <link>https://medium.com/@mibrahim2001?source=rss-1548afdcdad0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YrZkZPrgUN122PgW16zsQA.png</url>
            <title>Stories by Muhammad Ibrahim on Medium</title>
            <link>https://medium.com/@mibrahim2001?source=rss-1548afdcdad0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:00:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mibrahim2001/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Open AI Assistant Can Make You Bankrupt]]></title>
            <link>https://medium.com/@mibrahim2001/open-ai-assistant-can-make-you-bankrupt-cb5c64f15bfe?source=rss-1548afdcdad0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb5c64f15bfe</guid>
            <category><![CDATA[open-ai-api]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatbot-development]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[assistants-api]]></category>
            <dc:creator><![CDATA[Muhammad Ibrahim]]></dc:creator>
            <pubDate>Mon, 13 May 2024 11:59:33 GMT</pubDate>
            <atom:updated>2024-05-13T12:00:56.146Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Open AI Can Make You Bankrupt</strong></h3><figure><img alt="ai making the business man bankrupt" src="https://cdn-images-1.medium.com/max/1024/1*01zMa8f4tQi8N-M6wIFioA.jpeg" /></figure><p>Yes, you read that right if you don’t use the Assistants API provided by Open AI carefully your money can vanish quickly. <br> <br>Recently, I had to use Open AI Assistant to create a discord bot for a client. The Assistants API is really helpful as it can manage and store the context on its own, eliminating the need for a database and keeping the context in one place. Additionally, it has other impressive features such as Code Interpreter, File Search, and Function calling.</p><p><strong>How does this work? </strong><br> <br>The assistant uses a concept called <strong><em>“thread”</em></strong> that is similar to the conversations in ChatGPT. Just like each conversation in ChatGPT holds the context of that conversation, the thread also holds the context of the conversation between the user and the assistant. Additionally, we can add instructions and files to ensure that the response is tailored to the data we provide to the bot. This is particularly useful when creating a customer support chatbot, which can answer simple, repetitive questions.</p><p>Everything seems to be going well so far, right? Open AI is taking care of the context and data for us, among other things. However, I discovered that if we don’t control the size of the <strong>context window </strong>for each thread manually. The assistant automatically manages this, and it’s only restricted by the token size of the model being used.<br><br>For instance, if you use GPT-4 Turbo with a context size of 128,000 tokens and you have a lot of messages in the thread, each response could cost <strong>over $1</strong>. Now that’s a lot and can add up quickly.</p><p><strong>Let’s do some maths</strong></p><p>Price of GPT-4 Turbo = US$10.00 / 1M tokens<br>Price of processing 100k input tokens = $1</p><h3><strong>Solution:</strong></h3><p>OpenAI has recently made some updates to its run endpoint, which allows users to manage context windows using two parameters — max completion and max prompt tokens.</p><p>To give an example, if a Run is initiated with <em>max_prompt_tokens</em> set to 500 and <em>max_completion_tokens</em> set to 1000, it means that the first completion will limit the thread to 500 tokens and the output to 1000 tokens. If only 200 prompt tokens and 300 completion tokens are used in the first completion, the second completion will have limits of 300 prompt tokens and 700 completion tokens available.</p><p>If a completion reaches the <em>max_completion_tokens</em> limit, the Run will terminate with a status of incomplete, and details will be provided in the <em>incomplete_details</em> field of the Run object.</p><p><strong>But,</strong><br>If you’re using the <strong>File Search tool</strong>, you might encounter a problem due to token limitations that can result in incomplete completion of the run. Open AI suggests setting the max_prompt_tokens to no less than 20,000 when using the File Search tool. If you plan on having longer conversations or more interactions with File Search, it’s recommended to increase this limit to 50,000. For the best possible results, it’s suggested to <strong>remove the max_prompt_tokens</strong> limit altogether.</p><p>For this scenario, it would be better to use the <strong>Truncation Strategy</strong>. You can specify a truncation strategy to determine how your thread should be displayed in the model’s context window.</p><p>If you choose a truncation strategy of type <em>“auto”</em>, the default truncation strategy of OpenAI will be used. Alternatively, by selecting a truncation strategy of type <strong><em>“last_messages”</em></strong>, you can specify the number of recent messages to be included in the context window. <br> <br>More details about these parameters can be found here, <a href="https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-max_prompt_tokens">https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-max_prompt_tokens</a>.</p><p>In summary, while OpenAI’s Assistants API offers valuable features, it’s essential to watch out for costs. Without careful management, expenses can pile up fast, especially with large context sizes. Thankfully, recent updates allow for better control using parameters like max completion and max prompt tokens. So, by staying vigilant and using these tools wisely, you can make the most of OpenAI without breaking the bank.</p><h3>Follow me</h3><ul><li><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/ibrahim-dev/">ibrahim-dev</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb5c64f15bfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are the benefits of using custom hooks in React Native?]]></title>
            <link>https://medium.com/@mibrahim2001/what-are-the-benefits-of-using-custom-hooks-in-react-native-a92f657d0733?source=rss-1548afdcdad0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a92f657d0733</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks-state]]></category>
            <dc:creator><![CDATA[Muhammad Ibrahim]]></dc:creator>
            <pubDate>Sat, 22 Oct 2022 14:25:59 GMT</pubDate>
            <atom:updated>2022-10-22T14:29:29.635Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W9GwzLNbcFoJ9ftXxj0-Ag.png" /></figure><p>If you work with react you must have listened or read the word custom hook. What really are custom hooks? Let&#39;s find out today.</p><p>Custom Hooks are <strong>a mechanism to reuse stateful logic</strong> (such as setting up a subscription and remembering the current value), but every time you use a custom Hook, all states and effects inside of it are fully isolated.</p><p>Custom Hooks help us separate the UI and Business logic for our app. This is known as separation of concern.</p><h4><strong><em>Separation of concerns:</em></strong></h4><p>is a software architecture design pattern/principle for separating an application into distinct sections, so each section addresses a separate concern. At its essence, Separation of concerns is about order. The overall goal of separation of concerns is to establish a well-organized system where each part fulfills a meaningful and intuitive role while maximizing its ability to adapt to change.</p><h4>Why to use custom hooks?</h4><p>Custom hooks are useful in many ways but following are some advantages of custom hooks:</p><ul><li>It revolutionizes the way you write components</li><li>You can write concise and clearer code.</li><li>Hooks are simpler to work with and test. Code would appear cleaner and easier to read.</li><li>A related logic could be tightly coupled inside a custom hook<strong>.</strong></li><li>It simplifies how to make code more composable and reusable.</li><li>Unlike HOCs, they don’t create another element in DOM.</li><li>Hooks would work more efficiently with the future React optimizations. For example, it would work ahead of time compilation as well as components folding.</li><li>Components folding may be implemented in the future. It suggests that for code elimination at compile-time, hooks are simple to reuse the stateful logic.</li></ul><h4>How are custom hooks used?</h4><p>You can make your very own custom hook by using the very popular functional component in react. Just declare a functional component and return the variables you want to use in your UI and perform all the logical operations on the variables in your custom hook functional component.</p><p>Here is an example of a hook made to do GET API call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c80ff33b3f747d812555897169848a2f/href">https://medium.com/media/c80ff33b3f747d812555897169848a2f/href</a></iframe><p>And here is an example of how to use this hook to fetch the data in another component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c68fdeb140f45623d5d9140e2039e3e/href">https://medium.com/media/6c68fdeb140f45623d5d9140e2039e3e/href</a></iframe><p>That is all from my side. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a92f657d0733" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>