Skip to content

Commit

Permalink
chore: auth docs (#1116)
Browse files Browse the repository at this point in the history
Co-authored-by: Himanshu Dixit <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Soham Ganatra <[email protected]>
  • Loading branch information
4 people authored Jan 3, 2025
1 parent 93886f8 commit 343f57a
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 233 deletions.
52 changes: 11 additions & 41 deletions docs/examples/combined/newsletter-summarizer-javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ sidebarTitle: "Newsletter Summarizer"
description: "This project serves as an example of how to use Composio to seamlessly fetch and summarize newsletter emails. It automatically retrieves recent newsletters, summarizes their content, and sends a well-formatted email to the specified recipient."
---




<Tabs>

<Tab title="Javascript">
<Card color="#7bee0c" title="Newsletter Summarizer GitHub Repository" icon="github" href="https://github.com/ComposioHQ/composio/tree/master/js/examples/newsletter_summarizer/newsletter_summarizer_cloudflare">
Explore the complete source code for the Newsletter Summarizer project. This repository contains all the necessary files and scripts to set up and run the Newsletter Summarizer using Composio and Cloudflare.
<CardBody>
</CardBody>
</Card>
<Steps>
<Step title="Import base packages">
Expand Down Expand Up @@ -47,13 +41,13 @@ description: "This project serves as an example of how to use Composio to seamle
```javascript Define Webhook
app.get('/webhook', async (req, res) => {
try {
const body = `Please research on Arxiv about \`${researchTopic}\`, organize
the top ${nIssues} results as ${nIssues} issues for
a GitHub repository, and finally raise those issues with proper
title, body, implementation guidance, and references in
the ${targetRepo} repo, as well as relevant tags and assignees as
const body = `Please research on Arxiv about \`${researchTopic}\`, organize
the top ${nIssues} results as ${nIssues} issues for
a GitHub repository, and finally raise those issues with proper
title, body, implementation guidance, and references in
the ${targetRepo} repo, as well as relevant tags and assignees as
the repo owner.`;

const toolset = new OpenAIToolSet({
apiKey: process.env.COMPOSIO_API_KEY,
});
Expand All @@ -79,7 +73,7 @@ description: "This project serves as an example of how to use Composio to seamle
assistant_id: assistant.id,
});
run = await toolset.wait_and_handle_assistant_tool_calls(client, run, thread);

