Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion agentic/agentic-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { createAgenticServer } from 'agentic-server';
const app = createAgenticServer({
providerType: 'ollama',
providerBaseUrl: 'http://localhost:11434',
defaultModel: 'llama3',
defaultModel: 'qwen2.5:0.5b',
// Optional: record usage. Fire-and-forget; implementations must never throw.
inferenceSink: { logInference: (entry) => myBackend.record(entry) },
});
Expand All @@ -38,6 +38,8 @@ app.listen(3001, () => {

## Endpoints

Ollama chat requests must set `model` unless the selected provider has a configured `defaultModel`.

| Method | Path | Description |
|--------|------|-------------|
| POST | `/v1/chat/completions` | OpenAI-compatible chat completion (multi-provider) |
Expand Down
12 changes: 12 additions & 0 deletions agentic/agentic-server/__tests__/transforms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* gateway, or `ollama/…` can serve chat but no agent.
*/

import { BadRequestError } from '../src/errors';
import { transformChatRequest, transformChatResponse } from '../src/transforms';
import type { ResolvedProvider } from '../src/types';

Expand All @@ -22,6 +23,17 @@ const weatherTool = {
};

describe('transformChatRequest for ollama', () => {
it('uses the configured default model when the request omits it', () => {
const provider = { ...ollama, defaultModel: 'qwen2.5:0.5b' };
expect(transformChatRequest(provider, { messages: [] }).model).toBe('qwen2.5:0.5b');
});

it.each([undefined, ''])('rejects a request model of %p when no default is configured', (model) => {
expect(() => transformChatRequest(ollama, { model, messages: [] })).toThrow(
new BadRequestError('Ollama chat requires a request model or a provider defaultModel')
);
});

it('forwards tools and tool_choice', () => {
const body = transformChatRequest(ollama, {
model: 'qwen3:8b',
Expand Down
5 changes: 4 additions & 1 deletion agentic/agentic-server/src/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export function transformChatRequest(
const model = upstreamModel(provider, body.model);

if (provider.type === 'ollama') {
if (!model) {
throw new BadRequestError('Ollama chat requires a request model or a provider defaultModel');
}
// Ollama takes sampling and runtime settings under `options`; `max_tokens`
// is `num_predict`, and `num_ctx` (the context window the model is loaded
// with) has no OpenAI spelling, so it rides at the top level and moves here.
Expand All @@ -144,7 +147,7 @@ export function transformChatRequest(
};
const format = ollamaFormat(body);
return {
model: model || 'llama3',
model,
messages: flattenContentParts(body.messages),
stream: false,
...(body.tools !== undefined && { tools: body.tools }),
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-llm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ GraphileLlmPreset({
// Chat completion provider (required for RAG)
defaultChatCompleter: {
provider: 'ollama',
model: 'llama3',
model: 'qwen2.5:0.5b',
},

// Toggle individual capabilities
Expand Down
23 changes: 23 additions & 0 deletions graphile/graphile-llm/src/__tests__/graphile-llm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,29 @@ describe('Chat completion abstraction', () => {
expect(typeof buildChatCompleterFromEnv()).toBe('function');
});

it('sends the default Qwen chat model when CHAT_MODEL is unset', async () => {
process.env = { ...originalEnv };
delete process.env.CHAT_MODEL;
const fetchMock = jest.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(JSON.stringify({
choices: [{ message: { content: 'Hello' } }]
})));
try {
const chat = buildChatCompleterFromEnv()!;
await asTestRequest(() => chat([{ role: 'user', content: 'Hi' }]));
expect(fetchMock).toHaveBeenCalledWith(
`${gateway.url}/v1/chat/completions`,
expect.objectContaining({
body: JSON.stringify({
model: 'qwen2.5:0.5b',
messages: [{ role: 'user', content: 'Hi' }]
})
})
);
} finally {
fetchMock.mockRestore();
}
});

it('returns null when neither a gateway nor a provider is configured', () => {
process.env = { ...originalEnv };
delete process.env.AGENTIC_SERVER_URL;
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-llm/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function buildChatCompleter(config: ChatConfig): ChatFunction {
* AGENTIC_SERVER_URL - The gateway root; with it set, a completer is always
* available (the gateway resolves the upstream).
* CHAT_PROVIDER - Upstream dialect the gateway should use (default: 'ollama')
* CHAT_MODEL - Model identifier (default: 'llama3')
* CHAT_MODEL - Model identifier (default: 'qwen2.5:0.5b')
*
* Naming a provider or model without a gateway throws; naming nothing at all
* leaves RAG disabled.
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-llm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* },
* defaultChatCompleter: {
* provider: 'ollama',
* model: 'llama3',
* model: 'qwen2.5:0.5b',
* },
* enableRag: true,
* }),
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-llm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type ChatFunction = (messages: ChatMessage[], options?: ChatOptions) => P
export interface ChatConfig {
/** Upstream dialect the gateway should use: 'ollama', 'openai', ... */
provider: string;
/** Model identifier (e.g. 'llama3', 'gpt-4o') */
/** Model identifier (e.g. 'qwen2.5:0.5b', 'gpt-4o') */
model?: string;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/llm-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const opts = getEnvOptions();
// opts.embedding.model → EMBEDDER_MODEL || 'embeddinggemma-2:440m'
// opts.embedding.baseUrl → EMBEDDER_BASE_URL || 'http://localhost:11434'
// opts.chat.provider → CHAT_PROVIDER || 'ollama'
// opts.chat.model → CHAT_MODEL || 'llama3'
// opts.chat.model → CHAT_MODEL || 'qwen2.5:0.5b'
// opts.chat.baseUrl → CHAT_BASE_URL || 'http://localhost:11434'

// With runtime overrides
Expand All @@ -37,5 +37,5 @@ const custom = getEnvOptions({ embedding: { model: 'mxbai-embed-large' } });
| `EMBEDDER_MODEL` | `embeddinggemma-2:440m` | Embedding model identifier |
| `EMBEDDER_BASE_URL` | `http://localhost:11434` | Embedding provider URL |
| `CHAT_PROVIDER` | `ollama` | Chat provider name |
| `CHAT_MODEL` | `llama3` | Chat model identifier |
| `CHAT_MODEL` | `qwen2.5:0.5b` | Chat model identifier |
| `CHAT_BASE_URL` | `http://localhost:11434` | Chat provider URL |
2 changes: 1 addition & 1 deletion packages/llm-env/__tests__/llm-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('llmDefaults', () => {
expect(llmDefaults.embedding.model).toBe('embeddinggemma-2:440m');
expect(llmDefaults.embedding.baseUrl).toBe('http://localhost:11434');
expect(llmDefaults.chat.provider).toBe('ollama');
expect(llmDefaults.chat.model).toBe('llama3');
expect(llmDefaults.chat.model).toBe('qwen2.5:0.5b');
expect(llmDefaults.chat.baseUrl).toBe('http://localhost:11434');
});
});
4 changes: 2 additions & 2 deletions packages/llm-env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* EMBEDDER_MODEL - Embedding model (default: 'embeddinggemma-2:440m')
* EMBEDDER_BASE_URL - Embedding provider URL (default: 'http://localhost:11434')
* CHAT_PROVIDER - Chat provider name (default: 'ollama')
* CHAT_MODEL - Chat model (default: 'llama3')
* CHAT_MODEL - Chat model (default: 'qwen2.5:0.5b')
* CHAT_BASE_URL - Chat provider URL (default: 'http://localhost:11434')
* AGENTIC_SERVER_URL - Metered LLM gateway root (no default). When set, the
* server embeds and chats through the gateway, which
Expand Down Expand Up @@ -59,7 +59,7 @@ export const llmDefaults: ResolvedLlmEnvOptions = {
},
chat: {
provider: 'ollama',
model: 'llama3',
model: 'qwen2.5:0.5b',
baseUrl: 'http://localhost:11434'
},
gateway: {}
Expand Down
Loading