Skip to content

Commit 0ee5e93

Browse files
authored
Merge pull request #6 from ITZSHOAIB/feat-graphql-tool
feat: A new graphql tool added that LLM models can invoke
2 parents 78294cf + 9a7bc07 commit 0ee5e93

File tree

19 files changed

+1256
-431
lines changed

19 files changed

+1256
-431
lines changed

.changeset/all-snakes-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"graphql-agent-tool": patch
3+
---
4+
5+
feat: A new Graphql Tool that LLM models will be able to invoke

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json",
33
"changelog": [
44
"@changesets/changelog-github",
5-
{ "repo": "ITZSHOAIB/typescript-package-boilerplate" }
5+
{ "repo": "ITZSHOAIB/graphql-agent-tool" }
66
],
77
"commit": false,
88
"fixed": [],

.github/workflows/publish-on-main.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ concurrency:
1010

1111
jobs:
1212
checks:
13-
# Remove this line to enable the job
14-
if: ${{ false }}
1513
name: Checks
1614
uses: ./.github/workflows/pre-checks.yml
1715
secrets: inherit
1816

19-
publish:
20-
# Remove this line to enable the job
21-
if: ${{ false }}
17+
publish:
2218
name: Publish
2319
needs: checks
2420
runs-on: ubuntu-latest

.github/workflows/pull-request.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ concurrency:
99

1010
jobs:
1111
checks:
12-
# Remove this line to enable the job
13-
if: ${{ false }}
1412
name: Checks
1513
uses: ./.github/workflows/pre-checks.yml
1614
secrets: inherit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
3-
coverage
3+
coverage
4+
.env

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"recommendations": ["orta.vscode-twoslash-queries", "biomejs.biome"]
2+
"recommendations": ["biomejs.biome"]
33
}

examples/direct-call/invoke.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { GraphqlAgentTool } from "graphql-agent-tool";
2+
3+
export const invoke = async () => {
4+
const graphqlCapitalTool = new GraphqlAgentTool({
5+
name: "getCountryCapital",
6+
purpose:
7+
"Retrieves the capital city of a country using its ISO country code. The tool expects a country code in ISO format (e.g., 'IN' for India, 'US' for United States). Input should be provided in the format {variables: {countryCode: <countryCode>}}.",
8+
url: "https://countries.trevorblades.com",
9+
query: `
10+
query GetCountryCapital($countryCode: ID!) {
11+
country(code: $countryCode) {
12+
capital
13+
}
14+
}
15+
`,
16+
}).getTool();
17+
18+
const response = await graphqlCapitalTool.invoke({
19+
variables: {
20+
countryCode: "IN",
21+
},
22+
});
23+
24+
return response;
25+
};

examples/response-parser/invoke.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { GraphqlAgentTool } from "graphql-agent-tool";
2+
3+
export const invoke = async () => {
4+
const graphqlCapitalTool = new GraphqlAgentTool({
5+
name: "getCountryCapital",
6+
purpose:
7+
"Retrieves the capital city of a country using its ISO country code. The tool expects a country code in ISO format (e.g., 'IN' for India, 'US' for United States). Input should be provided in the format {variables: {countryCode: <countryCode>}}.",
8+
url: "https://countries.trevorblades.com",
9+
query: `
10+
query GetCountryCapital($countryCode: ID!) {
11+
country(code: $countryCode) {
12+
capital
13+
}
14+
}
15+
`,
16+
responseParser: (response: unknown) => {
17+
const { data } = response as { data: { country: { capital: string } } };
18+
return data.country.capital;
19+
},
20+
}).getTool();
21+
22+
const response = await graphqlCapitalTool.invoke({
23+
variables: {
24+
countryCode: "IN",
25+
},
26+
});
27+
28+
return response;
29+
};

examples/with-llm-model/invoke.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { GraphqlAgentTool } from "graphql-agent-tool";
2+
import { mistralModel } from "./models.js";
3+
4+
export const invoke = async (prompt: string) => {
5+
const graphqlCapitalTool = new GraphqlAgentTool({
6+
name: "getCountryCapital",
7+
purpose:
8+
"Retrieves the capital city of a country using its ISO country code. The tool expects a country code in ISO format (e.g., 'IN' for India, 'US' for United States). Input should be provided in the format {variables: {countryCode: <countryCode>}}.",
9+
url: "https://countries.trevorblades.com",
10+
query: `
11+
query GetCountryCapital($countryCode: ID!) {
12+
country(code: $countryCode) {
13+
capital
14+
}
15+
}
16+
`,
17+
}).getTool();
18+
19+
const modelWithTools = mistralModel.bindTools([graphqlCapitalTool]);
20+
const response = await modelWithTools.invoke(prompt);
21+
22+
return response;
23+
};

examples/with-llm-model/models.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ChatMistralAI } from "@langchain/mistralai";
2+
3+
// Mistral model
4+
export const mistralModel = new ChatMistralAI({
5+
model: "mistral-small-latest",
6+
apiKey: process.env.MISTRAL_API_KEY || "",
7+
temperature: 0.0,
8+
});

0 commit comments

Comments
 (0)