Skip to content

Conversation

apoorvdixit88
Copy link
Contributor

@apoorvdixit88 apoorvdixit88 commented Jul 9, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

The PR does the following actions

  • Adds endpoints to talk to ai services, particularly to n8n flow and embedded flow
  • Introduces a feature flag to manage chat features across different envs

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Closes #8584

How did you test it?

curl to test this

curl --location 'http://localhost:8080/chat/ai/data' \
--header 'x-feature: integ-custom' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer JWT' \
--data '{
            "message": "get count of failed payments"
    
}'
image ## Checklist
  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@apoorvdixit88 apoorvdixit88 requested review from a team as code owners July 9, 2025 09:19
@apoorvdixit88 apoorvdixit88 added the C-feature Category: Feature request or enhancement label Jul 9, 2025
@apoorvdixit88 apoorvdixit88 requested a review from a team as a code owner July 9, 2025 09:19
Copy link

semanticdiff-com bot commented Jul 9, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/lib.rs  75% smaller
  crates/router/src/routes/app.rs  3% smaller
  crates/router/src/routes.rs  1% smaller
  config/config.example.toml Unsupported file format
  config/deployments/env_specific.toml Unsupported file format
  config/development.toml Unsupported file format
  config/docker_compose.toml Unsupported file format
  crates/api_models/src/chat.rs  0% smaller
  crates/api_models/src/events.rs  0% smaller
  crates/api_models/src/events/chat.rs  0% smaller
  crates/api_models/src/lib.rs  0% smaller
  crates/common_utils/src/consts.rs  0% smaller
  crates/common_utils/src/events.rs  0% smaller
  crates/hyperswitch_domain_models/src/chat.rs  0% smaller
  crates/hyperswitch_domain_models/src/lib.rs  0% smaller
  crates/router/src/configs/secrets_transformers.rs  0% smaller
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/configs/validations.rs  0% smaller
  crates/router/src/core.rs  0% smaller
  crates/router/src/core/chat.rs  0% smaller
  crates/router/src/core/errors.rs  0% smaller
  crates/router/src/core/errors/chat.rs  0% smaller
  crates/router/src/routes/chat.rs  0% smaller
  crates/router/src/routes/lock_utils.rs  0% smaller
  crates/router_env/src/logger/types.rs  0% smaller
  loadtest/config/development.toml Unsupported file format

@apoorvdixit88 apoorvdixit88 changed the title Feat/add external chat api feat(ai): add endpoints to chat wit Jul 9, 2025
@apoorvdixit88 apoorvdixit88 changed the title feat(ai): add endpoints to chat wit feat(ai): add endpoints to chat with ai service Jul 9, 2025
JeevaRamu0104
JeevaRamu0104 previously approved these changes Jul 11, 2025
racnan
racnan previously approved these changes Jul 11, 2025
tsdk02
tsdk02 previously approved these changes Jul 14, 2025
Comment on lines +10 to +13
pub merchant_id: id_type::MerchantId,
pub profile_id: id_type::ProfileId,
pub org_id: id_type::OrganizationId,
pub query: GetDataMessage,
Copy link
Member

Choose a reason for hiding this comment

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

Would there be a situation where tenant ID might come into picture when calling the AI service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now we are only considering merchant_id and giving result for merchant level data, if tenant id comes into picture we may have to make changes in the ai service as well to talk to the corresponding schema. Not sure, will depend on the tenant, how they want this service. This all can be as per the use case.

Comment on lines 23 to 30
let request_body = chat_domain::EmbeddedAiDataRequest {
query: chat_domain::GetDataMessage {
message: req.message,
},
org_id: user_from_token.org_id,
merchant_id: user_from_token.merchant_id,
profile_id: user_from_token.profile_id,
};
Copy link
Member

Choose a reason for hiding this comment

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

Should we consider logging only the identifiers (without the message or by masking the message)?
And should we consider adding metrics (indicating the number of chat requests made) as well, having identifiers as the metric attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

logged the request with the masked message.

},
};

pub async fn get_data_from_hyperswitch_ai_workflow(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Should we consider having #[instrument] here as well?

Comment on lines +30 to +32
&auth::JWTAuth {
permission: Permission::MerchantPaymentRead,
},
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason for choosing this permission? If yes, should we consider explaining it in code comments?

@apoorvdixit88 apoorvdixit88 dismissed stale reviews from tsdk02 and sai-harsha-vardhan via f92fe4d July 15, 2025 11:54
@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 16, 2025
Merged via the queue into main with commit 3d60e6c Jul 16, 2025
16 of 20 checks passed
@likhinbopanna likhinbopanna deleted the feat/add-external-chat-api branch July 16, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add endpoints to support ai chat interactions
8 participants