Skip to content

Commit 95f09b7

Browse files
committed
fix web search issues & add model, search, and search_provider options
in url params
1 parent a7a4d49 commit 95f09b7

3 files changed

Lines changed: 81 additions & 14 deletions

File tree

README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Get the native NanoChat experience on your devices:
1414
- **iOS**: [nanochat-ios](https://github.com/nanogpt-community/nanochat-ios) ([TestFlight Beta](https://testflight.apple.com/join/afmPp2xW))
1515
- **Desktop**: coming soon
1616

17-
**IMPORTANT** - Rename your thom-chat.db.* files to nanochat.db.*
17+
**IMPORTANT** - Rename your thom-chat.db._ files to nanochat.db._
1818

1919
---
2020

@@ -160,30 +160,51 @@ View performance benchmarks from [Artificial Analysis](https://artificialanalysi
160160
### Provider Selection
161161

162162
For models supported by multiple providers on NanoGPT, you can:
163+
163164
- Select a specific provider (e.g., 'openai', 'anthropic', 'google') for a model.
164165
- Configure preferred and excluded providers in Account Settings.
165166
- Enable automatic fallback to other providers if the preferred one fails.
166167

167168
### Video Generation
168169

169170
Generate videos using NanoGPT's video models:
171+
170172
- Text-to-video generation
171173
- View generation status and history
172174
- Download generated videos
173175

176+
### URL Parameters & Shortcuts
177+
178+
You can use URL parameters to pre-configure your chat session. This is useful for creating bookmarks or "bang" style shortcuts (e.g. in your browser).
179+
180+
| Parameter | Description | Example |
181+
| ----------------- | -------------------------------------------------------- | ---------------------------- |
182+
| `q` | Pre-fills the chat input | `?q=Explain quantum physics` |
183+
| `model` | Selects the AI model | `?model=openai/gpt-4o` |
184+
| `model_provider` | Selects the provider for the model (NanoGPT) | `?model_provider=cerebras` |
185+
| `search` | Sets web search mode (`off`, `standard`, `deep`) | `?search=deep` |
186+
| `search_provider` | Sets search provider (`linkup`, `tavily`, `exa`, `kagi`) | `?search_provider=tavily` |
187+
| `projectId` | Contextualizes chat with a specific Project | `?projectId=123` |
188+
189+
**Example "Bang" URL:**
190+
`https://your-nanochat.com/chat?model=anthropic/claude-3-5-sonnet&search=deep&q=%s`
191+
192+
**In-Chat Shortcuts:**
193+
194+
- `@<rule_name>`: Apply a specific user rule to the current message (e.g., `@concise`)
174195

175196
---
176197

177198
## Environment Variables
178199

179-
| Variable | Description |
180-
| ---------------------------- | ------------------------------------------------------- |
181-
| `DATABASE_URL` | SQLite database path (default: ./data/nanochat.db) |
182-
| `NANOGPT_API_KEY` | Nano-GPT API key for generation |
183-
| `BETTER_AUTH_SECRET` | Authentication secret |
184-
| `BETTER_AUTH_URL` | Base URL for authentication |
185-
| `ARTIFICIAL_ANALYSIS_API_KEY`| (Optional) API key for model benchmarks from artificialanalysis.ai |
186-
| `ENCRYPTION_KEY` | (Optional) Encryption key for API keys at rest. Generate with `openssl rand -base64 32` |
200+
| Variable | Description |
201+
| ----------------------------- | --------------------------------------------------------------------------------------- |
202+
| `DATABASE_URL` | SQLite database path (default: ./data/nanochat.db) |
203+
| `NANOGPT_API_KEY` | Nano-GPT API key for generation |
204+
| `BETTER_AUTH_SECRET` | Authentication secret |
205+
| `BETTER_AUTH_URL` | Base URL for authentication |
206+
| `ARTIFICIAL_ANALYSIS_API_KEY` | (Optional) API key for model benchmarks from artificialanalysis.ai |
207+
| `ENCRYPTION_KEY` | (Optional) Encryption key for API keys at rest. Generate with `openssl rand -base64 32` |
187208

188209
### API Key Encryption
189210

src/routes/api/generate-message/+server.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,19 @@ ${attachedRules.map((r) => `- ${r.name}: ${r.rule}`).join('\n')}`;
748748
log('Background: MCP tools enabled for this request', startTime);
749749
}
750750

751+
// Filter out web search tool if native web search is enabled
752+
// This prevents the model from using the tool instead of the native integration
753+
// which supports multiple providers (Tavily, Exa, etc.)
754+
const webSearchActive = !webFeaturesDisabled && (lastUserMessage?.webSearchEnabled ?? false);
755+
const tools = mcpAvailable
756+
? mcpToolDefinitions.filter((t) => {
757+
if (webSearchActive && t.type === 'function' && t.function.name === 'nanogpt_web_search') {
758+
return false;
759+
}
760+
return true;
761+
})
762+
: undefined;
763+
751764
const streamResult = await ResultAsync.fromPromise(
752765
openai.chat.completions.create(
753766
{
@@ -758,7 +771,7 @@ ${attachedRules.map((r) => `- ${r.name}: ${r.rule}`).join('\n')}`;
758771
reasoning_effort: reasoningEffort,
759772
stream_options: { include_usage: true },
760773
// Add MCP tools when enabled
761-
tools: mcpAvailable ? mcpToolDefinitions : undefined,
774+
tools,
762775
// @ts-ignore - Custom NanoGPT parameters
763776
linkup:
764777
!webFeaturesDisabled && (lastUserMessage?.webSearchEnabled ?? false)

src/routes/chat/+page.svelte

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import { scale } from 'svelte/transition';
1010
import { useCachedQuery, api } from '$lib/cache/cached-query.svelte';
1111
import { Provider } from '$lib/types';
12+
import { untrack } from 'svelte';
1213
import { page } from '$app/state';
14+
import { settings } from '$lib/state/settings.svelte.js';
1315
1416
const defaultSuggestions = [
1517
'How does AI work?',
@@ -18,7 +20,7 @@
1820
'What is the meaning of life?',
1921
];
2022
21-
const settings = useCachedQuery(api.user_settings.get, {
23+
const userSettingsQuery = useCachedQuery(api.user_settings.get, {
2224
session_token: session.current?.session.token ?? '',
2325
});
2426
@@ -73,9 +75,40 @@
7375
// Handle URL parameter for initial query
7476
$effect(() => {
7577
const urlQuery = page.url.searchParams.get('q');
76-
if (urlQuery && prompt.current === '') {
77-
prompt.current = decodeURIComponent(urlQuery);
78-
}
78+
const modelParam = page.url.searchParams.get('model');
79+
const providerParam = page.url.searchParams.get('model_provider');
80+
const searchParam = page.url.searchParams.get('search');
81+
const searchProviderParam = page.url.searchParams.get('search_provider');
82+
83+
untrack(() => {
84+
if (urlQuery && prompt.current === '') {
85+
prompt.current = decodeURIComponent(urlQuery);
86+
}
87+
88+
if (modelParam && settings.modelId !== modelParam) {
89+
settings.modelId = modelParam;
90+
}
91+
92+
if (providerParam && settings.providerId !== providerParam) {
93+
settings.providerId = providerParam;
94+
}
95+
96+
if (
97+
searchParam &&
98+
['off', 'standard', 'deep'].includes(searchParam) &&
99+
settings.webSearchMode !== searchParam
100+
) {
101+
settings.webSearchMode = searchParam as 'off' | 'standard' | 'deep';
102+
}
103+
104+
if (
105+
searchProviderParam &&
106+
['linkup', 'tavily', 'exa', 'kagi'].includes(searchProviderParam) &&
107+
settings.webSearchProvider !== searchProviderParam
108+
) {
109+
settings.webSearchProvider = searchProviderParam as 'linkup' | 'tavily' | 'exa' | 'kagi';
110+
}
111+
});
79112
});
80113
</script>
81114

0 commit comments

Comments
 (0)