Skip to content

Add AIstudioProxyAPIHelper support#67

Merged
CJackHwang merged 9 commits intoCJackHwang:devfrom
luispater:helper
May 18, 2025
Merged

Add AIstudioProxyAPIHelper support#67
CJackHwang merged 9 commits intoCJackHwang:devfrom
luispater:helper

Conversation

@luispater
Copy link
Contributor

Sorry for my Python code; I haven't written Python in about 12 years.

I added code to support AIstudioProxyAPIHelper

It's a MITM (Man-in-the-Middle) proxy server designed for AIstudioProxyAPI.

I created the Helper to sniff AI Studio responses, parse the response data, and convert it to an OpenAI Compatibility response format.

So, AIstudioProxyAPI can use this helper to get AI Studio responses in real-time, making it unnecessary to wait for the AI Studio UI anymore. And now, AIstudioProxyAPI can get reason data from AI Studio.

It also supports a secondary proxy for the Great Firewall.

CJackHwang and others added 8 commits May 10, 2025 04:52
Dev重构版本合并

是的 又重构了
优化 HTML 输出逻辑,增强对象和数组的格式化显示。通过使用 `<pre>` 和 `<code>` 标签,确保复杂数据结构在页面上以更易…
优化对话速度和缓存机制:
修复了3.0.0版本缓存机制的缺失
使用js填充加快长上下文对话速度
Replaced error yields with exceptions for improved debugging and clarity. Enhanced helper-based response generation with distinct handling for streaming and non-streaming requests, ensuring robust processing and proper response formatting.
Version constraints were removed from `requirements.txt` to allow flexibility with dependency updates. Additionally, an unused global variable declaration was removed from the `lifespan` function in `server.py` to improve code cleanliness.
@luispater
Copy link
Contributor Author

luispater commented May 18, 2025

Start the helper and run AIstudioProxyAPI with the command:

HTTP_PROXY=http://127.0.0.1:3120/ HTTPS_PROXY=http://127.0.0.1:3120/ python launch_camoufox.py --helper=http://127.0.0.1:3121/getStreamResponse --debug --internal-auth-file=active/auth_state_1746422325.json

@CJackHwang
Copy link
Owner

CJackHwang commented May 18, 2025

感谢 有空我解决一下冲突,适配新版本

@luispater
Copy link
Contributor Author

感谢 有空我解决一下冲突,适配新版本

It's ok, the Python code only needs a little change.
If you don't have much more free time, I can do it.
I'll create a new PR based on the new version.

By the way, I've added a new feature to support function calls. I suppose the API project can support function calls as soon as possible.

@CJackHwang
Copy link
Owner

CJackHwang commented May 18, 2025

感谢 有空我解决一下冲突,适配新版本

It's ok, the Python code only needs a little change.
If you don't have much more free time, I can do it.
I'll create a new PR based on the new version.

By the way, I've added a new feature to support function calls. I suppose the API project can support function calls as soon as possible.

Never mind, I'll do it myself, while I'm free now.

The new version of server.py tries to be compatible with function calls, but I haven't tested it yet. You can compare the difference between your plan and mine, and then make improvements. What do you think?

@CJackHwang CJackHwang changed the base branch from main to dev May 18, 2025 17:23
@luispater
Copy link
Contributor Author

感谢 有空我解决一下冲突,适配新版本

It's ok, the Python code only needs a little change.
If you don't have much more free time, I can do it.
I'll create a new PR based on the new version.
By the way, I've added a new feature to support function calls. I suppose the API project can support function calls as soon as possible.

Never mind, I'll do it myself, while I'm free now.

The new version of server.py tries to be compatible with function calls, but I haven't tested it yet. You can compare the difference between your plan and mine, and then make improvements. What do you think?

可以说中文,我只是觉得开源项目使用英文可以得到更多人的帮助。

