mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
**Refactor:** Restructure server
package to streamline imports and improve file organization
- Moved `providers`, `services`, `models`, `lib`, and related files to `src` directory within `server` package. - Adjusted imports across the codebase to reflect the new paths. - Renamed several `.ts` files for consistency. - Introduced an `index.ts` in the `ai/providers` package to export all providers. This improves maintainability and aligns with the project's updated directory structure.
This commit is contained in:
75
packages/ai/providers/__tests__/chat-stream-provider.test.ts
Normal file
75
packages/ai/providers/__tests__/chat-stream-provider.test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { OpenAI } from 'openai';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
import {
|
||||
BaseChatProvider,
|
||||
CommonProviderParams,
|
||||
ChatStreamProvider,
|
||||
} from '../chat-stream-provider.ts';
|
||||
|
||||
// Create a concrete implementation of BaseChatProvider for testing
|
||||
class TestChatProvider extends BaseChatProvider {
|
||||
getOpenAIClient(param: CommonProviderParams): OpenAI {
|
||||
return param.openai as OpenAI;
|
||||
}
|
||||
|
||||
getStreamParams(param: CommonProviderParams, safeMessages: any[]): any {
|
||||
return {
|
||||
model: param.model,
|
||||
messages: safeMessages,
|
||||
stream: true,
|
||||
max_tokens: param.maxTokens as number,
|
||||
};
|
||||
}
|
||||
|
||||
async processChunk(chunk: any, dataCallback: (data: any) => void): Promise<boolean> {
|
||||
dataCallback({ type: 'chat', data: chunk });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('../../lib/chat-sdk', () => ({
|
||||
default: {
|
||||
buildAssistantPrompt: vi.fn().mockReturnValue('Assistant prompt'),
|
||||
buildMessageChain: vi.fn().mockReturnValue([
|
||||
{ role: 'system', content: 'System prompt' },
|
||||
{ role: 'user', content: 'User message' },
|
||||
]),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('ChatStreamProvider', () => {
|
||||
it('should define the required interface', () => {
|
||||
// Verify the interface has the required method
|
||||
const mockProvider: ChatStreamProvider = {
|
||||
handleStream: vi.fn(),
|
||||
};
|
||||
|
||||
expect(mockProvider.handleStream).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('BaseChatProvider', () => {
|
||||
it('should implement the ChatStreamProvider interface', () => {
|
||||
// Create a concrete implementation
|
||||
const provider = new TestChatProvider();
|
||||
|
||||
// Verify it implements the interface
|
||||
expect(provider.handleStream).toBeInstanceOf(Function);
|
||||
expect(provider.getOpenAIClient).toBeInstanceOf(Function);
|
||||
expect(provider.getStreamParams).toBeInstanceOf(Function);
|
||||
expect(provider.processChunk).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
it('should have abstract methods that need to be implemented', () => {
|
||||
// This test verifies that the abstract methods exist
|
||||
// We can't instantiate BaseChatProvider directly, so we use the concrete implementation
|
||||
const provider = new TestChatProvider();
|
||||
|
||||
// Verify the abstract methods are implemented
|
||||
expect(provider.getOpenAIClient).toBeDefined();
|
||||
expect(provider.getStreamParams).toBeDefined();
|
||||
expect(provider.processChunk).toBeDefined();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user