-
Notifications
You must be signed in to change notification settings - Fork 814
feat(ui): add Token Estimator link to footer #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HmbleCreator
wants to merge
17
commits into
coderamp-labs:main
Choose a base branch
from
HmbleCreator:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a3eef1a
feat(ui): add Token Estimator link to footer
HmbleCreator 6247f92
feat: Add token estimator documentation page and simplify footer link…
HmbleCreator cef47a2
feat: Add token estimator documentation page and simplify footer link…
HmbleCreator 48328ab
feat: use Jinja template for token estimator API docs
HmbleCreator 2ed86f6
Merge branch 'main' into main
filipchristiansen 3f0c1a5
Merge branch 'main' into main
HmbleCreator 98e5c45
Refactor token count API and routing, enforce API-only for /api/token…
HmbleCreator 5c271b5
Merge branch 'main' of https://github.com/HmbleCreator/gitingest
HmbleCreator 41ecea9
Merge branch 'main' into main
filipchristiansen 92b8660
Merge branch 'main' into main
filipchristiansen e1648c4
Merge branch 'main' into main
HmbleCreator 75daa98
Merge branch 'main' into main
filipchristiansen 5b282b5
Merge branch 'main' into main
HmbleCreator 806d2d5
Merge branch 'main' into main
HmbleCreator 79eb882
Merge branch 'main' into main
HmbleCreator 7852fde
Merge branch 'cyclotruc:main' into main
HmbleCreator b802ccf
Merge branch 'main' into main
filipchristiansen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% extends "base.jinja" %} | ||
{% block title %}Token Estimator{% endblock %} | ||
{% block content %} | ||
<div class="relative"> | ||
<div class="w-full h-full absolute inset-0 bg-gray-900 rounded-xl translate-y-2 translate-x-2"></div> | ||
<div class="rounded-xl relative z-20 p-8 sm:p-10 border-[3px] border-gray-900 bg-[#fff4da]"> | ||
<h1 class="text-3xl font-bold text-gray-900 mb-4">Token Estimator</h1> | ||
<form method="post" action="/tokencount" class="space-y-6"> | ||
<div> | ||
<label for="input_text" class="block mb-2 font-medium">Text to analyze:</label> | ||
<textarea name="input_text" id="input_text" rows="4" required class="w-full border-[3px] border-gray-900 rounded p-2 mb-2 bg-[#E8F0FE] focus:outline-none">{{ input_text if input_text else '' }}</textarea> | ||
</div> | ||
<div class="mb-10"> | ||
<label for="model_id" class="block mb-2 font-medium">Model:</label> | ||
<select name="model_id" id="model_id" class="w-full border-[3px] border-gray-900 rounded p-2 bg-[#E8F0FE] focus:outline-none"> | ||
{% for name, model in supported_models.items() %} | ||
<option value="{{ model }}" {% if model_id == model %}selected{% endif %}>{{ name }}</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<div> | ||
<button type="submit" class="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-2 px-4 rounded border-[3px] border-gray-900">Count Tokens</button> | ||
</div> | ||
</form> | ||
{% if result %} | ||
<div class="mt-6 p-4 border-[3px] border-gray-900 rounded bg-white"> | ||
<h2 class="text-xl font-semibold mb-2">Result</h2> | ||
<p><b>Token count:</b> {{ result.token_count }}</p> | ||
<p><b>Character count:</b> {{ result.character_count }}</p> | ||
<p><b>Model:</b> {{ result.model_id }}</p> | ||
</div> | ||
{% endif %} | ||
{% if error %} | ||
<div class="mt-6 p-4 border-[3px] border-red-600 rounded bg-red-100 text-red-800"> | ||
<b>Error:</b> {{ error }} | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from fastapi.testclient import TestClient | ||
from src.server.main import app | ||
|
||
client = TestClient(app, base_url="http://localhost") | ||
|
||
|
||
def test_tokencount_valid(): | ||
HmbleCreator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
response = client.post("/tokencount", json={"input_text": "Hello world!", "model_id": "openai-community/gpt2"}, headers={"host": "localhost"}) | ||
if response.status_code != 200: | ||
print("Response content:", response.content) | ||
assert response.status_code == 200 | ||
data = response.json() | ||
assert "token_count" in data | ||
assert isinstance(data["token_count"], int) | ||
assert data["token_count"] > 0 | ||
|
||
def test_tokencount_missing_input(): | ||
response = client.post("/tokencount", json={"model_id": "openai-community/gpt2"}, headers={"host": "localhost"}) | ||
if response.status_code != 400: | ||
print("Response content:", response.content) | ||
assert response.status_code == 400 | ||
data = response.json() | ||
assert "error" in data |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.