Skip to content

Commit d47e2ca

Browse files
authored
πŸ› FIX: usePipe types (#61)
1 parent 4e89655 commit d47e2ca

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

β€Žpackages/core/src/pipes/pipes.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
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';
33
import {Request} from '../common/request';
44
import {getLLMApiKey} from '../utils/get-llm-api-key';
55
import {getApiUrl, isProd} from '../utils/is-prod';
66
import {toOldPipeFormat} from '../utils/to-old-pipe-format';
77
import {isLocalServerRunning} from 'src/utils/local-server-running';
88

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-
319
export interface Variable {
3210
name: string;
3311
value: string;
@@ -137,7 +115,7 @@ export class Pipe {
137115

138116
return {
139117
tool_call_id: toolCall.id,
140-
role: 'tool' as Role,
118+
role: 'tool' as MessageRole,
141119
name: toolName,
142120
content: JSON.stringify(toolResponse),
143121
};
@@ -330,7 +308,7 @@ interface ChoiceStream {
330308
}
331309

332310
interface Delta {
333-
role?: Role;
311+
role?: MessageRole;
334312
content?: string;
335313
tool_calls?: ToolCall[];
336314
}

β€Žpackages/core/src/react/use-pipe.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function usePipe({
116116
);
117117

118118
const sendRequest = useCallback(
119-
async (content: string, options: PipeRequestOptions = {}) => {
119+
async (content: string | null, options: PipeRequestOptions = {}) => {
120120
abortControllerRef.current = new AbortController();
121121
const {signal} = abortControllerRef.current;
122122

@@ -127,7 +127,8 @@ export function usePipe({
127127

128128
let updatedMessages = messagesRef.current;
129129

130-
if (content.trim()) {
130+
const hasContent = content && content.trim();
131+
if (hasContent) {
131132
// Add new user message only if content is not empty
132133
updatedMessages = [
133134
...messagesRef.current,

β€Žpackages/core/types/pipes.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@ import {
1010
PerplexityModels,
1111
TogetherModels,
1212
} from './model';
13+
1314
export type MessageRole = 'function' | 'assistant' | 'system' | 'user' | 'tool';
1415

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+
1527
export interface Message {
1628
role: MessageRole;
17-
content: string;
29+
content: string | null;
1830
name?: string;
31+
tool_call_id?: string;
32+
tool_calls?: ToolCall[];
1933
}
2034

2135
interface ToolFunction {

0 commit comments

Comments
Β (0)