listpage-next-nest 0.0.151 → 0.0.162

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.
@@ -649,6 +649,123 @@ class VolcengineProvider extends BaseProvider {
649
649
  super(...args), this.baseURL = 'https://ark.cn-beijing.volces.com/api/v3/chat/completions ';
650
650
  }
651
651
  }
652
+ class MetaProvider extends BaseProvider {
653
+ handleJson(json) {
654
+ const message = json.choices[0].message;
655
+ return {
656
+ model: json.model,
657
+ content: message.content || '',
658
+ reasoning_content: void 0,
659
+ citations: (message.citations || []).map((c)=>({
660
+ content: c.snippet,
661
+ title: c.title,
662
+ url: c.link,
663
+ date: c.date
664
+ })),
665
+ usage: {
666
+ input: json.usage.prompt_tokens,
667
+ output: json.usage.completion_tokens,
668
+ total: json.usage.total_tokens
669
+ }
670
+ };
671
+ }
672
+ async handleStream(subject, stream) {
673
+ const decoder = new TextDecoder();
674
+ const reader = stream.getReader();
675
+ let buffer = '';
676
+ const handleBuffer = (buffer, onParsed)=>{
677
+ const lines = buffer.split('\n');
678
+ const lastLine = lines.pop();
679
+ const event = {};
680
+ lines.forEach((line)=>{
681
+ if ('' === line.trim()) return void onParsed(event);
682
+ const [name, ...values] = line.split(':');
683
+ const text = values.join(':').trim();
684
+ if ('[DONE]' === text.toUpperCase()) return;
685
+ const data = 'data' === name ? parseJson(text) : text;
686
+ event[name] = data;
687
+ });
688
+ return lastLine;
689
+ };
690
+ let usage = {};
691
+ while(true){
692
+ const { done, value } = await reader.read();
693
+ if (done) break;
694
+ const text = decoder.decode(value, {
695
+ stream: true
696
+ });
697
+ buffer += text;
698
+ buffer = handleBuffer(buffer, (event)=>{
699
+ if (event.data?.object !== 'chat.completion') return;
700
+ usage = event.data.usage;
701
+ const delta = event.data.choices[0].delta;
702
+ if (delta.citations) return void subject.next({
703
+ type: 'citations',
704
+ data: {
705
+ citations: delta.citations.map((c)=>({
706
+ title: c.title,
707
+ url: c.link,
708
+ content: c.content || '',
709
+ date: c.date
710
+ }))
711
+ }
712
+ });
713
+ if (delta.reasoning_content) return void subject.next({
714
+ type: 'thinking',
715
+ data: {
716
+ model: event.data.model,
717
+ content: delta.reasoning_content
718
+ }
719
+ });
720
+ if (delta.content) return void subject.next({
721
+ type: 'chunk',
722
+ data: {
723
+ model: event.data.model,
724
+ content: delta.content
725
+ }
726
+ });
727
+ });
728
+ }
729
+ subject.next({
730
+ type: 'complete',
731
+ data: {
732
+ usage: {
733
+ input: usage?.prompt_tokens || 0,
734
+ output: usage?.completion_tokens || 0,
735
+ total: usage?.total_tokens || 0
736
+ }
737
+ }
738
+ });
739
+ subject.complete();
740
+ }
741
+ async request(options) {
742
+ const { api_key, ...restOptions } = options;
743
+ const headers = {
744
+ 'Content-Type': 'application/json',
745
+ Authorization: `Bearer ${api_key}`
746
+ };
747
+ const body = restOptions;
748
+ const response = await fetch(this.baseURL, {
749
+ method: 'POST',
750
+ headers,
751
+ body: JSON.stringify(body)
752
+ });
753
+ if (!response.ok) {
754
+ const error = await response.text();
755
+ throw new common_namespaceObject.BadRequestException(`HTTP ${response.status}: ${error}`);
756
+ }
757
+ return response;
758
+ }
759
+ constructor(...args){
760
+ super(...args), this.baseURL = 'https://metaso.cn/api/v1/chat/completions';
761
+ }
762
+ }
763
+ function compilePrompt(prompt, params) {
764
+ const compiled = (0, external_lodash_namespaceObject.template)(prompt, {
765
+ interpolate: /{{([\s\S]+?)}}/g
766
+ });
767
+ return compiled(params);
768
+ }
652
769
  function llm_provider_service_ts_decorate(decorators, target, key, desc) {
653
770
  var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
654
771
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
@@ -662,12 +779,37 @@ class LLMProviderService {
662
779
  const volcengine = new VolcengineProvider();
663
780
  return volcengine.call(params);
664
781
  }
782
+ if ('meta' === provider) {
783
+ const meta = new MetaProvider();
784
+ return meta.call(params);
785
+ }
665
786
  throw new common_namespaceObject.BadRequestException('不支持该大模型提供商');
666
787
  }
