Skip to content
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

feat(api): implement /chat and /ask apis in Node.js (#5) #23

Merged
merged 14 commits into from
Sep 1, 2023

Conversation

sinedied
Copy link
Contributor

Test it locally

  1. Copy .env file from azd in packages/api
  2. npm install && npm start at the root of the project

Implemented

  • Complete /chat API, but with limitations (see [sdk] missing options from JS document-search SDK #21)
  • Azure and OpenAI clients integration
  • Managed auth, meaning that no API token need to be provided (as required by security team)
  • Automatic token refresh for OpenAI client
  • Port of Python "approach" interface to Node.js, implemented with dependency injection

Missing (for later PRs)

  • /ask API (and approaches)
  • Azure Monitor with OpenTelemetry integration
  • Document models typings

@sinedied sinedied changed the title feat(api): implement /chat api in Node.js feat(api): implement /chat api in Node.js (#5) Aug 31, 2023
Copy link
Member

@anfibiacreativa anfibiacreativa left a comment

Choose a reason for hiding this comment

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

We could improve some stuff for better maintenance and extensibility but we can also merge for now.

import { MessageBuilder } from '../message-builder.js';
import { AskApproach } from './approach.js';
import { messagesToString } from '../message.js';

Copy link
Member

Choose a reason for hiding this comment

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

For readability and maintenance, I would move this to a global variables file and outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that would be a good idea, as these prompt are specific to this particular approach. Other approaches have their own set of prompts, and mixing them altogether in a different file would make it more confusing IMO

const top = overrides?.top ? Number(overrides?.top) : 3;
const excludeCategory: string | undefined = overrides?.exclude_category;
const filter = excludeCategory ? `category ne '${excludeCategory.replace("'", "''")}'` : undefined;

Copy link
Member

Choose a reason for hiding this comment

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

Will we be using this when integrating a vector database? Otherwise maybe let's delete unnecessary code to make it easier to distro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already use a vector DB, it's Cognitive Search. The code is commented because of the missing SDK features, otherwise it would be used. This is currently a big issue as without using the semantic search and vector search, the results are pretty crap :/

If the question is not in English, translate the question to English before generating the search query.
If you cannot generate a search query, return just the number 0.
`;

Copy link
Member

Choose a reason for hiding this comment

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

Again, I would move all this to a global file.

packages/api/src/plugins/openai.ts Show resolved Hide resolved
packages/api/src/plugins/openai.ts Outdated Show resolved Hide resolved
chatClient = new OpenAI({
...commonOptions,
baseURL: `${openAiUrl}/openai/deployments/${config.azureOpenAiChatGptDeployment}`,
});
Copy link
Member

Choose a reason for hiding this comment

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

Are this API endpoints stable?

Copy link
Contributor Author

@sinedied sinedied Sep 1, 2023

Choose a reason for hiding this comment

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

Yes, they're used in the AOAI SDK too.
This service will probably be replaced by the AOAI SDK anyways (#22)

@sinedied sinedied changed the title feat(api): implement /chat api in Node.js (#5) feat(api): implement /chat and /ask apis in Node.js (#5) Sep 1, 2023
@anfibiacreativa anfibiacreativa merged commit 7b20ef4 into main Sep 1, 2023
1 check failed
@sinedied sinedied deleted the nodejs-backend branch September 6, 2023 13:01
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