mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
show pricing and better title format
This commit is contained in:
25
models.go
25
models.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -10,12 +11,18 @@ import (
|
|||||||
"github.com/revrost/go-openrouter"
|
"github.com/revrost/go-openrouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ModelPricing struct {
|
||||||
|
Input float64 `json:"input"`
|
||||||
|
Output float64 `json:"output"`
|
||||||
|
}
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Tags []string `json:"tags,omitempty"`
|
Pricing ModelPricing `json:"pricing"`
|
||||||
|
Tags []string `json:"tags,omitempty"`
|
||||||
|
|
||||||
Reasoning bool `json:"-"`
|
Reasoning bool `json:"-"`
|
||||||
Vision bool `json:"-"`
|
Vision bool `json:"-"`
|
||||||
@@ -90,11 +97,19 @@ func LoadModels(initial bool) error {
|
|||||||
name = name[index+2:]
|
name = name[index+2:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input, _ := strconv.ParseFloat(model.Pricing.Prompt, 64)
|
||||||
|
output, _ := strconv.ParseFloat(model.Pricing.Completion, 64)
|
||||||
|
|
||||||
m := &Model{
|
m := &Model{
|
||||||
ID: model.ID,
|
ID: model.ID,
|
||||||
Created: model.Created,
|
Created: model.Created,
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: model.Description,
|
Description: model.Description,
|
||||||
|
|
||||||
|
Pricing: ModelPricing{
|
||||||
|
Input: input * 1000000,
|
||||||
|
Output: output * 1000000,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
GetModelTags(model, m)
|
GetModelTags(model, m)
|
||||||
|
|||||||
@@ -1450,8 +1450,18 @@
|
|||||||
|
|
||||||
// render models
|
// render models
|
||||||
fillSelect($model, data.models, (el, model) => {
|
fillSelect($model, data.models, (el, model) => {
|
||||||
|
const separator = "─".repeat(24);
|
||||||
|
|
||||||
|
el.title = [
|
||||||
|
model.name,
|
||||||
|
separator,
|
||||||
|
`Created:\t\t${formatTimestamp(model.created)}`,
|
||||||
|
`Pricing/1M:\t$${fixed(model.pricing.input, 2)} In | $${fixed(model.pricing.output, 2)} Out`,
|
||||||
|
separator,
|
||||||
|
stripMarkdown(model.description),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
el.value = model.id;
|
el.value = model.id;
|
||||||
el.title = `${model.name} (${formatTimestamp(model.created)})\n---\n${model.description}`;
|
|
||||||
el.textContent = model.name;
|
el.textContent = model.name;
|
||||||
|
|
||||||
el.dataset.tags = (model.tags || []).join(",");
|
el.dataset.tags = (model.tags || []).join(",");
|
||||||
|
|||||||
@@ -168,6 +168,7 @@
|
|||||||
|
|
||||||
#render() {
|
#render() {
|
||||||
if (this.#selected === false) {
|
if (this.#selected === false) {
|
||||||
|
this.#_selected.title = "";
|
||||||
this.#_selected.innerHTML = "";
|
this.#_selected.innerHTML = "";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -175,6 +176,7 @@
|
|||||||
|
|
||||||
const selection = this.#options[this.#selected];
|
const selection = this.#options[this.#selected];
|
||||||
|
|
||||||
|
this.#_selected.title = selection.title;
|
||||||
this.#_selected.innerHTML = selection.el.innerHTML;
|
this.#_selected.innerHTML = selection.el.innerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,4 +162,25 @@
|
|||||||
window.renderInline = markdown => {
|
window.renderInline = markdown => {
|
||||||
return marked.parseInline(markdown.trim());
|
return marked.parseInline(markdown.trim());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.stripMarkdown = markdown => {
|
||||||
|
return (
|
||||||
|
markdown
|
||||||
|
// Remove headings
|
||||||
|
.replace(/^#+\s*/gm, "")
|
||||||
|
// Remove links, keeping the link text
|
||||||
|
.replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1")
|
||||||
|
// Remove bold/italics, keeping the text
|
||||||
|
.replace(/(\*\*|__|\*|_|~~|`)(.*?)\1/g, "$2")
|
||||||
|
// Remove images
|
||||||
|
.replace(/!\[[^\]]*\]\([^)]*\)/g, "")
|
||||||
|
// Remove horizontal rules
|
||||||
|
.replace(/^-{3,}\s*$/gm, "")
|
||||||
|
// Remove list markers
|
||||||
|
.replace(/^\s*([*-]|\d+\.)\s+/gm, "")
|
||||||
|
// Collapse multiple newlines into one
|
||||||
|
.replace(/\n{2,}/g, "\n")
|
||||||
|
.trim()
|
||||||
|
);
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user