Skip to content

introduce chat api to the project supported by langchain's sql-agent #2788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ianhe8x
Copy link
Collaborator

@ianhe8x ianhe8x commented May 15, 2025

Description

integrate llm chat api to query data from database

  • support openai, claude-ai and other openai compatibles
  • use environment to set LLM secrets
  • an openai styled chat api is now exposed from /v1/chat/completions
  • this feature is enabled by default, use --chat=false to turn off
    other minor changes
  • remove project service to drop support for legacy version of subql node
    Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have tested locally
  • I have performed a self review of my changes
  • Updated any relevant documentation
  • Linked to any relevant issues
  • I have added tests relevant to my changes
  • Any dependent changes have been merged and published in downstream modules
  • My code is up to date with the base branch
  • I have updated relevant changelogs. We suggest using chan

@ianhe8x ianhe8x requested a review from stwiname May 15, 2025 01:03
@@ -85,6 +86,17 @@ export class ConfigureModule {
pgClient._explainResults = [];
});
}
// todo: support ssl
const dataSource = new DataSource({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify this as read only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way. I think user may have to set up the readonly permission on db user

choices: [
{
index: 0,
message: {role: 'assistant', content: fullResponse},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right behaviour to send the full response again at the end of a stream?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part will need some clean up. Changed from initial version, i return the tool response as reasoning to user.
Although it is called fullResponse it is just the last message from llm which is considered the final answer of the question so it was send to user.

Copy link

github-actions bot commented May 22, 2025

Coverage report for .

Caution

Test run failed

St.
Category Percentage Covered / Total
🟡 Statements
70.8% (+0.69% 🔼)
22270/31454
🟡 Branches
79.37% (+1.08% 🔼)
3040/3830
🟡 Functions
73.25% (+10.75% 🔼)
1232/1682
🟡 Lines
70.8% (+0.69% 🔼)
22270/31454
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / migrate.ts
85.34% 9.09% 100% 85.34%
🟢
... / migrate-abis.controller.ts
95% 87.5% 100% 95%
🟢
... / constants.ts
100% 100% 100% 100%
🟢
... / index.ts
100% 100% 100% 100%
🟢
... / ethereum.ts
82.28% 83.33% 100% 82.28%
🟢
... / migrate-manifest.controller.ts
88% 73.33% 88.89% 88%
🟢
... / migrate-mapping.controller.ts
100% 100% 100% 100%
🟢
... / migrate-controller.ts
92.41% 84.62% 100% 92.41%
🟢
... / migrate.fixtures.ts
100% 100% 100% 100%
🟢
... / migrate-schema.controller.ts
97.23% 79.75% 100% 97.23%
🔴
... / types.ts
0% 0% 0% 0%
🟢
... / createProject.fixtures.ts
94.92% 77.78% 100% 94.92%
🟢
... / config.ts
100% 100% 100% 100%
🟢
... / index.ts
100% 100% 100% 100%
🔴
... / moduleLoader.ts
56% 40% 100% 56%
🟢
... / types.ts
100% 100% 100% 100%
🔴
... / utils.ts
0% 0% 0% 0%
🟢
... / networkFamily.ts
92.59% 88.89% 100% 92.59%
🟡
... / IPFSHTTPClientLite.ts
76.47% 80% 88.89% 76.47%
🟢
... / index.ts
100% 100% 100% 100%
🟢
... / utils.ts
92% 66.67% 100% 92%
🟡
... / admin.controller.ts
75.56% 96% 78.57% 75.56%
🟡
... / blockRange.ts
74.6% 100% 80% 74.6%
🟢
... / index.ts
100% 100% 100% 100%
🟢
... / blockchain.service.ts
100% 100% 100% 100%
🟢
... / SubqueryProject.ts
86.11% 83.33% 71.43% 86.11%
🟡
... / factory.ts
78.31% 66.67% 100% 78.31%
🟢
... / core.module.ts
100% 100% 100% 100%
🟢
... / dictionary.fixtures.ts
100% 100% 100% 100%
🟢
... / GlobalData.entity.ts
100% 100% 100% 100%
🟡
... / monitor.service.ts
70.04% 87.21% 94.12% 70.04%
🟡
... / multiChainRewind.service.ts
74.9% 91.11% 93.33% 74.9%
🔴
... / sandbox.service.ts
33.33% 50% 25% 33.33%
🟡
... / baseCache.service.ts
67.57% 90.91% 66.67% 67.57%
🟡
... / baseStoreModel.service.ts
64.41% 83.33% 83.33% 64.41%
🟡
... / cacheable.ts
64.29% 66.67% 50% 64.29%
🟡
... / csvStore.ts
75% 73.68% 85.71% 75%
🟡
... / exporter.ts
71.67% 71.43% 71.43% 71.67%
🟢
... / index.ts
100% 100% 100% 100%
🟢
... / global.ts
82.5% 92.59% 87.5% 82.5%
🔴
... / index.ts
0% 0% 0% 0%
🟢
... / index.ts
100% 100% 100% 100%
🟡
... / cacheMetadata.ts
60% 69.05% 86.67% 60%
🟢
... / index.ts
100% 100% 100% 100%
🟡
... / metadata.ts
67.47% 90% 66.67% 67.47%
🟢
... / utils.ts
100% 100% 100% 100%
🟡
... / cacheModel.ts
76.59% 91.11% 85% 76.59%
🟢
... / index.ts
100% 100% 100% 100%
🟡
... / model.ts
75.95% 73.91% 90.91% 75.95%
🟢
... / utils.ts
100% 100% 100% 100%
🟡
... / cachePoi.ts
77.89% 89.47% 85.71% 77.89%
🟢
... / index.ts
100% 100% 100% 100%
🔴
... / poi.ts
41.96% 71.43% 44.44% 41.96%
🟡
... / setValueModel.ts
61.54% 80% 78.57% 61.54%
🟡
... / storeCache.service.ts
66.67% 75.76% 76.92% 66.67%
🟡
... / storeModel.service.ts
64.84% 64.29% 71.43% 64.84%
🟢
... / types.ts
100% 100% 100% 100%
🟢
... / utils.ts
93.33% 66.67% 100% 93.33%
🟢
... / worker.core.module.ts
100% 100% 0% 100%
🔴
... / worker.monitor.service.ts
39.53% 100% 0% 39.53%
🔴
... / meta.controller.ts
53.33% 100% 0% 53.33%
🟡
... / meta.module.ts
60% 100% 0% 60%
🟢
... / process.ts
80.65% 57.14% 80% 80.65%
🔴
... / foreceClean.init.ts
47.62% 100% 0% 47.62%
🔴
... / reindex.init.ts
33.33% 100% 0% 33.33%
🟢
... / testing.core.module.ts
100% 100% 100% 100%
🟢
... / autoQueue.ts
95.34% 90.57% 94.12% 95.34%
🟢
... / index.ts
100% 100% 100% 100%
🟢
... / queue.ts
87.5% 93.33% 91.67% 87.5%
🟢
... / rampQueue.ts
95.74% 92% 100% 95.74%
🟢
... / string.ts
81.4% 83.33% 100% 81.4%
🟡
... / blockchain.service.ts
63.13% 100% 57.14% 63.13%
🔴
... / datasourceProcessors.ts
0% 0% 0% 0%
🔴
... / index.ts
0% 0% 0% 0%
🔴
... / types.ts
0% 0% 0% 0%
🔴
... / networking.ts
31.58% 100% 0% 31.58%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / delete.ts
48.72% (-5.57% 🔻)
100% 0%
48.72% (-5.57% 🔻)
🔴
... / promote.ts
44.19% (-4.53% 🔻)
100% 0%
44.19% (-4.53% 🔻)
🟡
... / add.ts
61.29% (-0.78% 🔻)
100% 0%
61.29% (-0.78% 🔻)
🟢
... / publish.ts
83.72% (-5.61% 🔻)
57.14% 100%
83.72% (-5.61% 🔻)
🔴
... / add-chain-controller.ts
40.07% (-0% 🔻)
66.67% 30%
40.07% (-0% 🔻)
🟢
... / build-controller.ts
90.26% (-1.04% 🔻)
61.11% (+3.97% 🔼)
100%
90.26% (-1.04% 🔻)
🟢
... / codegen-controller.ts
88.19% (-1.2% 🔻)
83.33% (+7.75% 🔼)
100%
88.19% (-1.2% 🔻)
🟡
... / deploy-controller.ts
64.94% (+27.48% 🔼)
72.73% (-5.05% 🔻)
64.29% (+39.29% 🔼)
64.94% (+27.48% 🔼)
🟢
... / generate-controller.ts
97.75% (+0.1% 🔼)
93.33% (-0.7% 🔻)
100%
97.75% (+0.1% 🔼)
🟡
... / init-controller.ts
72.57% (+2.09% 🔼)
50% (-18% 🔻)
61.11% (+7.78% 🔼)
72.57% (+2.09% 🔼)
🟢
... / project-controller.ts
85.54% (-11.72% 🔻)
57.14% (-2.86% 🔻)
75% (-25% 🔻)
85.54% (-11.72% 🔻)
🟢
... / publish-controller.ts
82.63% (+2.38% 🔼)
67.5% (-3.61% 🔻)
100%
82.63% (+2.38% 🔼)
🟡
... / utils.ts
79.26% (-1.82% 🔻)
83.64% (+2.93% 🔼)
86.21% (+8.93% 🔼)
79.26% (-1.82% 🔻)
🔴
... / models.ts
55.56% (-43.89% 🔻)
94.12% (+1.81% 🔼)
30.77% (-69.23% 🔻)
55.56% (-43.89% 🔻)
🟢
... / ProjectManifestVersioned.ts
82.19% (-2.74% 🔻)
88.89% (-11.11% 🔻)
61.54% (+3.21% 🔼)
82.19% (-2.74% 🔻)
🟢
... / model.ts
94.29% (-3.43% 🔻)
100%
73.33% (+1.9% 🔼)
94.29% (-3.43% 🔻)
🔴
... / models.ts
52.94% (-47.06% 🔻)
100%
0% (-100% 🔻)
52.94% (-47.06% 🔻)
🟡
... / load.ts
64.29% (+5.1% 🔼)
38.89% (-16.67% 🔻)
83.33% (+16.67% 🔼)
64.29% (+5.1% 🔼)
🟡
... / github-reader.ts
67.24% (-22.04% 🔻)
85.71% (+10.71% 🔼)
71.43% (-11.9% 🔻)
67.24% (-22.04% 🔻)
🟡
... / ipfs-reader.ts
63.49% (-22.22% 🔻)
72.73% (+9.09% 🔼)
71.43% (-11.9% 🔻)
63.49% (-22.22% 🔻)
🟡
... / local-reader.ts
72.09% (-13.95% 🔻)
100% (+37.5% 🔼)
83.33% (-16.67% 🔻)
72.09% (-13.95% 🔻)
🟢
... / reader.ts
81.58% (-7.89% 🔻)
57.14% (-17.86% 🔻)
100%
81.58% (-7.89% 🔻)
🔴
... / base.ts
47.66% (-50.34% 🔻)
87.5% (-12.5% 🔻)
40% (-40% 🔻)
47.66% (-50.34% 🔻)
🔴
... / models.ts
31.74% (-68.26% 🔻)
100%
0% (-100% 🔻)
31.74% (-68.26% 🔻)
🟢
... / NodeConfig.ts
88.72% (+0.11% 🔼)
80.88% (+1.25% 🔼)
83.33% (-2.71% 🔻)
88.72% (+0.11% 🔼)
🟢
... / ProjectUpgrade.service.ts
81.49% (-5.59% 🔻)
88.76% (-2.59% 🔻)
92.31% (+1% 🔼)
81.49% (-5.59% 🔻)
🟢
... / configure.module.ts
82.67% (-1.9% 🔻)
71.15% (+7.15% 🔼)
100%
82.67% (-1.9% 🔻)
🟢
... / db.module.ts
89.63% (+1.35% 🔼)
62.5% (-20.83% 🔻)
80%
89.63% (+1.35% 🔼)
🟢
... / SchemaMigration.service.ts
87.57% (+0% 🔼)
84.21% (+2.96% 🔼)
83.33% (-16.67% 🔻)
87.57% (+0% 🔼)
🟡
... / migration-helpers.ts
75.81% (-0.2% 🔻)
88.89% (+8.29% 🔼)
90.91%
75.81% (-0.2% 🔻)
🟡
... / migration.ts
73.65% (-8.63% 🔻)
81.69% (+1.96% 🔼)
85.71% (-4.76% 🔻)
73.65% (-8.63% 🔻)
🟡
... / sequelizeUtil.ts
79.46% (-11.61% 🔻)
66.67% (-3.7% 🔻)
62.5%
79.46% (-11.61% 🔻)
🟡
... / StoreOperations.ts
67.06% (-25.25% 🔻)
64.71% (-20.29% 🔻)
87.5% (-12.5% 🔻)
67.06% (-25.25% 🔻)
🔴
... / benchmark.service.ts
44.76% (-10.49% 🔻)
66.67%
36.36% (-3.64% 🔻)
44.76% (-10.49% 🔻)
🟢
... / base-block-dispatcher.ts
84.85% (+37.5% 🔼)
84% (-16% 🔻)
79.17% (+69.17% 🔼)
84.85% (+37.5% 🔼)
🟢
... / worker-block-dispatcher.ts
92.72% (+42.51% 🔼)
87.5% (-12.5% 🔻)
94.44% (+67.17% 🔼)
92.72% (+42.51% 🔼)
🔴
... / coreDictionary.ts
48.72% (-51.28% 🔻)
87.5% (-6.94% 🔻)
77.78% (-22.22% 🔻)
48.72% (-51.28% 🔻)
🟡
... / dictionary.service.ts
66.5% (-18.65% 🔻)
80% (-5.71% 🔻)
83.33% (-7.58% 🔻)
66.5% (-18.65% 🔻)
🟡
... / dictionaryV1.ts
77.55% (-15.68% 🔻)
76.09% (-2.17% 🔻)
91.67% (-8.33% 🔻)
77.55% (-15.68% 🔻)
🟢
... / dictionaryV2.ts
81.44% (-0.23% 🔻)
71.88% (+6.66% 🔼)
88.89% (-11.11% 🔻)
81.44% (-0.23% 🔻)
🔴
... / ds-processor.service.ts
39.73% (-22.36% 🔻)
75%
58.33% (-29.17% 🔻)
39.73% (-22.36% 🔻)
🟡
... / dynamic-ds.service.ts
63.38% (-26.82% 🔻)
63.64% (-3.03% 🔻)
81.82% (-3.9% 🔻)
63.38% (-26.82% 🔻)
🟢
... / inMemoryCache.service.ts
86.21% (-13.79% 🔻)
100%
75% (-25% 🔻)
86.21% (-13.79% 🔻)
🔴
... / indexer.manager.ts
17.48% (-15.73% 🔻)
100%
10% (-2.5% 🔻)
17.48% (-15.73% 🔻)
🟢
... / PoiBlock.ts
84.68% (-13.71% 🔻)
96.55%
75% (-25% 🔻)
84.68% (-13.71% 🔻)
🔴
... / poi.service.ts
55.51% (+31.58% 🔼)
57.69% (-42.31% 🔻)
80% (+51.43% 🔼)
55.51% (+31.58% 🔼)
🔴
... / poiSync.service.ts
55.88% (-31% 🔻)
77.61% (+1.05% 🔼)
88.89% (-3.42% 🔻)
55.88% (-31% 🔻)
🟡
... / project.service.ts
70.76% (-9.24% 🔻)
64.47% (-5.7% 🔻)
85.71% (+1.71% 🔼)
70.76% (-9.24% 🔻)
🔴
... / sandbox.ts
59.73% (-8.25% 🔻)
56.25% (-0.89% 🔻)
57.14% (-4.4% 🔻)
59.73% (-8.25% 🔻)
🔴
... / entity.ts
53.57% (-7.97% 🔻)
100%
50% (+50% 🔼)
53.57% (-7.97% 🔻)
🔴
... / store.ts
31.03% (-1.17% 🔻)
62.5% (-37.5% 🔻)
33.33% (+33.33% 🔼)
31.03% (-1.17% 🔻)
🟢
... / test.runner.ts
94.44% (-4.89% 🔻)
81.82% (+8.48% 🔼)
80% (-20% 🔻)
94.44% (-4.89% 🔻)
🔴
... / testing.service.ts
11.86% (-16.71% 🔻)
100% 0%
11.86% (-16.71% 🔻)
🟡
... / unfinalizedBlocks.service.ts
67.2% (-16.79% 🔻)
95.16% (-1.56% 🔻)
91.3% (-0.36% 🔻)
67.2% (-16.79% 🔻)
🟡
... / worker.builder.ts
61.97% (-17.22% 🔻)
65.38% 80%
61.97% (-17.22% 🔻)
🔴
... / worker.cache.service.ts
48.78% (-9.76% 🔻)
100% 0%
48.78% (-9.76% 🔻)
🔴
... / worker.connectionPoolState.manager.ts
38.21% (-22.76% 🔻)
100% 0%
38.21% (-22.76% 🔻)
🔴
... / worker.dynamic-ds.service.ts
44.44% (-17.78% 🔻)
100% 0%
44.44% (-17.78% 🔻)
🟢
... / worker.service.ts
93.16% (+48.52% 🔼)
85.71% (-14.29% 🔻)
100% (+100% 🔼)
93.16% (+48.52% 🔼)
🔴
... / worker.ts
42.13% (-0.32% 🔻)
100% 0%
42.13% (-0.32% 🔻)
🔴
... / worker.unfinalizedBlocks.service.ts
26.79% (-73.21% 🔻)
100%
0% (-100% 🔻)
26.79% (-73.21% 🔻)
🔴
... / logger.ts
49.3% (-15.18% 🔻)
33.33%
40% (+20% 🔼)
49.3% (-15.18% 🔻)
🔴
... / event.listener.ts
16.16% (-64.65% 🔻)
100%
0% (-25% 🔻)
16.16% (-64.65% 🔻)
🔴
... / health.controller.ts
37.93% (-17.24% 🔻)
100%
0% (-50% 🔻)
37.93% (-17.24% 🔻)
🔴
... / health.service.ts
21.05% (-36.48% 🔻)
100%
0% (-20% 🔻)
21.05% (-36.48% 🔻)
🔴
... / meta.service.ts
35.19% (-34.34% 🔻)
100% (+20% 🔼)
0% (-40% 🔻)
35.19% (-34.34% 🔻)
🔴
... / ready.controller.ts
34.78% (-21.74% 🔻)
100%
0% (-50% 🔻)
34.78% (-21.74% 🔻)
🔴
... / ready.service.ts
37.5% (-54.17% 🔻)
100%
0% (-66.67% 🔻)
37.5% (-54.17% 🔻)
🔴
... / reindex.service.ts
26.97% (-6.36% 🔻)
100%
11.11% (+11.11% 🔼)
26.97% (-6.36% 🔻)
🟡
... / blocks.ts
71.21% (-28.79% 🔻)
91.67% (+2.78% 🔼)
75% (-25% 🔻)
71.21% (-28.79% 🔻)
🟡
... / project.ts
73.29% (-0.09% 🔻)
75% (+0.42% 🔼)
77.78%
73.29% (-0.09% 🔻)
🟢
... / promise.ts
88.14% (-3.63% 🔻)
100% (+13.64% 🔼)
71.43% (-14.29% 🔻)
88.14% (-3.63% 🔻)
🟡
... / reindex.ts
73.33% (+39.29% 🔼)
10% (-90% 🔻)
100% (+100% 🔼)
73.33% (+39.29% 🔼)
🔴
... / yargs.ts
44.68% (-0.81% 🔻)
100% 14.29%
44.68% (-0.81% 🔻)
🟢
... / api.service.ts
85.75% (+2.24% 🔼)
78.69% (+6.47% 🔼)
80.77% (-5.9% 🔻)
85.75% (+2.24% 🔼)
🟢
... / apiPromise.connection.ts
80% (+10.92% 🔼)
61.54% (-18.46% 🔻)
66.67% (+23.81% 🔼)
80% (+10.92% 🔼)
🔴
... / index.ts
0% (-100% 🔻)
0% (-100% 🔻)
0% (-100% 🔻)
0% (-100% 🔻)
🟢
... / substrateDictionary.service.ts
98.15% (+7.58% 🔼)
66.67% (-6.06% 🔻)
100% (+20% 🔼)
98.15% (+7.58% 🔼)
🔴
... / types.ts
0% (-100% 🔻)
0% (-100% 🔻)
0% (-100% 🔻)
0% (-100% 🔻)
🟢
... / substrateDictionaryV1.ts
85.43% (-0.05% 🔻)
78.72% (+8.96% 🔼)
84.62% (+1.28% 🔼)
85.43% (-0.05% 🔻)
🟡
... / substrateDictionaryV2.ts
73.03% (-2.48% 🔻)
75% 33.33%
73.03% (-2.48% 🔻)
🔴
... / indexer.manager.ts
47.96% (-9.58% 🔻)
100%
16.67% (+7.58% 🔼)
47.96% (-9.58% 🔻)
🟢
... / runtimeService.ts
95.29% (+3.09% 🔼)
83.33% (-5.56% 🔻)
100% (+20% 🔼)
95.29% (+3.09% 🔼)
🟡
... / types.ts
70.45% (-14.84% 🔻)
100% 0%
70.45% (-14.84% 🔻)
🟢
... / project.ts
88.73% (-0.16% 🔻)
68.18% 87.5%
88.73% (-0.16% 🔻)
🟢
... / buffer.ts
95.12% (-4.88% 🔻)
95.83% (-4.17% 🔻)
90.48% (+6.27% 🔼)
95.12% (-4.88% 🔻)
🟢
... / builder.ts
93.02% (+0.25% 🔼)
82.14% (-0.62% 🔻)
100%
93.02% (+0.25% 🔼)
🟢
... / entities.ts
82.67% (-5.65% 🔻)
80.31% (-5.77% 🔻)
100%
82.67% (-5.65% 🔻)
🟡
... / logger.ts
69.19% (-0.41% 🔻)
48.15% (-6.85% 🔻)
78.57% (+3.57% 🔼)
69.19% (-0.41% 🔻)

Test suite run failed

Failed tests: 1/669. Failed suites: 1/111.
  ● CLI create project and delete project › Create project and delete

    Failed to create project: internal server error

      94 | export function errorHandle(e: any, msg: string): Error {
      95 |   if (axios.isAxiosError(e) && e?.response?.data) {
    > 96 |     return new Error(`${msg} ${e.response.data.message ?? e.response.data}`);
         |            ^
      97 |   }
      98 |
      99 |   return new Error(`${msg} ${e.message}`);

      at errorHandle (packages/cli/src/utils/utils.ts:96:12)
      at createProject (packages/cli/src/controller/project-controller.ts:59:22)
      at Object.<anonymous> (packages/cli/src/controller/project-controller.spec.ts:27:28)

Report generated by 🧪jest coverage report action from 1913bce

@stwiname stwiname marked this pull request as ready for review May 26, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants