-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
const langbase = new Langbase({ | ||
apiKey: process.env.LANGBASE_API_KEY, | ||
}); | ||
|
||
async function main() { | ||
const userMsg = 'Generate a PRD on a docker like application?'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); |
There was a problem hiding this comment.
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.