Ver código fonte

browser: renamed to websearch/webcrawl (#247)

nicole pardal 6 dias atrás
pai
commit
ab1e7a8ea3
2 arquivos alterados com 9 adições e 10 exclusões
  1. 7 8
      examples/websearch/websearch-tools.ts
  2. 2 2
      src/browser.ts

+ 7 - 8
examples/websearch/websearch-tools.ts

@@ -54,10 +54,10 @@ async function main() {
 
   const availableTools = {
     websearch: async (args: { queries: string[]; max_results?: number }) => {
-      return await client.search(args)
+      return await client.websearch(args)
     },
     webcrawl: async (args: { urls: string[] }) => {
-      return await client.crawl(args)
+      return await client.webcrawl(args)
     },
   }
 
@@ -71,7 +71,7 @@ async function main() {
   console.log('----- Prompt:', messages.find((m) => m.role === 'user')?.content, '\n')
 
   while (true) {
-    const response = await ollama.chat({
+    const response = await client.chat({
       model: 'gpt-oss',
       messages: messages,
       tools: [websearchTool, webcrawlTool],
@@ -102,13 +102,14 @@ async function main() {
         process.stdout.write(chunk.message.content)
       }
       if (chunk.message.tool_calls && chunk.message.tool_calls.length > 0) {
+        hadToolCalls = true
         messages.push({
           role: 'assistant',
           content: content,
           thinking: thinking,
+          tool_calls: chunk.message.tool_calls,
         })
-        
-        hadToolCalls = true
+        // Execute tools and append tool results
         for (const toolCall of chunk.message.tool_calls) {
           const functionToCall = availableTools[toolCall.function.name]
           if (functionToCall) {
@@ -116,10 +117,8 @@ async function main() {
             console.log('\nCalling function:', toolCall.function.name, 'with arguments:', args)
             const output = await functionToCall(args)
             console.log('Function output:', JSON.stringify(output).slice(0, 200), '\n')
-
-            // message history
+            
             messages.push(chunk.message)
-            // tool result
             messages.push({
               role: 'tool',
               content: JSON.stringify(output),

+ 2 - 2
src/browser.ts

@@ -331,7 +331,7 @@ async encodeImage(image: Uint8Array | string): Promise<string> {
    * @returns {Promise<SearchResponse>} - The search results
    * @throws {Error} - If the request is invalid or the server returns an error
    */
-  async search(request: SearchRequest): Promise<SearchResponse> {
+  async websearch(request: SearchRequest): Promise<SearchResponse> {
     if (!request.queries || request.queries.length === 0) {
       throw new Error('At least one query is required')
     }
@@ -348,7 +348,7 @@ async encodeImage(image: Uint8Array | string): Promise<string> {
    * @returns {Promise<CrawlResponse>} - The crawl results
    * @throws {Error} - If the request is invalid or the server returns an error
    */
-  async crawl(request: CrawlRequest): Promise<CrawlResponse> {
+  async webcrawl(request: CrawlRequest): Promise<CrawlResponse> {
     if (!request.urls || request.urls.length === 0) {
       throw new Error('At least one URL is required')
     }