// Check if the run is completed
if (run.status === "completed") {
let messages = await client.beta.threads.messages.list(thread.id);
Expand Down Expand Up @@ -110,34 +104,11 @@ description: "This project serves as an example of how to use Composio to seamle
```
</CodeGroup>
</Step>

</Steps>
</Tab>
</Tabs>

























## Putting It All Together

<CodeGroup>
Expand All @@ -154,11 +125,11 @@ description: "This project serves as an example of how to use Composio to seamle
// Function to set up the GitHub connection for the user if it doesn't exist
async function setupUserConnectionIfNotExists(toolset, entityId, c) {
const entity = await toolset.client.getEntity(entityId);
const connection = await entity.getConnection('github');
const connection = await entity.getConnection({ appName: "GITHUB" });

if (!connection) {
// If the user hasn't connected their GitHub account
const connection = await entity.initiateConnection('github');
const connection = await entity.initiateConnection({appName: "GITHUB"});
console.log('Log in via: ', connection.redirectUrl);
c.json({ redirectUrl: connection.redirectUrl, message: 'Please log in to continue and then call this API again.' });
}
Expand Down Expand Up @@ -231,6 +202,5 @@ description: "This project serves as an example of how to use Composio to seamle

export default app;
```
</CodeGroup>


</CodeGroup>
28 changes: 2 additions & 26 deletions docs/examples/combined/newsletter_summarizer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ description: "This project serves as an example of how to use Composio to seamle
<Tab title="Python">
<Card color="#7bee0c" title="Newsletter Summarizer GitHub Repository" icon="github" href="https://www.github.com/ComposioHQ/composio/blob/master/python/examples/newsletter_summarizer/">
Explore the complete source code for the Newsletter Summarizer project. This repository contains all the necessary files and scripts to set up and run the Newsletter Summarizer using Composio and Cloudflare.
<CardBody>
</CardBody>
</Card>
<Steps>
<Step title="Import Base Packages">
Expand Down Expand Up @@ -150,8 +148,6 @@ description: "This project serves as an example of how to use Composio to seamle
<Tab title="Javascript">
<Card color="#7bee0c" title="Newsletter Summarizer GitHub Repository" icon="github" href="https://github.com/ComposioHQ/composio/tree/master/js/examples/newsletter_summarizer/newsletter_summarizer_cloudflare">
Explore the complete source code for the Newsletter Summarizer project. This repository contains all the necessary files and scripts to set up and run the Newsletter Summarizer using Composio and Cloudflare.
<CardBody>
</CardBody>
</Card>
<Steps>
<Step title="Import base packages">
Expand Down Expand Up @@ -255,26 +251,6 @@ description: "This project serves as an example of how to use Composio to seamle
























## Putting It All Together

Expand Down Expand Up @@ -387,11 +363,11 @@ print(result)
// Function to set up the GitHub connection for the user if it doesn't exist
async function setupUserConnectionIfNotExists(toolset, entityId, c) {
const entity = await toolset.client.getEntity(entityId);
const connection = await entity.getConnection('github');
const connection = await entity.getConnection({ appName: "GITHUB" });

if (!connection) {
// If the user hasn't connected their GitHub account
const connection = await entity.initiateConnection('github');
const connection = await entity.initiateConnection({appName: "GITHUB"});
console.log('Log in via: ', connection.redirectUrl);
c.json({ redirectUrl: connection.redirectUrl, message: 'Please log in to continue and then call this API again.' });
}
Expand Down
16 changes: 11 additions & 5 deletions docs/introduction/intro/quickstart-entities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ We'll use Jessica as our example user. There are multiple ways to authenticate a

</Step>

<Step title="Initialize Composio and OpenAI">
<Step title="Initialize Composio Toolset and OpenAI">
Set up your development environment:

<CodeGroup>
```python Initialize Composio and OpenAI
```python Initialize Composio Toolset and OpenAI
from composio_openai import ComposioToolSet, Action
from openai import OpenAI

Expand Down Expand Up @@ -161,7 +161,7 @@ We'll use Jessica as our example user. There are multiple ways to authenticate a
const client = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });

const entity = await client.getEntity("Jessica");
const connection = await entity.initiateConnection('googlecalendar');
const connection = await entity.initiateConnection({appName: "googlecalendar"});

console.log(`Open this URL to authenticate: ${connection.redirectUrl}`);
```
Expand All @@ -177,11 +177,17 @@ We'll use Jessica as our example user. There are multiple ways to authenticate a

</Step>

<Step title="Initialize Composio and OpenAI">
<Step title="Initialize Composio Toolset and OpenAI">
Set up your development environment:

<CodeGroup>
<<<<<<< HEAD
```javascript Initialize Composio Toolset and OpenAI
||||||| 0378f58b
```javascript Initialize Composio and OpenAI
=======
```javascript Initialize Composio's OpenAI Toolset and OpenAI
>>>>>>> 44f9adb9f45a48b9ce6bd352c62a5a39f9b74a23
import { OpenAI } from "openai";
import { OpenAIToolSet } from "composio-core";

Expand Down Expand Up @@ -314,4 +320,4 @@ Congratulations! You've just:
Let's authenticate your user account to perform actions.
</Card>
</CardGroup>
<br/>
<br/>
26 changes: 13 additions & 13 deletions docs/introduction/intro/quickstart-tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Don't forget to set your `COMPOSIO_API_KEY` and `OPENAI_API_KEY` in your environ
</Tip>
</Step>

<Step title="Initialize Composio and OpenAI">
<Step title="Initialise Composio Toolset and OpenAI">
<CodeGroup>
```python Python
from composio_openai import ComposioToolSet, App
Expand Down Expand Up @@ -88,7 +88,7 @@ print(result)
</Steps>

</Tab>
<Tab title="Javascript">
<Tab title="JavaScript">
<Steps>

<Step title="Install Libraries">
Expand Down Expand Up @@ -120,7 +120,7 @@ print(result)
</CodeGroup>
</Step>

<Step title="Initialize Composio and OpenAI">
<Step title="Initialise Composio's OpenAIToolSet and OpenAI">
<CodeGroup>
```javascript JavaScript
import { OpenAI } from "openai";
Expand All @@ -137,19 +137,19 @@ print(result)

