Asksage usage fetch models (#7329)
* Add flagship models * Add model fetching * Add usage handling, tool result handling * Update AskSageProvider.tsx * Create eight-pants-explode.md --------- Co-authored-by: alex-mcgraw-askSage <alex.mcgraw@asksage.ai>
This commit is contained in:
1 parent
fab49e810b
commit
c312c4aef6
4 files changed
+168
-4
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": minor
|
||||
---
|
||||
|
||||
This minor change adds new models and image support for rleated models, adds fetching of model info from API, updates tool handling, and adds retrieval usage stats for individual messages and a user's monthly token usage.
|
||||
@@ -19,6 +19,16 @@ type AskSageRequest = {
|
||||
}[]
|
||||
model: string
|
||||
dataset: "none"
|
||||
usage: boolean
|
||||
}
|
||||
|
||||
type AskSageUsage = {
|
||||
model_tokens: {
|
||||
completion_tokens: number
|
||||
prompt_tokens: number
|
||||
total_tokens: number
|
||||
}
|
||||
asksage_tokens: number
|
||||
}
|
||||
|
||||
type AskSageResponse = {
|
||||
@@ -28,6 +38,18 @@ type AskSageResponse = {
|
||||
response: string
|
||||
// Generated response message
|
||||
message: string
|
||||
// whether embedding & vector systems are down
|
||||
embedding_down: boolean
|
||||
vectors_down: boolean
|
||||
// references if dataset is not none
|
||||
references: string
|
||||
type: string
|
||||
added_obj: any
|
||||
tool_calls: any
|
||||
// usage metrics
|
||||
usage: AskSageUsage | null
|
||||
tool_responses: any[]
|
||||
tool_calls_unified: any[]
|
||||
}
|
||||
|
||||
export class AskSageHandler implements ApiHandler {
|
||||
@@ -50,7 +72,6 @@ export class AskSageHandler implements ApiHandler {
|
||||
async *createMessage(systemPrompt: string, messages: ClineStorageMessage[]): ApiStream {
|
||||
try {
|
||||
const model = this.getModel()
|
||||
|
||||
// Transform messages into AskSageRequest format
|
||||
const formattedMessages = messages.map((msg) => {
|
||||
const content = Array.isArray(msg.content)
|
||||
@@ -68,6 +89,7 @@ export class AskSageHandler implements ApiHandler {
|
||||
message: formattedMessages,
|
||||
model: model.id,
|
||||
dataset: "none",
|
||||
usage: true,
|
||||
}
|
||||
|
||||
// Make request to AskSage API
|
||||
@@ -91,15 +113,72 @@ export class AskSageHandler implements ApiHandler {
|
||||
throw new Error("No content in AskSage response")
|
||||
}
|
||||
|
||||
// Return entire response as a single chunk since streaming is not supported
|
||||
// Yield tool responses if they exist
|
||||
if (result.tool_responses && result.tool_responses.length > 0) {
|
||||
for (const toolResponse of result.tool_responses) {
|
||||
yield {
|
||||
type: "text",
|
||||
text: `[Tool Response: ${JSON.stringify(toolResponse)}]\n`,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yield the main response text
|
||||
yield {
|
||||
type: "text",
|
||||
text: result.message,
|
||||
}
|
||||
|
||||
// Yield usage information if available
|
||||
if (result.usage) {
|
||||
yield {
|
||||
type: "usage",
|
||||
inputTokens: result.usage.model_tokens.prompt_tokens,
|
||||
outputTokens: result.usage.model_tokens.completion_tokens,
|
||||
cacheReadTokens: 0,
|
||||
cacheWriteTokens: 0,
|
||||
totalCost: result.usage.asksage_tokens, // Cost = Consumed AskSage tokens
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
throw new Error(`AskSage request failed: ${error.message}`)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async getApiStreamUsage() {
|
||||
if (!this.apiKey) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${this.apiUrl}/count-monthly-tokens`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-access-tokens": this.apiKey,
|
||||
},
|
||||
body: JSON.stringify({ app_name: "asksage" }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Failed to fetch AskSage usage", await response.text())
|
||||
return undefined
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const usedTokens = data.response as number
|
||||
|
||||
return {
|
||||
type: "usage" as const,
|
||||
inputTokens: usedTokens,
|
||||
outputTokens: 0,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching AskSage usage:", error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2664,6 +2664,46 @@ export const askSageModels = {
|
||||
"google-gemini-2.5-pro": {
|
||||
maxTokens: 65536,
|
||||
contextWindow: 1_048_576,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
},
|
||||
"google-claude-45-sonnet": {
|
||||
maxTokens: 64000,
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
},
|
||||
"google-claude-4-opus": {
|
||||
maxTokens: 32000,
|
||||
contextWindow: 200_000,
|
||||
supportsImages: true,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
},
|
||||
"gpt-5": {
|
||||
maxTokens: 65536,
|
||||
contextWindow: 2_097_152,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
},
|
||||
"gpt-5-mini": {
|
||||
maxTokens: 32768,
|
||||
contextWindow: 1_048_576,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
},
|
||||
"gpt-5-nano": {
|
||||
maxTokens: 16384,
|
||||
contextWindow: 262_144,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: false,
|
||||
inputPrice: 0,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { askSageDefaultURL, askSageModels } from "@shared/api"
|
||||
import { askSageDefaultURL, askSageModels, ModelInfo } from "@shared/api"
|
||||
import { Mode } from "@shared/storage/types"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import { ApiKeyField } from "../common/ApiKeyField"
|
||||
import { DebouncedTextField } from "../common/DebouncedTextField"
|
||||
@@ -23,10 +24,49 @@ interface AskSageProviderProps {
|
||||
export const AskSageProvider = ({ showModelOptions, isPopup, currentMode }: AskSageProviderProps) => {
|
||||
const { apiConfiguration } = useExtensionState()
|
||||
const { handleFieldChange, handleModeFieldChange } = useApiConfigurationHandlers()
|
||||
const [availableModels, setAvailableModels] = useState<Record<string, ModelInfo>>(askSageModels)
|
||||
|
||||
// Get the normalized configuration
|
||||
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, currentMode)
|
||||
|
||||
useEffect(() => {
|
||||
const fetchModels = async () => {
|
||||
try {
|
||||
const apiUrl = apiConfiguration?.asksageApiUrl || askSageDefaultURL
|
||||
const response = await fetch(`${apiUrl}/get-models`)
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Failed to fetch AskSage models, falling back to default list.")
|
||||
setAvailableModels(askSageModels)
|
||||
return
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
const modelIds = data.response as string[]
|
||||
|
||||
if (Array.isArray(modelIds) && modelIds.length > 0) {
|
||||
const filteredModels = Object.entries(askSageModels)
|
||||
.filter(([id]) => modelIds.includes(id))
|
||||
.reduce(
|
||||
(acc, [id, info]) => {
|
||||
acc[id] = info
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, ModelInfo>,
|
||||
)
|
||||
setAvailableModels(Object.keys(filteredModels).length > 0 ? filteredModels : askSageModels)
|
||||
} else {
|
||||
setAvailableModels(askSageModels)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching AskSage models:", error)
|
||||
setAvailableModels(askSageModels)
|
||||
}
|
||||
}
|
||||
|
||||
fetchModels()
|
||||
}, [apiConfiguration?.asksageApiUrl])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ApiKeyField
|
||||
@@ -49,7 +89,7 @@ export const AskSageProvider = ({ showModelOptions, isPopup, currentMode }: AskS
|
||||
<>
|
||||
<ModelSelector
|
||||
label="Model"
|
||||
models={askSageModels}
|
||||
models={availableModels}
|
||||
onChange={(e) =>
|
||||
handleModeFieldChange(
|
||||
{ plan: "planModeApiModelId", act: "actModeApiModelId" },
|
||||
|
||||
Reference in new issue
Block a user