Skip to content

Commit

Permalink
AI proxy spin app
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Dec 12, 2024
1 parent 5094835 commit 32cd285
Show file tree
Hide file tree
Showing 12 changed files with 2,714 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/aiproxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
26 changes: 26 additions & 0 deletions examples/aiproxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AI Proxy

This folder contains a [Spin](https://www.fermyon.com/spin) application, based on the WASI 2 and the WebAssembly Component Model ( https://component-model.bytecodealliance.org/ ). It is implemented in Rust as a serverless proxy for the OpenAI API.

There is a simple example of a web client in the [web](./web/) folder.

The application will keep track of of token usage per conversation in the built-in key-value storage of Spin. The initial balance for a conversation is retrieved from the Fungible Token smart contract.

To launch the application, make sure to have the Spin SDK installed. Set the environment variable `SPIN_VARIABLE_OPENAI_API_KEY` to your OpenAI API key.

Then run the following commands:

```
spin build
spin up
```

This will start the OpenAI proxy server at http://localhost:3000

You can also launch the web client using for example [http-server](https://www.npmjs.com/package/http-server):

```
http-server web
```

You will then find the web client at http://localhost:8080. Here you can have a conversation with the AI model.
Loading

0 comments on commit 32cd285

Please sign in to comment.