File tree Expand file tree Collapse file tree 3 files changed +21
-28
lines changed Expand file tree Collapse file tree 3 files changed +21
-28
lines changed Original file line number Diff line number Diff line change 1
1
import type { Runner } from 'src/helpers' ;
2
- import { Pipe as PipeI } from '../../types/pipes' ;
2
+ import { Message , MessageRole , Pipe as PipeI , ToolCall } from '../../types/pipes' ;
3
3
import { Request } from '../common/request' ;
4
4
import { getLLMApiKey } from '../utils/get-llm-api-key' ;
5
5
import { getApiUrl , isProd } from '../utils/is-prod' ;
6
6
import { toOldPipeFormat } from '../utils/to-old-pipe-format' ;
7
7
import { isLocalServerRunning } from 'src/utils/local-server-running' ;
8
8
9
- // Type Definitions
10
- export type Role = 'user' | 'assistant' | 'system' | 'tool' ;
11
-
12
- export interface Function {
13
- name : string ;
14
- arguments : string ;
15
- }
16
-
17
- export interface ToolCall {
18
- id : string ;
19
- type : 'function' ;
20
- function : Function ;
21
- }
22
-
23
- export interface Message {
24
- role : Role ;
25
- content : string | null ;
26
- name ?: string ;
27
- tool_call_id ?: string ;
28
- tool_calls ?: ToolCall [ ] ;
29
- }
30
-
31
9
export interface Variable {
32
10
name : string ;
33
11
value : string ;
@@ -137,7 +115,7 @@ export class Pipe {
137
115
138
116
return {
139
117
tool_call_id : toolCall . id ,
140
- role : 'tool' as Role ,
118
+ role : 'tool' as MessageRole ,
141
119
name : toolName ,
142
120
content : JSON . stringify ( toolResponse ) ,
143
121
} ;
@@ -330,7 +308,7 @@ interface ChoiceStream {
330
308
}
331
309
332
310
interface Delta {
333
- role ?: Role ;
311
+ role ?: MessageRole ;
334
312
content ?: string ;
335
313
tool_calls ?: ToolCall [ ] ;
336
314
}
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ export function usePipe({
116
116
) ;
117
117
118
118
const sendRequest = useCallback (
119
- async ( content : string , options : PipeRequestOptions = { } ) => {
119
+ async ( content : string | null , options : PipeRequestOptions = { } ) => {
120
120
abortControllerRef . current = new AbortController ( ) ;
121
121
const { signal} = abortControllerRef . current ;
122
122
@@ -127,7 +127,8 @@ export function usePipe({
127
127
128
128
let updatedMessages = messagesRef . current ;
129
129
130
- if ( content . trim ( ) ) {
130
+ const hasContent = content && content . trim ( ) ;
131
+ if ( hasContent ) {
131
132
// Add new user message only if content is not empty
132
133
updatedMessages = [
133
134
...messagesRef . current ,
Original file line number Diff line number Diff line change @@ -10,12 +10,26 @@ import {
10
10
PerplexityModels ,
11
11
TogetherModels ,
12
12
} from './model' ;
13
+
13
14
export type MessageRole = 'function' | 'assistant' | 'system' | 'user' | 'tool' ;
14
15
16
+ export interface Function {
17
+ name : string ;
18
+ arguments : string ;
19
+ }
20
+
21
+ export interface ToolCall {
22
+ id : string ;
23
+ type : 'function' ;
24
+ function : Function ;
25
+ }
26
+
15
27
export interface Message {
16
28
role : MessageRole ;
17
- content : string ;
29
+ content : string | null ;
18
30
name ?: string ;
31
+ tool_call_id ?: string ;
32
+ tool_calls ?: ToolCall [ ] ;
19
33
}
20
34
21
35
interface ToolFunction {
You canβt perform that action at this time.
0 commit comments