CNSeniorious000 / free-chat

An elegant LLM chat UI forked from chatgpt-demo of @anse-app. Index site at https://free-chat.asia
https://endless-chat.vercel.app
MIT License
177 stars 52 forks source link

Sweep(slow): count tokens on the server side #17

Open CNSeniorious000 opened 10 months ago

CNSeniorious000 commented 10 months ago

Details

在 src/pages/api/generate.ts 中加上和 src/components/Generator.tsx 中一样的裁剪 messages 的逻辑: 但是注意:服务端用不了 tiktoken 库,只能用 tiktoken-js 库,他们应该有类似的 interface

Checklist - [X] Create `src/utils/tiktoken-server.ts` ✓ https://github.com/CNSeniorious000/free-chat/commit/09d72442ebe25ea72693afd406fe601d703d1b27 - [X] Running GitHub Actions for `src/utils/tiktoken-server.ts` ✓ - [X] Modify `src/pages/api/generate.ts` ✓ https://github.com/CNSeniorious000/free-chat/commit/30a5ea4d0bdc06e092563c96327c3e11eeb3cff2 - [X] Running GitHub Actions for `src/pages/api/generate.ts` ✓ ![Flowchart](https://raw.githubusercontent.com/CNSeniorious000/free-chat/sweep/assets/af2844339ca9a1866f4f16217294aea5a3ca95949e1b67b7c2151d232b872674_17_flowchart.svg)
sweep-ai[bot] commented 10 months ago

Here's the PR! https://github.com/CNSeniorious000/free-chat/pull/20.

Sweep Basic Tier: I'm using GPT-4. You have 4 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 1bfb7247a1)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for 117c9ef
Checking src/pages/api/generate.ts for syntax errors... ✅ src/pages/api/generate.ts has no syntax errors! 1/1 ✓
Checking src/pages/api/generate.ts for syntax errors...
✅ src/pages/api/generate.ts has no syntax errors!

Sandbox passed on the latest endless, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/CNSeniorious000/free-chat/blob/117c9ef603e6b267a13c3b7c633fcb86624dbef8/src/components/Generator.tsx#L1-L19 https://github.com/CNSeniorious000/free-chat/blob/117c9ef603e6b267a13c3b7c633fcb86624dbef8/src/pages/api/generate.ts#L1-L15 https://github.com/CNSeniorious000/free-chat/blob/117c9ef603e6b267a13c3b7c633fcb86624dbef8/src/components/Generator.tsx#L217-L260 https://github.com/CNSeniorious000/free-chat/blob/117c9ef603e6b267a13c3b7c633fcb86624dbef8/src/utils/tiktoken.ts#L1-L38

Step 2: ⌨️ Coding

Ran GitHub Actions for 09d72442ebe25ea72693afd406fe601d703d1b27:
• Vercel Preview Comments:

Ran GitHub Actions for 30a5ea4d0bdc06e092563c96327c3e11eeb3cff2:
• Vercel Preview Comments:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/server-side-token-counting_1.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord