mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Get accurate OpenRouter pricing
This commit is contained in:
11 files changed
+81
-94
No files matched your search
@@ -3,7 +3,6 @@ import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { TestApp } from '@/test/TestApp';
|
||||
import { CreditsBadge } from './CreditsBadge';
|
||||
|
||||
|
||||
// Mock the useAICredits hook
|
||||
vi.mock('@/hooks/useAICredits', () => ({
|
||||
useAICredits: () => ({
|
||||
@@ -16,7 +15,8 @@ vi.mock('@/hooks/useAICredits', () => ({
|
||||
// Mock the fetch function
|
||||
global.fetch = vi.fn();
|
||||
|
||||
const mockConnection = {
|
||||
const mockProvider = {
|
||||
id: 'test-provider',
|
||||
baseURL: 'https://api.test.com/v1',
|
||||
apiKey: 'test-key',
|
||||
};
|
||||
@@ -25,10 +25,7 @@ describe('CreditsBadge', () => {
|
||||
it('renders the credits amount', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<CreditsBadge
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
/>
|
||||
<CreditsBadge provider={mockProvider} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
@@ -41,8 +38,7 @@ describe('CreditsBadge', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<CreditsBadge
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
onOpenDialog={mockCallback}
|
||||
/>
|
||||
</TestApp>
|
||||
@@ -57,10 +53,7 @@ describe('CreditsBadge', () => {
|
||||
it('has proper styling for clickable badge', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<CreditsBadge
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
/>
|
||||
<CreditsBadge provider={mockProvider} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
@@ -72,10 +65,7 @@ describe('CreditsBadge', () => {
|
||||
it('does not render dialog directly', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<CreditsBadge
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
/>
|
||||
<CreditsBadge provider={mockProvider} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { AIProvider } from '@/contexts/AISettingsContext';
|
||||
import { useAICredits } from '@/hooks/useAICredits';
|
||||
|
||||
interface CreditsBadgeProps {
|
||||
providerId: string;
|
||||
connection: {
|
||||
baseURL: string;
|
||||
apiKey?: string;
|
||||
nostr?: boolean;
|
||||
};
|
||||
provider: AIProvider;
|
||||
className?: string;
|
||||
onOpenDialog?: () => void;
|
||||
}
|
||||
@@ -15,8 +11,8 @@ interface CreditsBadgeProps {
|
||||
/**
|
||||
* Displays a clickable credits badge showing the remaining credits for an AI provider
|
||||
*/
|
||||
export function CreditsBadge({ providerId, connection, className, onOpenDialog }: CreditsBadgeProps) {
|
||||
const { data: credits, isLoading, error } = useAICredits(providerId, connection);
|
||||
export function CreditsBadge({ provider, className, onOpenDialog }: CreditsBadgeProps) {
|
||||
const { data: credits, isLoading, error } = useAICredits(provider);
|
||||
|
||||
// Don't render anything if there's an error (provider doesn't support credits endpoint)
|
||||
if (error || isLoading) {
|
||||
|
||||
@@ -2,14 +2,16 @@ import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { TestApp } from '@/test/TestApp';
|
||||
import { CreditsDialog } from './CreditsDialog';
|
||||
|
||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||
|
||||
// Mock the fetch function
|
||||
global.fetch = vi.fn();
|
||||
|
||||
const mockConnection = {
|
||||
const mockProvider: AIProvider = {
|
||||
id: 'test-provider',
|
||||
baseURL: 'https://api.test.com/v1',
|
||||
apiKey: 'test-key',
|
||||
nostr: false,
|
||||
};
|
||||
|
||||
describe('CreditsDialog', () => {
|
||||
@@ -19,8 +21,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -36,8 +37,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={false}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -51,8 +51,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -67,8 +66,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -89,8 +87,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={false}
|
||||
onOpenChange={mockCallback}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -101,8 +98,7 @@ describe('CreditsDialog', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={mockCallback}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
@@ -13,15 +13,12 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { createAIClient } from '@/lib/ai-client';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { AIProvider } from '@/contexts/AISettingsContext';
|
||||
|
||||
interface CreditsDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
providerId: string;
|
||||
connection: {
|
||||
baseURL: string;
|
||||
apiKey?: string;
|
||||
nostr?: boolean;
|
||||
};
|
||||
provider: AIProvider;
|
||||
}
|
||||
|
||||
interface Payment {
|
||||
@@ -184,7 +181,7 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
export function CreditsDialog({ open, onOpenChange, providerId, connection }: CreditsDialogProps) {
|
||||
export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogProps) {
|
||||
const { user } = useCurrentUser();
|
||||
const { toast } = useToast();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -196,9 +193,9 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
|
||||
// Query for payment history
|
||||
const { data: payments, isLoading: isLoadingPayments } = useQuery({
|
||||
queryKey: ['ai-payments', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
queryFn: async (): Promise<Payment[]> => {
|
||||
const ai = createAIClient(connection, user);
|
||||
const ai = createAIClient(provider, user);
|
||||
const data = await ai.get('/credits/payments?limit=50') as PaymentsResponse;
|
||||
return data.data;
|
||||
},
|
||||
@@ -210,7 +207,7 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
// Mutation for adding credits
|
||||
const addCreditsMutation = useMutation({
|
||||
mutationFn: async (request: AddCreditsRequest): Promise<Payment> => {
|
||||
const ai = createAIClient(connection, user);
|
||||
const ai = createAIClient(provider, user);
|
||||
return await ai.post('/credits/add', {
|
||||
body: request,
|
||||
}) as Payment;
|
||||
@@ -230,12 +227,12 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
|
||||
// Refresh payments list
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['ai-payments', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
});
|
||||
|
||||
// Refresh credits balance
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['ai-credits', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
});
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
@@ -251,7 +248,7 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
// Mutation for checking payment status
|
||||
const checkPaymentMutation = useMutation({
|
||||
mutationFn: async (paymentId: string): Promise<Payment> => {
|
||||
const ai = createAIClient(connection, user);
|
||||
const ai = createAIClient(provider, user);
|
||||
return await ai.get(`/credits/payments/${paymentId}`) as Payment;
|
||||
},
|
||||
onMutate: async (paymentId: string) => {
|
||||
@@ -268,7 +265,7 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
|
||||
// Update the specific payment in the cache instead of refetching
|
||||
queryClient.setQueryData<Payment[]>(
|
||||
['ai-payments', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
(oldPayments) => {
|
||||
if (!oldPayments) return oldPayments;
|
||||
return oldPayments.map(payment =>
|
||||
@@ -280,7 +277,7 @@ export function CreditsDialog({ open, onOpenChange, providerId, connection }: Cr
|
||||
// If payment completed, refresh credits balance
|
||||
if (updatedPayment.status === 'completed') {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['ai-credits', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
});
|
||||
toast({
|
||||
title: 'Payment completed!',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { TestApp } from '@/test/TestApp';
|
||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||
|
||||
// Mock QRCode
|
||||
vi.mock('qrcode', () => ({
|
||||
@@ -18,9 +19,11 @@ const mockWebLN = {
|
||||
// We need to import the component after mocking
|
||||
const { CreditsDialog } = await import('./CreditsDialog');
|
||||
|
||||
const mockConnection = {
|
||||
const mockProvider: AIProvider = {
|
||||
id: 'test-provider',
|
||||
baseURL: 'https://api.test.com/v1',
|
||||
apiKey: 'test-key',
|
||||
nostr: false,
|
||||
};
|
||||
|
||||
describe('Lightning Payment', () => {
|
||||
@@ -39,8 +42,7 @@ describe('Lightning Payment', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -61,8 +63,7 @@ describe('Lightning Payment', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
@@ -77,8 +78,7 @@ describe('Lightning Payment', () => {
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
providerId="test-provider"
|
||||
connection={mockConnection}
|
||||
provider={mockProvider}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { z } from 'zod';
|
||||
import { createAIClient } from '@/lib/ai-client';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { AIProvider } from '@/contexts/AISettingsContext';
|
||||
|
||||
// Zod schemas for the two possible response formats
|
||||
const creditsResponseV1Schema = z.object({
|
||||
@@ -31,18 +32,14 @@ export interface CreditsResponse {
|
||||
* @param connection - The AI connection configuration
|
||||
* @returns Query result with credits information
|
||||
*/
|
||||
export function useAICredits(providerId: string, connection: {
|
||||
baseURL: string;
|
||||
apiKey?: string;
|
||||
nostr?: boolean;
|
||||
}) {
|
||||
export function useAICredits(provider: AIProvider) {
|
||||
const { user } = useCurrentUser();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['ai-credits', connection.nostr ? user?.pubkey ?? '' : '', providerId],
|
||||
queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
|
||||
queryFn: async (): Promise<CreditsResponse> => {
|
||||
try {
|
||||
const ai = createAIClient(connection, user);
|
||||
const ai = createAIClient(provider, user);
|
||||
const data = await ai.get('/credits');
|
||||
|
||||
// Validate and normalize the response
|
||||
@@ -68,5 +65,6 @@ export function useAICredits(providerId: string, connection: {
|
||||
retry: false, // Don't retry as not all providers support this endpoint
|
||||
refetchOnWindowFocus: false,
|
||||
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||
enabled: provider.id === 'shakespeare' && !!user,
|
||||
});
|
||||
}
|
||||
@@ -42,9 +42,8 @@ describe('useAIProjectId', () => {
|
||||
|
||||
// Mock parseProviderModel
|
||||
mockParseProviderModel.mockReturnValue({
|
||||
provider: 'openai',
|
||||
provider: { id: 'openai', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' },
|
||||
model: 'gpt-4',
|
||||
connection: { apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
});
|
||||
|
||||
// Mock createAIClient
|
||||
@@ -86,7 +85,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -110,7 +109,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -134,7 +133,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -157,7 +156,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -170,7 +169,7 @@ describe('useAIProjectId', () => {
|
||||
{ id: 'openai', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
]);
|
||||
expect(mockCreateAIClient).toHaveBeenCalledWith(
|
||||
{ apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' },
|
||||
{ id: 'openai', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' },
|
||||
undefined
|
||||
);
|
||||
});
|
||||
@@ -188,7 +187,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -241,7 +240,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -296,7 +295,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -346,7 +345,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -396,7 +395,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -453,7 +452,7 @@ describe('useAIProjectId', () => {
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
|
||||
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
});
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ export function useAIProjectId({ onError }: UseAIProjectIdOptions = {}) {
|
||||
|
||||
try {
|
||||
// Initialize OpenAI client
|
||||
const { model, connection } = parseProviderModel(providerModel, settings.providers);
|
||||
const openai = createAIClient(connection, user);
|
||||
const { model, provider } = parseProviderModel(providerModel, settings.providers);
|
||||
const openai = createAIClient(provider, user);
|
||||
|
||||
const systemPrompt = `You are a product expert. Given the user's project description, come up with a short, unique, and memorable name for their product or brand. Generate only the name without any additional text or punctuation. The name should be lowercase, use hyphens instead of spaces, and contain only alphanumeric characters and hyphens. Avoid using special characters or underscores.`;
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ export class SessionManager {
|
||||
let finishReason: string | null = null;
|
||||
|
||||
// Process the stream
|
||||
let usage: { prompt_tokens: number; completion_tokens: number } | undefined;
|
||||
let usage: { prompt_tokens: number; completion_tokens: number; cost?: number } | undefined;
|
||||
for await (const chunk of stream) {
|
||||
// Check if session was cancelled
|
||||
if (!session.isLoading) break;
|
||||
@@ -319,9 +319,14 @@ export class SessionManager {
|
||||
|
||||
// Capture usage data if available (some providers include it in the final chunk)
|
||||
if (chunk.usage) {
|
||||
const cost = 'cost' in chunk.usage && typeof chunk.usage.cost === 'number'
|
||||
? chunk.usage.cost
|
||||
: undefined;
|
||||
|
||||
usage = {
|
||||
prompt_tokens: chunk.usage.prompt_tokens || 0,
|
||||
completion_tokens: chunk.usage.completion_tokens || 0
|
||||
completion_tokens: chunk.usage.completion_tokens || 0,
|
||||
cost,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -461,12 +466,20 @@ export class SessionManager {
|
||||
/**
|
||||
* Update session cost and context usage based on usage data
|
||||
*/
|
||||
private updateSessionCost(projectId: string, usage: { prompt_tokens: number; completion_tokens: number }, providerModel: string): void {
|
||||
private updateSessionCost(projectId: string, usage: { prompt_tokens: number; completion_tokens: number; cost?: number }, providerModel: string): void {
|
||||
if (!this.getProviderModels) return;
|
||||
|
||||
const session = this.sessions.get(projectId);
|
||||
if (!session) return;
|
||||
|
||||
// If provider gives direct cost, use it
|
||||
if (typeof usage.cost === 'number') {
|
||||
session.totalCost = (session.totalCost || 0) + usage.cost;
|
||||
this.emit('costUpdated', projectId, session.totalCost);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, get the cost from the models endpoint
|
||||
try {
|
||||
const parsed = parseProviderModel(providerModel, this.aiSettings.providers);
|
||||
const modelName = parsed.model;
|
||||
@@ -491,7 +504,6 @@ export class SessionManager {
|
||||
|
||||
// Update session total cost
|
||||
session.totalCost = (session.totalCost || 0) + requestCost;
|
||||
|
||||
this.emit('costUpdated', projectId, session.totalCost);
|
||||
} catch (error) {
|
||||
console.warn('Failed to calculate session cost:', error);
|
||||
|
||||
@@ -35,14 +35,15 @@ export function createAIClient(provider: AIProvider, user?: NUser): OpenAI {
|
||||
openai = new OpenAI(baseConfig);
|
||||
}
|
||||
|
||||
const createCompletion = openai.chat.completions.create;
|
||||
const createCompletion: typeof openai.chat.completions.create
|
||||
= openai.chat.completions.create.bind(openai.chat.completions);
|
||||
|
||||
openai.chat.completions.create = ((...[body, options]: Parameters<typeof createCompletion>) => {
|
||||
// OpenRouter usage accounting
|
||||
// https://openrouter.ai/docs/use-cases/usage-accounting
|
||||
// if (provider.features?.includes('openrouter.usage_accounting')) {
|
||||
// (body as { usage?: { include?: boolean } }).usage = { include: true };
|
||||
// }
|
||||
if (provider.id === 'openrouter') {
|
||||
(body as { usage?: { include?: boolean } }).usage = { include: true };
|
||||
}
|
||||
|
||||
return createCompletion(body, options);
|
||||
}) as typeof createCompletion;
|
||||
|
||||
@@ -144,8 +144,7 @@ function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpe
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<CreditsBadge
|
||||
providerId={provider.id}
|
||||
connection={{ baseURL: provider.baseURL, apiKey: provider.apiKey, nostr: provider.nostr }}
|
||||
provider={provider}
|
||||
onOpenDialog={() => onOpenCreditsDialog(provider.id)}
|
||||
/>
|
||||
<Button
|
||||
@@ -547,8 +546,7 @@ export function AISettings() {
|
||||
handleCloseCreditsDialog();
|
||||
}
|
||||
}}
|
||||
providerId={activeCreditsDialog}
|
||||
connection={{ baseURL: provider.baseURL, apiKey: provider.apiKey, nostr: provider.nostr }}
|
||||
provider={provider}
|
||||
/>
|
||||
);
|
||||
})()}
|
||||
|
||||
Reference in new issue
Block a user