Skip to content

Commit

Permalink
add getting started with modus
Browse files Browse the repository at this point in the history
  • Loading branch information
johnymontana committed Nov 3, 2024
1 parent 5ef2bda commit 0c31a2e
Show file tree
Hide file tree
Showing 12 changed files with 1,938 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
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).
15 changes: 15 additions & 0 deletions modus-getting-started/.gitignore
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/
3 changes: 3 additions & 0 deletions modus-getting-started/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["assemblyscript-prettier"]
}
7 changes: 7 additions & 0 deletions modus-getting-started/README.md
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:

[![Getting started with Modus video](https://img.youtube.com/vi/3CcJTXTmz88/0.jpg)](https://www.youtube.com/watch?v=3CcJTXTmz88)
6 changes: 6 additions & 0 deletions modus-getting-started/asconfig.json
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"]
}
}
50 changes: 50 additions & 0 deletions modus-getting-started/assembly/index.ts
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"}!`;
}
4 changes: 4 additions & 0 deletions modus-getting-started/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": ["./**/*.ts"]
}
11 changes: 11 additions & 0 deletions modus-getting-started/eslint.config.js
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,
);
23 changes: 23 additions & 0 deletions modus-getting-started/modus.json
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"
}
}
}
Loading

0 comments on commit 0c31a2e

Please sign in to comment.