Helper的v1.1.0版本对 function calls 已经实现完了,API这边只要可以正常提交function calls,那就基本上不用操心返回的问题了,Helper吐什么你直接输出就OK了,不过因为Helper只是Helper,你需要在Helper失效的情况下保持兼容,UI读取毕竟是最后一道防线。

使用Golang也是迫不得已,上次写Python还是12年前最后一份工作的事情,可读、可理解,但是上手写效率过低,Golang版本用了不到24小时写完调试完,当然还是要得益于各路AI的支持。😊

另外我就不重新修改代码发起PR了,我发现你们的效率挺高的,代码已经改的和上一个版本面目全非了。要改我要从新读一遍代码了。

我去体验一下新版本 function calls 的功能。

I'll use English next time. 😛

@CJackHwang
Copy link
Owner

感谢 有空我解决一下冲突,适配新版本

It's ok, the Python code only needs a little change.
If you don't have much more free time, I can do it.
I'll create a new PR based on the new version.
By the way, I've added a new feature to support function calls. I suppose the API project can support function calls as soon as possible.

Never mind, I'll do it myself, while I'm free now.
The new version of server.py tries to be compatible with function calls, but I haven't tested it yet. You can compare the difference between your plan and mine, and then make improvements. What do you think?

可以说中文,我只是觉得开源项目使用英文可以得到更多人的帮助。

Helper的v1.1.0版本对 function calls 已经实现完了,API这边只要可以正常提交function calls,那就基本上不用操心返回的问题了,Helper吐什么你直接输出就OK了,不过因为Helper只是Helper,你需要在Helper失效的情况下保持兼容,UI读取毕竟是最后一道防线。

使用Golang也是迫不得已,上次写Python还是12年前最后一份工作的事情,可读、可理解,但是上手写效率过低,Golang版本用了不到24小时写完调试完,当然还是要得益于各路AI的支持。😊

另外我就不重新修改代码发起PR了,我发现你们的效率挺高的,代码已经改的和上一个版本面目全非了。要改我要从新读一遍代码了。

我去体验一下新版本 function calls 的功能。

I'll use English next time. 😛

hahahaha我项目为什么全是中文呢?因为我怕英文会使得太国际化和受欢迎,容易引起google的注意,万一以后对我们做出了反制措施,甚至把aistudio网页对话的极大额度也取消了,那可能是一个很大的损失😊😊😊。
至于效率高是因为也是各路ai的支持。如果不是因为要上学,可能三天就几乎重构一次了哈哈哈

@CJackHwang CJackHwang merged commit b6b533d into CJackHwang:dev May 18, 2025
@CJackHwang
Copy link
Owner

CJackHwang commented May 18, 2025

I will try to use your helper program, and I will integrate it if I can.

@luispater
Copy link
Contributor Author

I have studied it for a long time, but I still can't figure out how to use it. I don't understand his mechanism. For example, once it was successfully forwarded in a very short time, but it was also reported that it could not be connected, which was almost the same time.

哦,原来是这样,也有点道理,那可以在这个项目中使用中文。

我解释一下工作原理:

  1. helper是个中间人攻击的代理服务器,所以首先要配置代理信息到helper的代理端口,端口默认是3120
  2. 因为API这边是依赖于网页的,所以中间人不能直接修改aistudio的response请求,所以使用3121端口的api的端点getStreamResponse,所以运行时的请求的流程是(附了脑图)
    1. api request
    2. camoufox request
    3. helper 3120 request aistudio
    4. aistduio response
    5. helper 3120 捕获 aistudio response
      1. 解压缩并分析aistudio response,放入内存,等待客户端获取
        1. api部分新增的helper代码
      2. 将原始aistudio response数据包返回
        1. camoufox
        2. api
          mind

因为helper自身要负责请求aistudio,如果无法连接,大概率是没有配置helper的代理服务器信息:
AIstudioProxyAPIHelper -proxy socks5://user:password@192.168.1.1:7654/

@luispater luispater deleted the helper branch May 20, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants