Learning to Write a Python SDK Library for ChatGPT API from OpenAI

After ChatGPT was released, OpenAI open-sourced the Python library openai-python for model invocation. This library is very comprehensive, encapsulating the APIs published by OpenAI, and is also very simple to use.

OpenAI-python library encapsulation

The first version of this library implemented Python abstract classes and invocation methods for parameter encapsulation of various ChatGPT APIs, using the requests and aiohttp libraries to send synchronous or asynchronous HTTP requests. Overall, the external interface is good and easy to use. The overall source code implementation has good logical abstraction, using many advanced Python features, and the code is beautifully written, worth learning from. But essentially, this is still “API boy“ work, more of repetitive manual labor without much technical content.

So, in November 2023, OpenAI began introducing Stainless, eliminating the need to manually write SDK code. Each time, they only need to provide API protocol updates, and then code can be automatically generated, freeing them from repetitive manual labor. Specifically, new code was introduced in Pull 677 and released as the official V1 version.

Read More

Blog Speed Optimization - CDN, Image Compression and HTTP2

I’ve been writing my personal blog for a while now. Previously, I was content as long as it was accessible, without much concern for speed. Recently, when accessing it myself, I felt that the page loading speed was quite slow, significantly affecting the experience. Moreover, slow loading also affects search engine rankings. So I set out to perform a series of optimizations on the blog to improve page loading speed. I encountered quite a few pitfalls along the way, which I’ll record in this article, hoping it will be helpful to others.

Personal Blog Web Page Loading Speed Optimization

Read More

A Glimpse into Black Hat SEO Business Through Peripheral Traffic Posts

Recently, while using Google search, I discovered that black hat traffic-generating content appeared on the first page of search results. My search keyword was “Shanghai to Nanjing network latency,” and the first page showed traffic-generating posts for escort services, as shown in the image below:

Black hat traffic-generating post

It’s worth noting that Google built its reputation on search technology, and its search results have always been highly accurate. The fact that black hat traffic-generating posts have appeared this time suggests that these operators have indeed found vulnerabilities in the SEO ranking algorithm and have effectively exploited them. Let’s try to guess how they’re doing it by looking at the search results.

Read More