Skip to content

Commit

Permalink
support siri ultra vision
Browse files Browse the repository at this point in the history
  • Loading branch information
fatwang2 committed Jun 3, 2024
1 parent 5a52cf0 commit 1ae8641
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ This is a Siri Ultra that works with Apple Shortcuts removing the need for a ded

## How it works

The assistant is run on Cloudflare Workers and can work with any LLM model.
The assistant is run on Cloudflare Workers and can work with any LLMs.

[Demo Video](https://x.com/fatwang2ai/status/1789601031313035281)
[Siri Ultra Demo Video](https://x.com/fatwang2ai/status/1789601031313035281)
[Siri Ultra Vision Demo Video](https://x.com/fatwang2ai/status/1791648375693361161)

## Features
- Real-time dialogue 💬
- Real-time voice 🎙️
- Real-time Web Search 🔍
- Talk with pictures 🌄
- Talk with videos 📹

# Usage

## Method 1: Setting Up the Shortcut Directly
1. **Install the Shortcut**:
- Click [this link](https://search2ai.online/siri002) to install.
- Click [Siri Ultra](https://search2ai.online/siri002) for chat with LLMs to install.
- Click [Siri Ultra Vision](https://search2ai.online/siri003) for vision of LLMs to install.

2. **Configure**:
- Open the Shortcut, follow prompts to input necessary variables.

> **Branch**: Siri Ultra Vision is testing on [this link](https://search2ai.online/siri003), which can talk with photos by gpt-4o
## Method 2: Setting Up the Self-Hosted Version

### Getting Started
Expand Down Expand Up @@ -66,8 +73,8 @@ To deploy the worker, run `npx wrangler deploy`.
### Setting Up the Shortcut

1. **Install the shortcut**:
- Use [this link](https://search2ai.online/siri002) to install the shortcut.

- Use [Siri Ultra](https://search2ai.online/siri002) to install the chat shortcut.
- Use [Siri Ultra Vision](https://search2ai.online/siri003) to install the vision shortcut.
2. **Configure the shortcut**:
- Open the shortcut and replace the `URL` field with your worker's URL.
- If you didn't change the default name, the URL should be `https://siri-ultra.<your-username>.workers.dev`.
45 changes: 36 additions & 9 deletions src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FunctionHandler } from "./functions";
export interface IBody {
chat_id: string;
input: string;
image?: string[];
date: string;
config?: {
model?: string;
Expand Down Expand Up @@ -55,18 +56,44 @@ export const handle = async (req: IRequest): Promise<string> => {
date: ${req.request.date}
`;
const chat = ChatHistory.getInstance(req.env.siri_ai_chats);
await chat.add(req.request.chat_id, {
role: "user",
content: req.request.input,
});
if (!req.request.image) {
await chat.add(req.request.chat_id, {
role: "user",
content: req.request.input,
});
}

let response = "";
while (true) {
const ask = await openai.client.chat.completions.create({
model: openai.model,
messages: [
let currentMessages;
if (req.request.image) {
currentMessages = [
{ role: "system", content: system },
{
role: "user",
content: [
{
type: "text",
text: req.request.input,
},
...req.request.image.map((base64Image) => ({
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${base64Image}`,
},
})),
],
},
];
} else {
currentMessages = [
{ role: "system", content: system },
...(await chat.get(req.request.chat_id)),
],
];
}
const ask = await openai.client.chat.completions.create({
model: openai.model,
messages: currentMessages,
tools: FunctionHandler.functions,
});
if (ask.choices[0].message.tool_calls) {
Expand Down Expand Up @@ -101,5 +128,5 @@ export const handle = async (req: IRequest): Promise<string> => {
break;
}
}
return response;
return response;
};
2 changes: 0 additions & 2 deletions src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ export class ChatHistory {
messages.push(message);
await this.kv.put(chat_id, JSON.stringify(messages));
}
console.log(JSON.stringify(this.kv.get(chat_id), null, 2));
}

async get(chat_id: string): Promise<ChatEntry[]> {
const chat = await this.kv.get(chat_id);
if (!chat) {
return [];
}
console.log(chat);
return JSON.parse(chat);
}
}
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const app = new Hono();
app.post("/", async (c) => {
const body = (await c.req.json()) as IBody;
try {
console.log(JSON.stringify(body, null, 2));
const response = await handle({
env: c.env,
request: body,
Expand All @@ -16,7 +15,6 @@ app.post("/", async (c) => {
response,
});
} catch (error) {
console.log(error);
return c.json({
response: "Something went wrong, we are working on it",
});
Expand Down

0 comments on commit 1ae8641

Please sign in to comment.