@cuijy/free-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +299 -0
- package/bin/freeapi +8 -0
- package/dist/cli/commands/chat.d.ts +3 -0
- package/dist/cli/commands/chat.d.ts.map +1 -0
- package/dist/cli/commands/chat.js +39 -0
- package/dist/cli/commands/chat.js.map +1 -0
- package/dist/cli/commands/config.d.ts +3 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +289 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/init.d.ts +3 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +114 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/list.d.ts +3 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +109 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +3 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +51 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/start.d.ts +3 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +34 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +3 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +45 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +3 -0
- package/dist/cli/commands/stop.d.ts.map +1 -0
- package/dist/cli/commands/stop.js +54 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +79 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/services/base/index.d.ts +112 -0
- package/dist/services/base/index.d.ts.map +1 -0
- package/dist/services/base/index.js +51 -0
- package/dist/services/base/index.js.map +1 -0
- package/dist/services/base/types.d.ts +114 -0
- package/dist/services/base/types.d.ts.map +1 -0
- package/dist/services/base/types.js +7 -0
- package/dist/services/base/types.js.map +1 -0
- package/dist/services/chatgpt/api-client.d.ts +81 -0
- package/dist/services/chatgpt/api-client.d.ts.map +1 -0
- package/dist/services/chatgpt/api-client.js +325 -0
- package/dist/services/chatgpt/api-client.js.map +1 -0
- package/dist/services/chatgpt/cli-adapter.d.ts +108 -0
- package/dist/services/chatgpt/cli-adapter.d.ts.map +1 -0
- package/dist/services/chatgpt/cli-adapter.js +315 -0
- package/dist/services/chatgpt/cli-adapter.js.map +1 -0
- package/dist/services/chatgpt/config-manager.d.ts +87 -0
- package/dist/services/chatgpt/config-manager.d.ts.map +1 -0
- package/dist/services/chatgpt/config-manager.js +344 -0
- package/dist/services/chatgpt/config-manager.js.map +1 -0
- package/dist/services/chatgpt/config-wizard.d.ts +35 -0
- package/dist/services/chatgpt/config-wizard.d.ts.map +1 -0
- package/dist/services/chatgpt/config-wizard.js +524 -0
- package/dist/services/chatgpt/config-wizard.js.map +1 -0
- package/dist/services/chatgpt/error-handler.d.ts +94 -0
- package/dist/services/chatgpt/error-handler.d.ts.map +1 -0
- package/dist/services/chatgpt/error-handler.js +409 -0
- package/dist/services/chatgpt/error-handler.js.map +1 -0
- package/dist/services/chatgpt/exports.d.ts +71 -0
- package/dist/services/chatgpt/exports.d.ts.map +1 -0
- package/dist/services/chatgpt/exports.js +81 -0
- package/dist/services/chatgpt/exports.js.map +1 -0
- package/dist/services/chatgpt/index.d.ts +125 -0
- package/dist/services/chatgpt/index.d.ts.map +1 -0
- package/dist/services/chatgpt/index.js +394 -0
- package/dist/services/chatgpt/index.js.map +1 -0
- package/dist/services/chatgpt/service-adapter.d.ts +152 -0
- package/dist/services/chatgpt/service-adapter.d.ts.map +1 -0
- package/dist/services/chatgpt/service-adapter.js +430 -0
- package/dist/services/chatgpt/service-adapter.js.map +1 -0
- package/dist/services/chatgpt/session-manager.d.ts +113 -0
- package/dist/services/chatgpt/session-manager.d.ts.map +1 -0
- package/dist/services/chatgpt/session-manager.js +396 -0
- package/dist/services/chatgpt/session-manager.js.map +1 -0
- package/dist/services/chatgpt/types.d.ts +130 -0
- package/dist/services/chatgpt/types.d.ts.map +1 -0
- package/dist/services/chatgpt/types.js +19 -0
- package/dist/services/chatgpt/types.js.map +1 -0
- package/dist/utils/config.d.ts +61 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +215 -0
- package/dist/utils/config.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT Service Adapter
|
|
3
|
+
* Main service class that integrates API client, session management, and chat functionality
|
|
4
|
+
*/
|
|
5
|
+
import { ChatGPTConfig, ChatGPTMode, ChatMessage, Conversation, AuthenticationResponse, UsageStats } from './types';
|
|
6
|
+
import { SessionData } from './session-manager';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
export interface ChatOptions {
|
|
9
|
+
conversationId?: string;
|
|
10
|
+
stream?: boolean;
|
|
11
|
+
temperature?: number;
|
|
12
|
+
maxTokens?: number;
|
|
13
|
+
systemPrompt?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ChatResponse {
|
|
16
|
+
conversationId: string;
|
|
17
|
+
message: ChatMessage;
|
|
18
|
+
usage: {
|
|
19
|
+
prompt_tokens: number;
|
|
20
|
+
completion_tokens: number;
|
|
21
|
+
total_tokens: number;
|
|
22
|
+
};
|
|
23
|
+
finish_reason: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class ChatGPTService extends EventEmitter {
|
|
26
|
+
private client;
|
|
27
|
+
private sessionManager;
|
|
28
|
+
private config;
|
|
29
|
+
private usageStats;
|
|
30
|
+
private isInitialized;
|
|
31
|
+
constructor(config: ChatGPTConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Set up event forwarding from child components
|
|
34
|
+
*/
|
|
35
|
+
private setupEventForwarding;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the service
|
|
38
|
+
*/
|
|
39
|
+
initialize(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Authenticate user
|
|
42
|
+
*/
|
|
43
|
+
authenticate(email: string, password: string): Promise<AuthenticationResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Send a chat message
|
|
46
|
+
*/
|
|
47
|
+
chat(message: string, options?: ChatOptions): Promise<ChatResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Make chat completion request to API
|
|
50
|
+
*/
|
|
51
|
+
private makeChatRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Create new conversation
|
|
54
|
+
*/
|
|
55
|
+
private createNewConversation;
|
|
56
|
+
/**
|
|
57
|
+
* Update usage statistics
|
|
58
|
+
*/
|
|
59
|
+
private updateUsageStats;
|
|
60
|
+
/**
|
|
61
|
+
* Reset usage statistics
|
|
62
|
+
*/
|
|
63
|
+
resetUsageStats(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get conversation by ID
|
|
66
|
+
*/
|
|
67
|
+
getConversation(conversationId: string): Conversation | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get all conversations
|
|
70
|
+
*/
|
|
71
|
+
getAllConversations(): Conversation[];
|
|
72
|
+
/**
|
|
73
|
+
* Delete conversation
|
|
74
|
+
*/
|
|
75
|
+
deleteConversation(conversationId: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Get current session
|
|
78
|
+
*/
|
|
79
|
+
getCurrentSession(): SessionData | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get all sessions
|
|
82
|
+
*/
|
|
83
|
+
getAllSessions(): SessionData[];
|
|
84
|
+
/**
|
|
85
|
+
* Switch session
|
|
86
|
+
*/
|
|
87
|
+
switchSession(sessionId: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Clear current session
|
|
90
|
+
*/
|
|
91
|
+
clearCurrentSession(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Get usage statistics
|
|
94
|
+
*/
|
|
95
|
+
getUsageStats(): UsageStats;
|
|
96
|
+
/**
|
|
97
|
+
* Get rate limit information
|
|
98
|
+
*/
|
|
99
|
+
getRateLimitInfo(): import("./types").RateLimitInfo;
|
|
100
|
+
/**
|
|
101
|
+
* Get service configuration
|
|
102
|
+
*/
|
|
103
|
+
getConfig(): ChatGPTConfig;
|
|
104
|
+
/**
|
|
105
|
+
* Update configuration
|
|
106
|
+
*/
|
|
107
|
+
updateConfig(newConfig: Partial<ChatGPTConfig>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Get service status
|
|
110
|
+
*/
|
|
111
|
+
getStatus(): {
|
|
112
|
+
initialized: boolean;
|
|
113
|
+
mode: ChatGPTMode;
|
|
114
|
+
authenticated: boolean;
|
|
115
|
+
hasActiveSession: boolean;
|
|
116
|
+
totalConversations: number;
|
|
117
|
+
totalTokens: number;
|
|
118
|
+
rateLimited: boolean;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Clean up resources
|
|
122
|
+
*/
|
|
123
|
+
destroy(): void;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/chatgpt/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAiD,YAAY,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnK,OAAO,EAAyB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,WAAW,WAAW;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,C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;IAInD;;OAEG;IACH,iBAAiB,IAAI,WAAW,GAAG,SAAS;IAI5C;;OAEG;IACH,cAAc,IAAI,WAAW,EAAE;IAI/B;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIzC;;OAEG;IACH,mBAAmB,IAAI,IAAI;IAI3B;;OAEG;IACH,aAAa,IAAI,UAAU;IAI3B;;OAEG;IACH,gBAAgB;IAIhB;;OAEG;IACH,SAAS,IAAI,aAAa;IAI1B;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI;IAWrD;;OAEG;IACH,SAAS,IAAI;QACX,WAAW,EAAE,OAAO,CAAC;QACrB,IAAI,EAAE,WAAW,CAAC;QAClB,aAAa,EAAE,OAAO,CAAC;QACvB,gBAAgB,EAAE,OAAO,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;KACtB;IAgBD;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB"}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ChatGPT Service Adapter
|
|
4
|
+
* Main service class that integrates API client, session management, and chat functionality
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.ChatGPTService = void 0;
|
|
41
|
+
const types_1 = require("./types");
|
|
42
|
+
const api_client_1 = require("./api-client");
|
|
43
|
+
const session_manager_1 = require("./session-manager");
|
|
44
|
+
const events_1 = require("events");
|
|
45
|
+
const crypto = __importStar(require("crypto"));
|
|
46
|
+
class ChatGPTService extends events_1.EventEmitter {
|
|
47
|
+
client;
|
|
48
|
+
sessionManager;
|
|
49
|
+
config;
|
|
50
|
+
usageStats;
|
|
51
|
+
isInitialized = false;
|
|
52
|
+
constructor(config) {
|
|
53
|
+
super();
|
|
54
|
+
this.config = config;
|
|
55
|
+
this.usageStats = {
|
|
56
|
+
total_tokens: 0,
|
|
57
|
+
prompt_tokens: 0,
|
|
58
|
+
completion_tokens: 0,
|
|
59
|
+
requests: 0,
|
|
60
|
+
rate_limited: false,
|
|
61
|
+
last_reset: Date.now()
|
|
62
|
+
};
|
|
63
|
+
// Initialize API client
|
|
64
|
+
this.client = new api_client_1.ChatGPTAPIClient(config);
|
|
65
|
+
// Initialize session manager
|
|
66
|
+
this.sessionManager = new session_manager_1.ChatGPTSessionManager(this.client, config);
|
|
67
|
+
// Set up event forwarding
|
|
68
|
+
this.setupEventForwarding();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set up event forwarding from child components
|
|
72
|
+
*/
|
|
73
|
+
setupEventForwarding() {
|
|
74
|
+
// Forward client events
|
|
75
|
+
this.client.on('request:start', (data) => this.emit('request:start', data));
|
|
76
|
+
this.client.on('request:success', (data) => this.emit('request:success', data));
|
|
77
|
+
this.client.on('request:error', (data) => this.emit('request:error', data));
|
|
78
|
+
this.client.on('ratelimit:update', (data) => this.emit('ratelimit:update', data));
|
|
79
|
+
this.client.on('ratelimit:exceeded', (data) => this.emit('ratelimit:exceeded', data));
|
|
80
|
+
this.client.on('ratelimit:waiting', (data) => this.emit('ratelimit:waiting', data));
|
|
81
|
+
this.client.on('ratelimit:reset', (data) => this.emit('ratelimit:reset', data));
|
|
82
|
+
this.client.on('error', (data) => this.emit('client:error', data));
|
|
83
|
+
this.client.on('config:updated', (data) => this.emit('config:updated', data));
|
|
84
|
+
// Forward session manager events
|
|
85
|
+
this.sessionManager.on('auth:start', () => this.emit('auth:start'));
|
|
86
|
+
this.sessionManager.on('auth:success', (data) => this.emit('auth:success', data));
|
|
87
|
+
this.sessionManager.on('auth:failed', (data) => this.emit('auth:failed', data));
|
|
88
|
+
this.sessionManager.on('auth:error', (data) => this.emit('auth:error', data));
|
|
89
|
+
this.sessionManager.on('session:created', (data) => this.emit('session:created', data));
|
|
90
|
+
this.sessionManager.on('session:expired', () => this.emit('session:expired'));
|
|
91
|
+
this.sessionManager.on('session:refreshed', (data) => this.emit('session:refreshed', data));
|
|
92
|
+
this.sessionManager.on('session:switched', (data) => this.emit('session:switched', data));
|
|
93
|
+
this.sessionManager.on('session:cleared', (data) => this.emit('session:cleared', data));
|
|
94
|
+
this.sessionManager.on('session:error', (data) => this.emit('session:error', data));
|
|
95
|
+
this.sessionManager.on('conversation:added', (data) => this.emit('conversation:added', data));
|
|
96
|
+
this.sessionManager.on('conversation:updated', (data) => this.emit('conversation:updated', data));
|
|
97
|
+
this.sessionManager.on('conversation:deleted', (data) => this.emit('conversation:deleted', data));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Initialize the service
|
|
101
|
+
*/
|
|
102
|
+
async initialize() {
|
|
103
|
+
if (this.isInitialized) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
this.emit('service:initializing');
|
|
108
|
+
// For authenticated mode, check if we have credentials
|
|
109
|
+
if (this.config.mode === types_1.ChatGPTMode.AUTHENTICATED && this.config.credentials) {
|
|
110
|
+
const { email, password } = this.config.credentials;
|
|
111
|
+
if (email && password) {
|
|
112
|
+
await this.authenticate(email, password);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Clean up expired sessions
|
|
116
|
+
this.sessionManager.cleanupExpiredSessions();
|
|
117
|
+
this.isInitialized = true;
|
|
118
|
+
this.emit('service:initialized');
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.emit('service:init:error', error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Authenticate user
|
|
127
|
+
*/
|
|
128
|
+
async authenticate(email, password) {
|
|
129
|
+
this.emit('service:auth:attempt', { email });
|
|
130
|
+
try {
|
|
131
|
+
const response = await this.sessionManager.authenticate(email, password);
|
|
132
|
+
if (response.authenticated) {
|
|
133
|
+
// Update configuration with new credentials
|
|
134
|
+
this.config.credentials = {
|
|
135
|
+
email,
|
|
136
|
+
password,
|
|
137
|
+
access_token: response.access_token,
|
|
138
|
+
refresh_token: response.refresh_token,
|
|
139
|
+
session_token: response.session_token
|
|
140
|
+
};
|
|
141
|
+
this.client.updateConfig({
|
|
142
|
+
credentials: this.config.credentials
|
|
143
|
+
});
|
|
144
|
+
this.emit('service:auth:success', response);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.emit('service:auth:failed', { email, reason: 'Invalid credentials' });
|
|
148
|
+
}
|
|
149
|
+
return response;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
this.emit('service:auth:error', { email, error });
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Send a chat message
|
|
158
|
+
*/
|
|
159
|
+
async chat(message, options = {}) {
|
|
160
|
+
if (!this.isInitialized) {
|
|
161
|
+
await this.initialize();
|
|
162
|
+
}
|
|
163
|
+
this.emit('chat:start', { message, options });
|
|
164
|
+
try {
|
|
165
|
+
// Get or create conversation
|
|
166
|
+
let conversation;
|
|
167
|
+
if (options.conversationId) {
|
|
168
|
+
const existing = this.sessionManager.getConversation(options.conversationId);
|
|
169
|
+
if (!existing) {
|
|
170
|
+
throw new Error(`Conversation ${options.conversationId} not found`);
|
|
171
|
+
}
|
|
172
|
+
conversation = existing;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
conversation = this.createNewConversation(options.systemPrompt);
|
|
176
|
+
}
|
|
177
|
+
// Prepare messages
|
|
178
|
+
const messages = [...conversation.messages];
|
|
179
|
+
if (options.systemPrompt && conversation.messages.length === 0) {
|
|
180
|
+
messages.unshift({
|
|
181
|
+
role: 'system',
|
|
182
|
+
content: options.systemPrompt
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
messages.push({
|
|
186
|
+
role: 'user',
|
|
187
|
+
content: message
|
|
188
|
+
});
|
|
189
|
+
// Prepare API request
|
|
190
|
+
const request = {
|
|
191
|
+
model: this.config.model,
|
|
192
|
+
messages,
|
|
193
|
+
max_tokens: options.maxTokens || this.config.max_tokens,
|
|
194
|
+
temperature: options.temperature || this.config.temperature,
|
|
195
|
+
top_p: this.config.top_p,
|
|
196
|
+
frequency_penalty: this.config.frequency_penalty,
|
|
197
|
+
presence_penalty: this.config.presence_penalty,
|
|
198
|
+
stream: options.stream || false,
|
|
199
|
+
user: this.sessionManager.getCurrentSession()?.user_id
|
|
200
|
+
};
|
|
201
|
+
// Make API call
|
|
202
|
+
this.emit('chat:request', { conversationId: conversation.id, request });
|
|
203
|
+
const response = await this.makeChatRequest(request);
|
|
204
|
+
// Update conversation
|
|
205
|
+
const assistantMessage = {
|
|
206
|
+
role: 'assistant',
|
|
207
|
+
content: response.choices[0].message.content
|
|
208
|
+
};
|
|
209
|
+
conversation.messages.push({ role: 'user', content: message }, assistantMessage);
|
|
210
|
+
conversation.updated_at = Date.now();
|
|
211
|
+
conversation.token_count += response.usage.total_tokens;
|
|
212
|
+
this.sessionManager.updateConversation(conversation);
|
|
213
|
+
// Update usage statistics
|
|
214
|
+
this.updateUsageStats(response.usage);
|
|
215
|
+
const chatResponse = {
|
|
216
|
+
conversationId: conversation.id,
|
|
217
|
+
message: assistantMessage,
|
|
218
|
+
usage: response.usage,
|
|
219
|
+
finish_reason: response.choices[0].finish_reason
|
|
220
|
+
};
|
|
221
|
+
this.emit('chat:success', chatResponse);
|
|
222
|
+
return chatResponse;
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
this.emit('chat:error', { message, options, error });
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Make chat completion request to API
|
|
231
|
+
*/
|
|
232
|
+
async makeChatRequest(request) {
|
|
233
|
+
this.usageStats.requests++;
|
|
234
|
+
try {
|
|
235
|
+
const response = await this.client.chatCompletion(request);
|
|
236
|
+
return response;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (error.response?.status === 429) {
|
|
240
|
+
this.usageStats.rate_limited = true;
|
|
241
|
+
}
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Create new conversation
|
|
247
|
+
*/
|
|
248
|
+
createNewConversation(systemPrompt) {
|
|
249
|
+
const conversationId = `conv_${crypto.randomBytes(8).toString('hex')}`;
|
|
250
|
+
const now = Date.now();
|
|
251
|
+
const conversation = {
|
|
252
|
+
id: conversationId,
|
|
253
|
+
title: 'New Conversation',
|
|
254
|
+
created_at: now,
|
|
255
|
+
updated_at: now,
|
|
256
|
+
messages: systemPrompt ? [
|
|
257
|
+
{
|
|
258
|
+
role: 'system',
|
|
259
|
+
content: systemPrompt
|
|
260
|
+
}
|
|
261
|
+
] : [],
|
|
262
|
+
model: this.config.model,
|
|
263
|
+
token_count: 0
|
|
264
|
+
};
|
|
265
|
+
this.sessionManager.addConversation(conversation);
|
|
266
|
+
return conversation;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Update usage statistics
|
|
270
|
+
*/
|
|
271
|
+
updateUsageStats(usage) {
|
|
272
|
+
this.usageStats.total_tokens += usage.total_tokens;
|
|
273
|
+
this.usageStats.prompt_tokens += usage.prompt_tokens;
|
|
274
|
+
this.usageStats.completion_tokens += usage.completion_tokens;
|
|
275
|
+
// Reset daily if needed
|
|
276
|
+
const now = Date.now();
|
|
277
|
+
const oneDay = 24 * 60 * 60 * 1000;
|
|
278
|
+
if (now - this.usageStats.last_reset > oneDay) {
|
|
279
|
+
this.resetUsageStats();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Reset usage statistics
|
|
284
|
+
*/
|
|
285
|
+
resetUsageStats() {
|
|
286
|
+
this.usageStats = {
|
|
287
|
+
total_tokens: 0,
|
|
288
|
+
prompt_tokens: 0,
|
|
289
|
+
completion_tokens: 0,
|
|
290
|
+
requests: 0,
|
|
291
|
+
rate_limited: false,
|
|
292
|
+
last_reset: Date.now()
|
|
293
|
+
};
|
|
294
|
+
this.emit('usage:reset', this.usageStats);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get conversation by ID
|
|
298
|
+
*/
|
|
299
|
+
getConversation(conversationId) {
|
|
300
|
+
return this.sessionManager.getConversation(conversationId);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get all conversations
|
|
304
|
+
*/
|
|
305
|
+
getAllConversations() {
|
|
306
|
+
return this.sessionManager.getAllConversations();
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Delete conversation
|
|
310
|
+
*/
|
|
311
|
+
deleteConversation(conversationId) {
|
|
312
|
+
return this.sessionManager.deleteConversation(conversationId);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get current session
|
|
316
|
+
*/
|
|
317
|
+
getCurrentSession() {
|
|
318
|
+
return this.sessionManager.getCurrentSession();
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Get all sessions
|
|
322
|
+
*/
|
|
323
|
+
getAllSessions() {
|
|
324
|
+
return this.sessionManager.getAllSessions();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Switch session
|
|
328
|
+
*/
|
|
329
|
+
switchSession(sessionId) {
|
|
330
|
+
return this.sessionManager.switchSession(sessionId);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Clear current session
|
|
334
|
+
*/
|
|
335
|
+
clearCurrentSession() {
|
|
336
|
+
this.sessionManager.clearCurrentSession();
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get usage statistics
|
|
340
|
+
*/
|
|
341
|
+
getUsageStats() {
|
|
342
|
+
return { ...this.usageStats };
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get rate limit information
|
|
346
|
+
*/
|
|
347
|
+
getRateLimitInfo() {
|
|
348
|
+
return this.client.getRateLimitInfo();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Get service configuration
|
|
352
|
+
*/
|
|
353
|
+
getConfig() {
|
|
354
|
+
return { ...this.config };
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Update configuration
|
|
358
|
+
*/
|
|
359
|
+
updateConfig(newConfig) {
|
|
360
|
+
this.config = { ...this.config, ...newConfig };
|
|
361
|
+
this.client.updateConfig(newConfig);
|
|
362
|
+
if (newConfig.mode === types_1.ChatGPTMode.AUTHENTICATED && newConfig.credentials) {
|
|
363
|
+
this.sessionManager.cleanupExpiredSessions();
|
|
364
|
+
}
|
|
365
|
+
this.emit('service:config:updated', this.config);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Get service status
|
|
369
|
+
*/
|
|
370
|
+
getStatus() {
|
|
371
|
+
const session = this.getCurrentSession();
|
|
372
|
+
const conversations = this.getAllConversations();
|
|
373
|
+
const totalTokens = conversations.reduce((sum, conv) => sum + conv.token_count, 0);
|
|
374
|
+
return {
|
|
375
|
+
initialized: this.isInitialized,
|
|
376
|
+
mode: this.config.mode,
|
|
377
|
+
authenticated: !!session,
|
|
378
|
+
hasActiveSession: !!session,
|
|
379
|
+
totalConversations: conversations.length,
|
|
380
|
+
totalTokens,
|
|
381
|
+
rateLimited: this.usageStats.rate_limited
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Clean up resources
|
|
386
|
+
*/
|
|
387
|
+
destroy() {
|
|
388
|
+
this.sessionManager.destroy();
|
|
389
|
+
this.removeAllListeners();
|
|
390
|
+
this.emit('service:destroyed');
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
exports.ChatGPTService = ChatGPTService;
|
|
394
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/chatgpt/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAmK;AACnK,6CAAgD;AAChD,uDAAuE;AACvE,mCAAsC;AACtC,+CAAiC;AAqBjC,MAAa,cAAe,SAAQ,qBAAY;IACtC,MAAM,CAAmB;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