788
+ async run(options) {
789
+ const { system, user, data = {}, provider, params } = options;
790
+ const messages = [
791
+ {
792
+ role: 'system',
793
+ content: compilePrompt(system, data)
794
+ },
795
+ {
796
+ role: 'user',
797
+ content: user
798
+ }
799
+ ];
800
+ return this.call({
801
+ provider,
802
+ params: {
803
+ ...params,
804
+ messages
805
+ }
806
+ });
807
+ }
667
808
  async sse(options, callback) {
668
809
  const { provider, params } = options;
669
810
  const ProviderConstructors = {
670
- volcengine: VolcengineProvider
811
+ volcengine: VolcengineProvider,
812
+ meta: MetaProvider
671
813
  };
672
814
  const Constructor = ProviderConstructors[provider];
673
815
  if (!Constructor) throw new common_namespaceObject.BadRequestException('不支持该大模型提供商');
@@ -707,6 +849,7 @@ LLMProviderModule = llm_provider_module_ts_decorate([
707
849
  ], LLMProviderModule);
708
850
  var types_SupportProvider = /*#__PURE__*/ function(SupportProvider) {
709
851
  SupportProvider["volcengine"] = "volcengine";
852
+ SupportProvider["meta"] = "meta";
710
853
  return SupportProvider;
711
854
  }({});
712
855
  var types_ServerSendEventName = /*#__PURE__*/ function(ServerSendEventName) {
@@ -715,6 +858,7 @@ var types_ServerSendEventName = /*#__PURE__*/ function(ServerSendEventName) {
715
858
  ServerSendEventName["Processing"] = "processing";
716
859
  ServerSendEventName["Chunk"] = "chunk";
717
860
  ServerSendEventName["Complete"] = "complete";
861
+ ServerSendEventName["Citations"] = "citations";
718
862
  return ServerSendEventName;
719
863
  }({});
720
864
  exports.AdminAuthGuard = __webpack_exports__.AdminAuthGuard;
@@ -52,6 +52,15 @@ export declare class BaseQueryDto {
52
52
  get take(): number;
53
53
  }
54
54
 
55
+ declare type CitationItem = {
56
+ title: string;
57
+ url: string;
58
+ content?: string;
59
+ source?: string;
60
+ date?: string;
61
+ icon?: string;
62
+ };
63
+
55
64
  export declare class CorsInterceptor implements NestInterceptor {
56
65
  intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
57
66
  }
@@ -69,8 +78,17 @@ export declare type LLMProviderCallOptions = {
69
78
  export declare class LLMProviderModule {
70
79
  }
71
80
 
81
+ export declare type LLMProviderRunOptions = {
82
+ system: string;
83
+ user: string;
84
+ data?: any;
85
+ provider: SupportProvider;
86
+ params: Omit<ProviderParams[LLMProviderRunOptions['provider']], 'messages'>;
87
+ };
88
+
72
89
  export declare class LLMProviderService {
73
90
  call(options: LLMProviderCallOptions): Promise<ServerSendJsonData>;
91
+ run(options: LLMProviderRunOptions): Promise<ServerSendJsonData>;
74
92
  sse(options: LLMProviderCallOptions, callback?: ServerSendEventCallback): Promise<ReplaySubject<ServerSendEventData>>;
75
93
  }
76
94
 
@@ -79,6 +97,19 @@ export declare class LoggingInterceptor implements NestInterceptor {
79
97
  intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
80
98
  }
81
99
 
100
+ declare type MetaRequestionOption = {
101
+ api_key: string;
102
+ model: 'fast' | 'fast_thinking' | 'ds-r1';
103
+ messages: Array<{
104
+ role: string;
105
+ content: string;
106
+ }>;
107
+ stream?: boolean;
108
+ scope?: 'document' | 'scholar' | 'video' | 'podcast';
109
+ conciseSnippet: boolean;
110
+ [key: string]: any;
111
+ };
112
+
82
113
  export declare class PaginatedResponse<T> extends ApiResponse<PaginationData<T>> {
83
114
  constructor(list: T[], current: number, pageSize: number, total: number, message?: string);
84
115
  static create<T>(list: T[], current: number, pageSize: number, total: number, message?: string): PaginatedResponse<T>;
@@ -94,6 +125,7 @@ export declare class PaginationData<T> {
94
125
 
95
126
  declare type ProviderParams = {
96
127
  [SupportProvider.volcengine]: VolcengineRequestionOption;
128
+ [SupportProvider.meta]: MetaRequestionOption;
97
129
  };
98
130
 
99
131
  export declare const Public: () => CustomDecorator<string>;
@@ -147,7 +179,7 @@ export declare type ServerSendEventCallback<T extends ServerSendEventData['type'
147
179
  }>['data']) => void;
148
180
 
149
181
  export declare type ServerSendEventData = {
150
- type: 'received' | 'thinking' | 'processing' | 'chunk' | 'complete';
182
+ type: 'received' | 'thinking' | 'processing' | 'chunk' | 'complete' | 'citations';
151
183
  data: SevrverSendEventMessages[ServerSendEventData['type']];
152
184
  };
153
185
 
@@ -156,13 +188,15 @@ export declare enum ServerSendEventName {
156
188
  Thinking = "thinking",
157
189
  Processing = "processing",
158
190
  Chunk = "chunk",
159
- Complete = "complete"
191
+ Complete = "complete",
192
+ Citations = "citations"
160
193
  }
161
194
 
162
195
  export declare type ServerSendJsonData = {
163
196
  model?: string;
164
197
  content: string;
165
- reasoning_content: string;
198
+ reasoning_content?: string;
199
+ citations?: Array<CitationItem>;
166
200
  usage: {
167
201
  input: number;
168
202
  output: number;
@@ -190,6 +224,9 @@ export declare type SevrverSendEventMessages = {
190
224
  [ServerSendEventName.Complete]: {
191
225
  usage: ServerSendJsonData['usage'];
192
226
  };
227
+ [ServerSendEventName.Citations]: {
228
+ citations: CitationItem[];
229
+ };
193
230
  };
194
231
 
195
232
  export declare class StaticRouteMiddleware implements NestMiddleware {
@@ -213,7 +250,8 @@ export declare interface StaticRouteOptions {
213
250
  }
214
251
 
215
252
  export declare enum SupportProvider {
216
- volcengine = "volcengine"
253
+ volcengine = "volcengine",
254
+ meta = "meta"
217
255
  }
218
256
 
219
257
  export declare const User: (...dataOrPipes: (string | PipeTransform<any, any> | Type<PipeTransform<any, any>>)[]) => ParameterDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next-nest",
3
- "version": "0.0.151",
3
+ "version": "0.0.162",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "main": "./dist/cjs/index.cjs",
6
6
  "module": "./dist/esm/index.js",