Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
_APP_ASSISTANT_OPENAI_API_KEY=YOUR_OPENAI_API_KEY
_APP_ASSISTANT_BASE_URL=https://api.openai.com/v1
_APP_ASSISTANT_MODEL_NAME=gpt-4o
_APP_ASSISTANT_EMBEDDING_MODEL=text-embedding-ada-002
_BUILD_GIT_URL=https://github.com/appwrite/website.git
_BUILD_GIT_BRANCH=main
_BUILD_WEBSITE_URL=https://appwrite.io
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ COPY --from=builder /usr/src/app/package.json ./
COPY --from=builder /usr/src/app/src ./src

ENV _APP_ASSISTANT_OPENAI_API_KEY=''
ENV _APP_ASSISTANT_BASE_URL='https://api.openai.com/v1'
ENV _APP_ASSISTANT_MODEL_NAME='gpt-4o'
ENV _APP_ASSISTANT_EMBEDDING_MODEL='text-embedding-ada-002'

EXPOSE 3003
CMD [ "node", "src/main.js" ]
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ services:
- ./sources:/usr/src/app/sources
environment:
- _APP_ASSISTANT_OPENAI_API_KEY
- _APP_ASSISTANT_BASE_URL
- _APP_ASSISTANT_MODEL_NAME
- _APP_ASSISTANT_EMBEDDING_MODEL
3 changes: 3 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ declare global {
namespace NodeJS {
interface ProcessEnv {
_APP_ASSISTANT_OPENAI_API_KEY?: string;
_APP_ASSISTANT_BASE_URL?: string;
_APP_ASSISTANT_MODEL_NAME?: string;
_APP_ASSISTANT_EMBEDDING_MODEL?: string;
_BUILD_WEBSITE_URL?: string;
_BUILD_WEBSITE_VERSION?: string;
_BUILD_GIT_URL?: string;
Expand Down
19 changes: 17 additions & 2 deletions src/embeddings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ import { getDocuments } from "./documents.js";
export const initializeDocumentRetriever = async () => {
const embeddings = new OpenAIEmbeddings({
openAIApiKey: process.env._APP_ASSISTANT_OPENAI_API_KEY,
configuration: {
baseURL: process.env._APP_ASSISTANT_BASE_URL || "https://api.openai.com/v1",
},
modelName: process.env._APP_ASSISTANT_EMBEDDING_MODEL || "text-embedding-ada-002",
batchSize: 10,
});

const documents = await getDocuments();
const vectorStore = await HNSWLib.fromDocuments(documents, embeddings);

if (documents.length === 0) {
throw new Error("No documents found. Make sure to run 'pnpm run fetch-sources' first.");
}
Comment on lines +22 to +24
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve error message for production environments.

The document validation is excellent defensive programming. However, the error message references pnpm run fetch-sources, which assumes a development environment and may confuse users in production Docker deployments where the sources should already be present.

Consider a more environment-agnostic message:

-    throw new Error("No documents found. Make sure to run 'pnpm run fetch-sources' first.");
+    throw new Error("No documents found. Ensure the sources directory is populated with documentation files.");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (documents.length === 0) {
throw new Error("No documents found. Make sure to run 'pnpm run fetch-sources' first.");
}
if (documents.length === 0) {
throw new Error("No documents found. Ensure the sources directory is populated with documentation files.");
}
🤖 Prompt for AI Agents
In src/embeddings.js around lines 22 to 24, the thrown error references a
dev-only command ("pnpm run fetch-sources") which can confuse production users;
replace that hardcoded instruction with an environment-agnostic message that
explains no documents were found and instructs the operator to ensure source
data is present or that any ingestion step has been run (for dev, suggest
running the fetch step) and include brief guidance to check
deployment/configuration for where sources should be located.


const vectorStore = await HNSWLib.fromDocuments(documents, embeddings, {
space: "cosine",
});

return vectorStore.asRetriever(5);
};
Expand All @@ -24,8 +36,11 @@ export const initializeDocumentRetriever = async () => {
*/
export const getOpenAIChat = async (onToken, systemPrompt) =>
new OpenAIChat({
modelName: "gpt-4o",
modelName: process.env._APP_ASSISTANT_MODEL_NAME || "gpt-4o",
openAIApiKey: process.env._APP_ASSISTANT_OPENAI_API_KEY,
configuration: {
baseURL: process.env._APP_ASSISTANT_BASE_URL || "https://api.openai.com/v1",
},
temperature: 0,
maxTokens: 1000,
streaming: true,
Expand Down