Skip to content

Commit

Permalink
- fix: pr checks (#30)
Browse files Browse the repository at this point in the history
* - fix: pr checks

* - fix: concurrent tasks

* - fix: dependsOn

* - fix: bundling system tools-runner

* - fix: duck duck go tests

* - fix: tests
  • Loading branch information
agallardol authored Aug 21, 2024
1 parent 67b32cf commit 3dbbd22
Show file tree
Hide file tree
Showing 17 changed files with 5,938 additions and 11,573 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ target
.nx/cache
.nx/workspace-data
libs/shinkai-tools-runner/tools
libs/shinkai-tools-runner/shinka-tools-runner-resources
libs/shinkai-tools-runner/shinkai-tools-runner-resources
6 changes: 4 additions & 2 deletions apps/shinkai-tool-download-page/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder';
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition';
import TurndownService from 'turndown';
import axios from 'axios';

type Config = {};
type Params = {
Expand Down Expand Up @@ -39,8 +40,9 @@ export class Tool extends BaseTool<Config, Params, Result> {
};

async run(params: Params): Promise<RunResult<Result>> {
const response = await fetch(params.url);
const html = await response.text();
await process.nextTick(() => { });
const response = await axios.get(params.url);
const html = response.data;
const turndownService = new TurndownService();
const markdown = turndownService.turndown(html);
return Promise.resolve({ data: { markdown } });
Expand Down
1 change: 0 additions & 1 deletion apps/shinkai-tool-duckduckgo-search/src/Untitled-1.json

This file was deleted.

5 changes: 0 additions & 5 deletions apps/shinkai-tool-duckduckgo-search/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { TextEncoder as NodeTextEncoder, TextDecoder as NodeTextDecoder } from 'util';
global.TextEncoder = NodeTextEncoder as any;
global.TextDecoder = NodeTextDecoder as any;

import { Tool } from '../src/index';
global.fetch = require('node-fetch');

test('searches DuckDuckGo and gets a response', async () => {
const tool = new Tool({});
Expand Down
14 changes: 7 additions & 7 deletions apps/shinkai-tool-duckduckgo-search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ToolDefinition,
} from '@shinkai_protocol/shinkai-tools-builder';
import { URL } from 'whatwg-url';
import axios from 'axios';

type Config = {};
type Params = {
Expand Down Expand Up @@ -56,14 +57,13 @@ export class Tool extends BaseTool<Config, Params, Result> {

private static async getVQD(keywords: string): Promise<string> {
const body = buildQueryString({ q: keywords });
const response = await fetch('https://duckduckgo.com', {
method: 'POST',
await process.nextTick(() => { });
const response = await axios.post('https://duckduckgo.com', body, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body,
});
const text = await response.text();
const text = response.data;
// console.log('DuckDuckGo response HTML:', text);

// Extract vqd token using a regular expression
Expand Down Expand Up @@ -128,14 +128,14 @@ export class Tool extends BaseTool<Config, Params, Result> {
const urlString = url.toString();
console.log('urlString: ', urlString);

const response = await fetch(url.toString(), {
method: 'GET',
await process.nextTick(() => { });
const response = await axios.get(url.toString(), {
headers: {
'Content-Type': 'application/json',
},
});
console.log('response: ', response);
const text = await response.text();
const text = response.data;
console.log('DuckDuckGo search response:', text);

// Parse the response using the custom parser
Expand Down
6 changes: 4 additions & 2 deletions apps/shinkai-tool-ethplorer-tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder';
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition';
import axios from 'axios';

type Config = {};
type Params = {
Expand Down Expand Up @@ -97,8 +98,9 @@ export class Tool extends BaseTool<Config, Params, Result> {

async run(params: Params): Promise<RunResult<Result>> {
const url = `https://api.ethplorer.io/getAddressInfo/${params.address}?apiKey=freekey`;
const response = await fetch(url);
const data = (await response.json()) as {
await process.nextTick(() => { });
const response = await axios.get(url);
const data = response.data as {
address: string;
ETH?: {
balance: number;
Expand Down
35 changes: 18 additions & 17 deletions apps/shinkai-tool-token-price/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder';
import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition';
import { ArchiveNodeProvider, Chainlink } from 'micro-eth-signer/net';
import axios from 'axios';

type Config = {};
type Params = {
Expand Down Expand Up @@ -44,30 +45,30 @@ export class Tool extends BaseTool<Config, Params, Result> {
async run(params: Params): Promise<RunResult<Result>> {
const provider = new ArchiveNodeProvider({
call: async (method: string, ...args: any[]) => {
const response = await fetch('https://eth.llamarpc.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
try {
await process.nextTick(() => { });
const response = await axios.post('https://eth.llamarpc.com', {
jsonrpc: '2.0',
id: 1,
method,
params: args,
}),
});
}, {
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
if (response.data.error) {
throw new Error(response.data.error.message);
}

type Response = { error: any; result: any };
const data = (await response.json()) as Response;
if (data.error) {
throw new Error(data.error.message);
return response.data.result;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(`HTTP error! status: ${error.response?.status}`);
}
throw error;
}

return data.result;
},
});

Expand Down
21 changes: 12 additions & 9 deletions apps/shinkai-tool-weather-by-city/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
RunResult,
ToolDefinition,
} from '@shinkai_protocol/shinkai-tools-builder';
import axios from 'axios';

type Config = {
apiKey: string;
Expand Down Expand Up @@ -44,15 +45,17 @@ export class Tool extends BaseTool<Config, Params, Result> {
};

async run(params: Params): Promise<RunResult<Result>> {
// response type is still an small subset of fetch Response type
const response = await fetch(
`http://api.openweathermap.org/data/2.5/weather?q=${params.city}&appid=${this.config.apiKey}`,
{},
);
if (!response.ok) {
throw new Error(`Failed to fetch weather data, status: ${response.status}`);
try {
await process.nextTick(() => { });
const response = await axios.get(
`http://api.openweathermap.org/data/2.5/weather?q=${params.city}&appid=${this.config.apiKey}`
);
return { data: { weather: JSON.stringify(response.data) } };
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(`Failed to fetch weather data, status: ${error.response?.status}`);
}
throw error;
}
const data = await response.json();
return { data: { weather: `${JSON.stringify(data)}` } };
}
}
35 changes: 18 additions & 17 deletions apps/shinkai-tool-web3-eth-balance/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { weieth } from 'micro-eth-signer';
import { ArchiveNodeProvider } from 'micro-eth-signer/net';
import { BaseTool, RunResult, ToolDefinition } from '@shinkai_protocol/shinkai-tools-builder';
import axios from 'axios';

type Config = {};

Expand Down Expand Up @@ -40,30 +41,30 @@ export class Tool extends BaseTool<Config, Params, Result> {
async run(params: Params): Promise<RunResult<Result>> {
const provider = new ArchiveNodeProvider({
call: async (method: string, ...args: any[]) => {
const response = await fetch('https://eth.llamarpc.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
try {
await process.nextTick(() => { });
const response = await axios.post('https://eth.llamarpc.com', {
jsonrpc: '2.0',
id: 1,
method,
params: args,
}),
});
}, {
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
if (response.data.error) {
throw new Error(response.data.error.message);
}

type Response = { error: any; result: any };
const data = (await response.json()) as Response;
if (data.error) {
throw new Error(data.error.message);
return response.data.result;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(`HTTP error! status: ${error.response?.status}`);
}
throw error;
}

return data.result;
},
});
console.log('Provider created');
Expand Down
35 changes: 18 additions & 17 deletions apps/shinkai-tool-web3-eth-uniswap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RunResult,
ToolDefinition,
} from '@shinkai_protocol/shinkai-tools-builder';
import axios from 'axios';

type Config = {};

Expand Down Expand Up @@ -45,30 +46,30 @@ export class Tool extends BaseTool<Config, Params, Result> {
async run(params: Params): Promise<RunResult<Result>> {
const provider = new ArchiveNodeProvider({
call: async (method: string, ...args: any[]) => {
const response = await fetch('https://eth.llamarpc.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
try {
await process.nextTick(() => { });
const response = await axios.post('https://eth.llamarpc.com', {
jsonrpc: '2.0',
id: 1,
method,
params: args,
}),
});
}, {
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
if (response.data.error) {
throw new Error(response.data.error.message);
}

type Response = { error: any; result: any };
const data = (await response.json()) as Response;
if (data.error) {
throw new Error(data.error.message);
return response.data.result;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(`HTTP error! status: ${error.response?.status}`);
}
throw error;
}

return data.result;
},
});
console.log('Provider created');
Expand Down
1 change: 1 addition & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const nxPreset = require('@nx/jest/preset').default;
module.exports = {
...nxPreset,
testEnvironment: 'node',
detectOpenHandles: true,
};
14 changes: 7 additions & 7 deletions libs/shinkai-tools-runner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=resources/*");

let resources_path = Path::new("shinka-tools-runner-resources");
let resources_path =
Path::new(env!("CARGO_MANIFEST_DIR")).join("shinkai-tools-runner-resources");
let target_path =
Path::new(&env::var("OUT_DIR").unwrap()).join("shinka-tools-runner-resources");
Path::new(&env::var("OUT_DIR").unwrap()).join("shinkai-tools-runner-resources");

if resources_path.exists() {
fs::create_dir_all(&target_path).unwrap();
Expand All @@ -21,10 +22,6 @@ fn main() {
}

let backend_path = target_path.join("shinkai-tools-backend");
println!("OUT_DIR: {:?}", env::var("OUT_DIR").unwrap());
println!("resources_path: {:?}", resources_path.display());
println!("target_path: {:?}", target_path.display());
println!("backend_path: {:?}", backend_path.display());

if !cfg!(target_os = "windows") {
let output = std::process::Command::new("chmod")
Expand All @@ -33,7 +30,10 @@ fn main() {
.output()
.expect("Failed to execute chmod command");
if !output.status.success() {
panic!("chmod command failed: {}", String::from_utf8_lossy(&output.stderr));
panic!(
"chmod command failed: {}",
String::from_utf8_lossy(&output.stderr)
);
}
}
}
Loading

0 comments on commit 3dbbd22

Please sign in to comment.