-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ef2bda
commit 0c31a2e
Showing
12 changed files
with
1,938 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Modus Recipes | ||
|
||
Code recipes for cooking with Modus, the open source serverless framework for building intelligent APIs, powered by WebAssembly. | ||
|
||
## [modus101](modus101/) | ||
|
||
Demo from [Introducing ModusHack: Modus 101 livestream](https://www.youtube.com/watch?v=8vgXmZPKjbo). | ||
|
||
## [modus-getting-started](modus-getting-started/) | ||
|
||
Code from [Getting Started With Modus video](https://www.youtube.com/watch?v=3CcJTXTmz88). |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Ignore macOS system files | ||
.DS_Store | ||
|
||
# Ignore environment variable files | ||
.env | ||
.env.* | ||
|
||
# Ignore build output directories | ||
build/ | ||
|
||
# Ignore node_modules folders | ||
node_modules/ | ||
|
||
# Ignore logs generated by as-test | ||
logs/ |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["assemblyscript-prettier"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Getting Started With Modus | ||
|
||
Simple getting started to show how to create a serverless API with Modus. | ||
|
||
Watch the recording: | ||
|
||
[](https://www.youtube.com/watch?v=3CcJTXTmz88) |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./node_modules/@hypermode/modus-sdk-as/plugin.asconfig.json", | ||
"options": { | ||
"transform": ["@hypermode/modus-sdk-as/transform", "json-as/transform"] | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { http, models } from "@hypermode/modus-sdk-as"; | ||
import { | ||
OpenAIChatModel, | ||
ResponseFormat, | ||
SystemMessage, | ||
UserMessage, | ||
} from "@hypermode/modus-sdk-as/models/openai/chat"; | ||
|
||
export function generateText(instruction: string, prompt: string): string { | ||
const model = models.getModel<OpenAIChatModel>("text-generator"); | ||
|
||
const input = model.createInput([ | ||
new SystemMessage(instruction), | ||
new UserMessage(prompt), | ||
]); | ||
|
||
input.temperature = 0.7; | ||
const output = model.invoke(input); | ||
|
||
return output.choices[0].message.content.trim(); | ||
} | ||
|
||
|
||
@json | ||
class Quote { | ||
|
||
@alias("q") | ||
quote!: string; | ||
|
||
|
||
@alias("a") | ||
author!: string; | ||
} | ||
|
||
export function getRandomQuote(): Quote { | ||
const request = new http.Request("https://zenquotes.io/api/random"); | ||
|
||
const response = http.fetch(request); | ||
if (!response.ok) { | ||
throw new Error( | ||
`Failed to fetch quote. Received: ${response.status} ${response.statusText}`, | ||
); | ||
} | ||
|
||
return response.json<Quote[]>()[0]; | ||
} | ||
|
||
export function sayHello(name: string | null = null): string { | ||
return `Hello, ${name || "World"}!`; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "assemblyscript/std/assembly.json", | ||
"include": ["./**/*.ts"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @ts-check | ||
|
||
import eslint from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
import aseslint from "@hypermode/modus-sdk-as/tools/assemblyscript-eslint"; | ||
|
||
export default tseslint.config( | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
aseslint.config, | ||
); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://schema.hypermode.com/modus.json", | ||
"endpoints": { | ||
"default": { | ||
"type": "graphql", | ||
"path": "/graphql", | ||
"auth": "bearer-token" | ||
} | ||
}, | ||
"connections": { | ||
"zenquotes": { | ||
"type": "http", | ||
"baseUrl": "https://zenquotes.io/" | ||
} | ||
}, | ||
"models": { | ||
"text-generator": { | ||
"sourceModel": "meta-llama/Meta-Llama-3.1-8B-Instruct", | ||
"provider": "hugging-face", | ||
"connection": "hypermode" | ||
} | ||
} | ||
} |
Oops, something went wrong.