Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ https://user-images.githubusercontent.com/1011391/230610706-96755450-4a3b-4530-b
### ℹ️ Contents

- [Window: use your own AI models on the web](#window-use-your-own-ai-models-on-the-web)
- [📺 Demo](#-demo)
- [ℹ️ Contents](#ℹ️-contents)
- [📺 Demo](#-demo)
- [ℹ️ Contents](#ℹ️-contents)
- [⭐️ Main features](#️-main-features)
- [⚙️ How it works](#️-how-it-works)
- [📥 Installation](#-installation)
Expand Down Expand Up @@ -149,7 +149,7 @@ handler to improve UX, since not all models and config options support it.
### Examples

- [Next.js Window AI](https://github.com/YanniKouloumbis/next-js-window-ai) - A Next.js app that demonstrates how to use Window AI in a chat application. ([Demo](https://next-js-window-ai.vercel.app/))
- [Robot Companion](https://github.com/zoan37/robot-companion) - An AI robot that can move, emote, and change facial expressions while chatting. ([Demo](https://robot-companion.vercel.app/))
- [Robot Companion](https://github.com/zoan37/robot-companion) - An AI robot that can move, emote, and change facial expressions while chatting. ([Demo](https://robot-companion.vercel.app/))

### Functions

Expand Down Expand Up @@ -195,16 +195,15 @@ The `BETA_generate3DObject` function allows you to generate 3D objects with a de
Here's an example request:

```javascript
const [ result ] = await window.ai.BETA_generate3DObject(
{ "prompt": "a glazed donut" },
{ "numInferenceSteps": 32,});
const [result] = await window.ai.BETA_generate3DObject(
{ prompt: "a glazed donut" },
{ numInferenceSteps: 32 }
)

// base64 representation of your 3D object, in ply format
const uri = result.uri;
const uri = result.uri
```



All public types, including error messages, are documented in the [window.ai library](/packages/lib/src/index.ts). Highlights below:

### CompletionOptions
Expand Down Expand Up @@ -242,11 +241,12 @@ export interface CompletionOptions {
}
```

### ThreeDOptions
### ThreeDOptions

This options dictionary allows you to specify options for generating a three dimensional object.

```ts
export interface ThreeDOptions{
export interface ThreeDOptions {
// The number of inference steps to run. Defaults to 32, with specific default values for each model.
numInferenceSteps?: number
// How many generations to create. Defaults to 1.
Expand Down
1 change: 1 addition & 0 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/chrome": "^0.0.237",
"@types/webextension-polyfill": "^0.10.0",
"@vespaiach/axios-fetch-adapter": "github:alexanderatallah/axios-fetch-adapter",
"@xenova/transformers": "^2.17.2",
"axios": "^1.4.0",
"axios-retry": "^3.5.0",
"object-hash": "^3.0.0",
Expand Down
49 changes: 19 additions & 30 deletions apps/extension/src/background/ports/media.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
import {
ErrorCode,
ModelID,
type MediaOutput,
} from "window.ai"
import { ErrorCode, type MediaOutput, ModelID } from "window.ai"

import type { PlasmoMessaging } from "@plasmohq/messaging"

import {
type PortRequest,
type PortResponse,
} from "~core/constants"
import { promptInterrupts } from "~background/lib/helpers"
import { type PortRequest, type PortResponse } from "~core/constants"
import { PortName } from "~core/constants"
import { configManager, AuthType } from "~core/managers/config"
import {
transactionManager
} from "~core/managers/transaction"
import {
err,
isErr,
isOk,
ok,
unknownErr
} from "~core/utils/result-monad"
import { AuthType, configManager } from "~core/managers/config"
import { originManager } from "~core/managers/origin"
import { transactionManager } from "~core/managers/transaction"
import { getMediaCaller } from "~core/media"
import { NO_TXN_REFERRER } from "~core/model-router"
import { err, isErr, isOk, ok, unknownErr } from "~core/utils/result-monad"
import { log } from "~core/utils/utils"

import { requestPermission } from "./permission"
import { getMediaCaller } from "~core/media"
import { originManager } from "~core/managers/origin"
import { NO_TXN_REFERRER } from "~core/model-router"
import { promptInterrupts } from "~background/lib/helpers"

const handler: PlasmoMessaging.PortHandler<
PortRequest[PortName.Media],
Expand All @@ -48,14 +34,17 @@ const handler: PlasmoMessaging.PortHandler<

const txn = request.transaction

if ('messages' in txn.input) {
if ("messages" in txn.input) {
return res.send(err(ErrorCode.InvalidRequest))
}

// temporarily, use external model config
const config = await configManager.forAuthAndModel(AuthType.External, ModelID.Shap_e)
const config = await configManager.forAuthAndModel(
AuthType.External,
ModelID.Shap_e
)
// if not credentialed, present with login flow
if(!configManager.isCredentialed(config)){
if (!configManager.isCredentialed(config)) {
promptInterrupts(id, err(ErrorCode.NotAuthenticated))
return res.send({ response: err(ErrorCode.NotAuthenticated), id })
}
Expand All @@ -73,19 +62,19 @@ const handler: PlasmoMessaging.PortHandler<
model: txn.routedModel,
origin: txn ? originManager.url(txn.origin) : NO_TXN_REFERRER,
num_generations: txn.numOutputs,
num_inference_steps: txn.numInferenceSteps,
num_inference_steps: txn.numInferenceSteps
})
} catch (error) {
result = unknownErr(error)
}

if (isOk(result)) {
const outputs = result.data
res.send({ response: ok(outputs), id })
// do not store URIs in the transaction, empty string to save storage
txn.outputs = outputs.map((output: MediaOutput) => ({
...output,
uri: "",
uri: ""
}))
} else {
res.send({ response: result, id })
Expand Down
Loading