1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-08 17:06:42 +00:00

include exa cost

This commit is contained in:
Laura
2025-08-28 14:46:28 +02:00
parent b331920634
commit 98c6976dfa
4 changed files with 17 additions and 15 deletions

11
chat.go
View File

@@ -14,11 +14,12 @@ import (
) )
type ToolCall struct { type ToolCall struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Args string `json:"args"` Args string `json:"args"`
Result string `json:"result,omitempty"` Result string `json:"result,omitempty"`
Done bool `json:"done,omitempty"` Done bool `json:"done,omitempty"`
Cost float64 `json:"cost,omitempty"`
} }
type TextFile struct { type TextFile struct {

5
exa.go
View File

@@ -18,9 +18,14 @@ type ExaResult struct {
Summary string `json:"summary"` Summary string `json:"summary"`
} }
type ExaCost struct {
Total float64 `json:"total"`
}
type ExaResults struct { type ExaResults struct {
RequestID string `json:"requestId"` RequestID string `json:"requestId"`
Results []ExaResult `json:"results"` Results []ExaResult `json:"results"`
Cost ExaCost `json:"costDollars"`
} }
func (e *ExaResult) String() string { func (e *ExaResult) String() string {

View File

@@ -116,6 +116,8 @@ func HandleSearchWebTool(ctx context.Context, tool *ToolCall) error {
return nil return nil
} }
tool.Cost = results.Cost.Total
if len(results.Results) == 0 { if len(results.Results) == 0 {
tool.Result = "error: no search results" tool.Result = "error: no search results"
@@ -146,6 +148,8 @@ func HandleFetchContentsTool(ctx context.Context, tool *ToolCall) error {
return nil return nil
} }
tool.Cost = results.Cost.Total
if len(results.Results) == 0 { if len(results.Results) == 0 {
tool.Result = "error: no search results" tool.Result = "error: no search results"

View File

@@ -407,16 +407,6 @@
#updateToolHeight() { #updateToolHeight() {
const result = this.#_tool.querySelector(".result"); const result = this.#_tool.querySelector(".result");
try {
const clone = result.cloneNode();
setTimeout(() => {
console.log(clone, clone.getBoundingClientRect(), clone.scrollHeight, clone.height);
}, 0);
} catch(err) {
console.warn(err);
}
this.#_tool.style.setProperty("--height", `${result.scrollHeight}px`); this.#_tool.style.setProperty("--height", `${result.scrollHeight}px`);
} }
@@ -1047,6 +1037,8 @@
message.setTool(chunk.text); message.setTool(chunk.text);
if (chunk.text.done) { if (chunk.text.done) {
totalCost += chunk.text.cost || 0;
finish(); finish();
} }