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

langbase example added #912

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions js/examples/prd_generator/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dotenv/config';
import { Langbase } from 'langbase';
import { OpenAIToolSet } from 'composio-core';
import { createInterface } from 'readline';
import { stdin as input, stdout as output, title } from 'process';
import dotenv from 'dotenv';
dotenv.config();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate dotenv import and config call. Remove lines 6-7 since dotenv is already imported and configured in line 1.

const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY,
});

async function main() {
const userMsg = 'Generate a PRD on a docker like application?';
Copy link
Collaborator

Choose a reason for hiding this comment

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

The hardcoded prompt should be moved to a constant or configuration file. Consider making it more configurable for different use cases.


const response = await langbase.pipe.run({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing error handling for the Langbase API call. Consider wrapping this in a try-catch block to handle potential API failures gracefully.

messages: [
{
role: 'user',
content: userMsg,
},
],
stream: false,
name: 'summary'
});
console.log('response: ', response);

const readline = createInterface({ input, output });

const answer = await new Promise(resolve => {
readline.question('Do you want to write this in Google Doc? (yes/no): ', resolve);
});

readline.close();

if (answer.toLowerCase() === 'yes') {
const toolset = new OpenAIToolSet(process.env.COMPOSIO_API_KEY);
const entity = toolset.client.getEntity('default');
const result = await entity.execute(
"GOOGLEDOCS_CREATE_DOCUMENT",
{
title: "Summary",
text:response.completion
},
);
console.log(result);
console.log("Executed");
} else {
console.log("No");
}
}

main();
Loading
Loading