File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
packages/langbase/src/lib/helpers Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11import { ChatCompletionStream } from 'openai/lib/ChatCompletionStream' ;
22import { Stream } from 'openai/streaming' ;
33import { ChatCompletionMessageToolCall } from 'openai/resources/chat/completions' ;
4+ import { RunResponse , RunResponseStream } from '@/langbase/langbase' ;
45
56export interface Runner extends ChatCompletionStream { }
67
@@ -121,3 +122,25 @@ export async function getToolsFromStream(
121122 const tools = choices [ 0 ] . message . tool_calls ;
122123 return tools ?? [ ] ;
123124}
125+
126+ /**
127+ * Retrieves tools from a readable stream asynchronously.
128+ *
129+ * @param stream - The readable stream to extract tools from
130+ * @returns A promise that resolves with the tools extracted from the stream
131+ */
132+ export async function getToolsFromRunStream ( response : RunResponseStream ) {
133+ return getToolsFromStream ( response . stream ) ;
134+ }
135+
136+ /**
137+ * Extracts tool calls from non-stream response.
138+ * @param response - The run response object
139+ * @returns A promise that resolves to an array of tool calls. Returns empty array if no tools are present.
140+ */
141+ export async function getToolsFromRun (
142+ response : RunResponse ,
143+ ) : Promise < ChatCompletionMessageToolCall [ ] > {
144+ const tools = response . choices [ 0 ] . message . tool_calls ;
145+ return tools ?? [ ] ;
146+ }
You can’t perform that action at this time.
0 commit comments