-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Samantha): Transform project from assistant to Samantha
- Strip away feature for HomeAssistant AI Summaries - Update README
- Loading branch information
1 parent
07c7988
commit c093f43
Showing
9 changed files
with
208 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
# assistant | ||
# Samantha — Connecting OpenAI Assistant with my digital ecosystem | ||
|
||
A NodeJS app bridging the gap between openai/chatgpt and various tools : Home-Assistant, calendar, emails | ||
[Part of the OpenAI Projects of @thomashermine](https://thomashermine.notion.site/OpenAI-Projects-30b950137c124b3c8fd0622007a889f0?pvs=4) | ||
|
||
Samantha is a NodeJS app connecting OpenAI custom Asssistants with various third-party services : Google Calendar, Gmail/Google Mail, Slack, Spotify, HomeAssistant,... | ||
It can be invoked via an iOS Shortcuts, or use as an HomeAssistant Conversation Agent. | ||
|
||
## Architecture | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant EndUser as End User | ||
participant NodeJSApp as Samantha NodeJS App | ||
participant OpenAI as OpenAI Custom Assistant | ||
EndUser->>NodeJSApp: HTTP POST message | ||
NodeJSApp->>OpenAI: Send request to OpenAI | ||
OpenAI->>NodeJSApp: Respond with actions to perform | ||
NodeJSApp->>NodeJSApp: Perform Actions | ||
NodeJSApp->>OpenAI: Send completion results of actions | ||
OpenAI->>NodeJSApp: Respond with message | ||
NodeJSApp->>EndUser: HTTP Response with message | ||
``` | ||
|
||
## Documentation | ||
|
||
[Complete Documentation](https://thomashermine.notion.site/Samantha-Connecting-OpenAI-Assistant-with-my-digital-ecosystem-202bff7ef3054ca5a5ceb9432e3e06d6?pvs=4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,41 @@ | ||
import "dotenv/config"; | ||
|
||
import { log } from "./_helpers/logs"; | ||
import { sleep } from "./_helpers/sleep"; | ||
import { init } from "./init"; | ||
import { summariesJob } from "./_helpers/summaries/job"; | ||
import { HOME_ASSISTANT_SUMMARIES_UPDATE_INTERVAL } from "./config"; | ||
|
||
import { launchAssistantConversation } from "./openai/assistant"; | ||
import { | ||
createAssistantThread, | ||
handleUserMessageOnThread, | ||
} from "./openai/assistant"; | ||
|
||
async function main() { | ||
// Init | ||
// =================================================================================================================== | ||
log("app", "info", "Starting up..."); | ||
const { ha, openai } = await init(); | ||
const { server } = await init(); | ||
log("app", "info", "Initialized."); | ||
|
||
// Start the OpenAI Assistant Conversation | ||
// =================================================================================================================== | ||
await launchAssistantConversation("agenda"); | ||
const { threadId, assistantId, instructions } = | ||
await createAssistantThread("agenda"); | ||
|
||
// Jobs | ||
// =================================================================================================================== | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
// TODO: Use a pub-sub model instead to update everytime one of the entities we summarize is updated | ||
await summariesJob(ha, openai); | ||
await sleep(HOME_ASSISTANT_SUMMARIES_UPDATE_INTERVAL); | ||
} | ||
server.post("/assistant/agenda/message", async (req, res) => { | ||
console.log("req.body", req.body); | ||
const { message } = req.body; | ||
log("app", "debug", `Received message ${message}`); | ||
const response = await handleUserMessageOnThread( | ||
assistantId, | ||
threadId, | ||
message, | ||
instructions, | ||
); | ||
res.status(201).json({ message: response }); | ||
}); | ||
log( | ||
"app", | ||
"info", | ||
"Ready to make conversation with assistant. Send a POST request to /assistant/agenda/message with a message in the body to start the conversation.", | ||
); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.