Skip to content

Commit d618b2f

Browse files
authored
Merge pull request #280 from drivecore/feature/local-openai-support
feature: local openai support
2 parents 6a3a392 + c04ee43 commit d618b2f

File tree

14 files changed

+120
-28
lines changed

14 files changed

+120
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export default {
8383
profile: false,
8484
tokenCache: true,
8585

86-
// Ollama configuration (if using local models)
87-
ollamaBaseUrl: 'http://localhost:11434',
86+
// Base URL configuration (for providers that need it)
87+
baseUrl: 'http://localhost:11434', // Example for Ollama
8888
};
8989
```
9090

mycoder.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default {
1818
//model: 'llama3.2:3b',
1919
//provider: 'xai',
2020
//model: 'grok-2-latest',
21+
//provider: 'openai',
22+
//model: 'qwen2.5-coder:14b',
23+
//baseUrl: 'http://192.168.2.66:80/v1-openai',
2124
maxTokens: 4096,
2225
temperature: 0.7,
2326

packages/agent/src/core/llm/__tests__/openai.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('OpenAIProvider', () => {
177177
'role' in toolUseMessage
178178
) {
179179
expect(toolUseMessage.role).toBe('assistant');
180-
expect(toolUseMessage.content).toBe(null);
180+
expect(toolUseMessage.content).toBe(''); // required by gpustack' implementation of openai SDK.
181181

182182
if (
183183
'tool_calls' in toolUseMessage &&

packages/agent/src/core/llm/provider.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ export const providerConfig: Record<string, ProviderConfig> = {
5757
model: 'gpt-4o-2024-05-13',
5858
factory: (model, options) => new OpenAIProvider(model, options),
5959
},
60-
gpustack: {
61-
docsUrl: 'https://mycoder.ai/docs/provider/local-openai',
62-
model: 'llama3.2',
63-
baseUrl: 'http://localhost:80',
64-
factory: (model, options) => new OpenAIProvider(model, options),
65-
},
6660
ollama: {
6761
docsUrl: 'https://mycoder.ai/docs/provider/ollama',
6862
model: 'llama3.2',

packages/agent/src/core/llm/providers/openai.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class OpenAIProvider implements LLMProvider {
154154
// so we'll include it as a function call in an assistant message
155155
return {
156156
role: 'assistant',
157-
content: null,
157+
content: '',
158158
tool_calls: [
159159
{
160160
id: msg.id,

packages/agent/src/tools/getTools.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { fetchTool } from './io/fetch.js';
1010
import { textEditorTool } from './io/textEditor.js';
1111
import { createMcpTool } from './mcp.js';
1212
import { listBackgroundToolsTool } from './system/listBackgroundTools.js';
13-
import { respawnTool } from './system/respawn.js';
1413
import { sequenceCompleteTool } from './system/sequenceComplete.js';
1514
import { shellMessageTool } from './system/shellMessage.js';
1615
import { shellStartTool } from './system/shellStart.js';
@@ -39,7 +38,7 @@ export function getTools(options?: GetToolsOptions): Tool[] {
3938
shellMessageTool as unknown as Tool,
4039
browseStartTool as unknown as Tool,
4140
browseMessageTool as unknown as Tool,
42-
respawnTool as unknown as Tool,
41+
//respawnTool as unknown as Tool, this is a confusing tool for now.
4342
sleepTool as unknown as Tool,
4443
listBackgroundToolsTool as unknown as Tool,
4544
];

packages/agent/src/tools/system/respawn.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { respawnTool } from './respawn';
88
const toolContext: ToolContext = getMockToolContext();
99

1010
describe('respawnTool', () => {
11-
it('should have correct name and description', () => {
11+
it('should have correct name', () => {
1212
expect(respawnTool.name).toBe('respawn');
13-
expect(respawnTool.description).toContain('Resets the agent context');
1413
});
1514

1615
it('should execute and return confirmation message', async () => {

packages/agent/src/tools/system/respawn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const returnSchema = z.object({
2020
export const respawnTool: Tool = {
2121
name: 'respawn',
2222
description:
23-
'Resets the agent context to just the system prompt and provided context',
23+
'Resets the current conversation to just the system prompt and provided input context to this tool.',
2424
logPrefix: '🔄',
2525
parameters: parameterSchema,
2626
returns: returnSchema,

packages/cli/src/commands/$default.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,25 @@ export async function executePrompt(
114114
throw new Error(`Unknown provider: ${config.provider}`);
115115
}
116116

117-
const { keyName } = providerSettings;
117+
// only validate key if baseUrl is not set, otherwise we assume the user is using a local provider
118118
let apiKey: string | undefined = undefined;
119+
const { keyName } = providerSettings;
119120
if (keyName) {
120121
// Then fall back to environment variable
122+
logger.info(`Looking API key in env: ${keyName}`);
121123
apiKey = process.env[keyName];
122-
if (!apiKey) {
123-
logger.error(getProviderApiKeyError(config.provider));
124-
throw new Error(`${config.provider} API key not found`);
124+
if (!config.baseUrl) {
125+
if (!apiKey) {
126+
logger.error(getProviderApiKeyError(config.provider));
127+
throw new Error(`${config.provider} API key not found`);
128+
}
125129
}
126130
}
127131

128132
logger.info(`LLM: ${config.provider}/${config.model}`);
133+
if (apiKey) {
134+
logger.info(`Using API key: ${apiKey.slice(0, 4)}...`);
135+
}
129136
if (config.baseUrl) {
130137
// For Ollama, we check if the base URL is set
131138
logger.info(`Using base url: ${config.baseUrl}`);

packages/docs/docs/providers/anthropic.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export default {
3232
provider: 'anthropic',
3333
model: 'claude-3-7-sonnet-20250219',
3434

35-
// Optional: Set API key directly (environment variable is preferred)
36-
// anthropicApiKey: 'your_api_key_here',
37-
3835
// Other MyCoder settings
3936
maxTokens: 4096,
4037
temperature: 0.7,

0 commit comments

Comments
 (0)