<Step title="Fetch GitHub Actions & and pass them to LLM">
<CodeGroup>
```javascript Star a repo using LLM
```javascript JavaScript
const tools = await composio_toolset.getTools({
actions: ["github_star_a_repository_for_the_authenticated_user"]
});
actions: ["github_star_a_repository_for_the_authenticated_user"],
});

const instruction = "Star the repo composiohq/composio on GitHub";

const response = await openai_client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: instruction }],
tools: tools,
tool_choice: "auto",
});
model: "gpt-4o",
messages: [{ role: "user", content: instruction }],
tools: tools,
tool_choice: "auto",
});
```
</CodeGroup>
<Tip>
Expand All @@ -159,7 +159,7 @@ print(result)

<Step title="Execute Tool Calls">
<CodeGroup>
```javascript Execute Function calls
```javascript JavaScript
const result = await composio_toolset.handleToolCall(response);
console.log(result);
```
Expand Down Expand Up @@ -205,4 +205,4 @@ Subscribe to triggers to execute actions automatically
<Card title="Other Concepts" href="../../introduction/foundations/components/workspace">
Learn about workspace environments, using CLI & other concepts
</Card>
</CardGroup>
</CardGroup>
4 changes: 2 additions & 2 deletions docs/introduction/intro/quickstart-triggers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const agentFunction = async (threadId, subject, senderMail) => {
<Step title="Create a Trigger Listener">
<CodeGroup>
```javascript JavaScript
toolset.client.triggers.subscribe(
toolset.triggers.subscribe(
(data) => {
const {
payload: {
Expand Down Expand Up @@ -248,4 +248,4 @@ Subscribe to triggers to execute actions automatically
<Card title="Other Concepts" href="../../introduction/foundations/components/workspace">
Learn about workspace environments, using CLI & other concepts
</Card>
</CardGroup>
</CardGroup>
8 changes: 4 additions & 4 deletions docs/introduction/intro/quickstart_3_backup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Follow these 5 steps to list your emails as soon as you receive them:
const client = new Composio(process.env.COMPOSIO_API_KEY);

const entity = await client.getEntity("Jessica");
const connection = await entity.initiateConnection('gmail');
const connection = await entity.initiateConnection({appName: "gmail"});

console.log(`Open this URL to authenticate: ${connection.redirectUrl}`);
```
Expand Down Expand Up @@ -170,7 +170,7 @@ Follow these 5 steps to list your emails as soon as you receive them:
</Tabs>
</Step>

<Step title="Initialize Composio and OpenAI">
<Step title="Initialize Composio Toolset and OpenAI">
Set up your development environment:

<Tabs>
Expand All @@ -187,7 +187,7 @@ Follow these 5 steps to list your emails as soon as you receive them:
</Tab>
<Tab title="JavaScript">
<CodeGroup>
```javascript Initialize Composio and OpenAI
```javascript Initialize Composio's OpenAI Toolset and OpenAI
import { OpenAI } from "openai";
import { OpenAIToolSet } from "composio-core";

Expand Down Expand Up @@ -285,4 +285,4 @@ Congratulations! You've just:
</Card>
</CardGroup>
</Card>
</Frame>
</Frame>
4 changes: 2 additions & 2 deletions docs/javascript/langchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const toolset = new LangchainToolSet({ apiKey: process.env.COMPOSIO_API_KEY, });

async function setupUserConnectionIfNotExists(entityId) {
const entity = toolset.client.getEntity(entityId);
const connection = await entity.getConnection('github');
const connection = await entity.getConnection({ appName: "GITHUB" });

if (!connection) {
// If this entity/user hasn't already connected the account
const connection = await entity.initiateConnection(appName);
const connection = await entity.initiateConnection({appName: appName});
console.log("Log in via: ", connection.redirectUrl);
return connection.waitUntilActive(60);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/javascript/openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const appName = 'github';

async function setupUserConnectionIfNotExists(entityId) {
const entity = toolset.client.getEntity(entityId);
const connection = await entity.getConnection(appName);
const connection = await entity.getConnection({ appName: appName });

if (!connection) {
const connection = await entity.initiateConnection(appName);
const connection = await entity.initiateConnection({appName: appName});
console.log("Log in via: ", connection.redirectUrl);
return connection.waitUntilActive(60);
}
Expand Down
Loading

0 comments on commit 343f57a

Please sign in to comment.