Skip to content

Commit b6c7e3f

Browse files
authored
feat(cli): remove tag from llm-sfn init template (#1024)
1 parent 42af24d commit b6c7e3f

File tree

14 files changed

+30
-50
lines changed

14 files changed

+30
-50
lines changed

cli/serverless/golang/serverless.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (s *GolangServerless) Init(opts *serverless.Options) error {
6060
WithWantedTarget: opt.WithWantedTarget,
6161
WithDescription: opt.WithDescription,
6262
WithInputSchema: opt.WithInputSchema,
63+
WithDataTags: opt.WithDataTags,
6364
}
6465

6566
isWasi := opts.WASI
@@ -251,6 +252,7 @@ type AppOpts struct {
251252
WithWantedTarget bool
252253
WithDescription bool
253254
WithInputSchema bool
255+
WithDataTags bool
254256
}
255257

256258
// ParseSrc parse app option from source code to run serverless
@@ -274,6 +276,8 @@ func ParseSrc(appFile string) (*AppOpts, error) {
274276
opts.WithInputSchema = true
275277
case "WantedTarget":
276278
opts.WithWantedTarget = true
279+
case "DataTags":
280+
opts.WithDataTags = true
277281
}
278282
}
279283
}

cli/serverless/golang/template.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Context struct {
2828
WithDescription bool
2929
// WithInputSchema determines whether to work with input schema
3030
WithInputSchema bool
31+
// WithDataTags determines whether to work with data tags
32+
WithDataTags bool
3133
}
3234

3335
// RenderTmpl renders the template with the given context

cli/serverless/golang/templates/main.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ func InputSchema() any {
44
}
55
{{end}}
66

7+
{{if not .WithDataTags}}
8+
func DataTags() []uint32 {
9+
return []uint32{}
10+
}
11+
{{end}}
12+
713
// Serverless main function
814
func main() {
915
if err := rootCmd.Execute(); err != nil {

cli/serverless/nodejs/templates/wrapper_ts.tmpl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@ import {
77
_FunctionCall,
88
_createConnection,
99
} from '@yomo/sfn'
10-
import { description, tag, handler } from '{{ .FileName }}'
10+
import * as app from '{{ .FileName }}'
1111

12+
const { description, handler, tag } = app as {
13+
description: string
14+
handler: (args: unknown) => Promise<unknown>
15+
tag?: number
16+
}
1217
const WORK_DIR = '{{ .WorkDir }}'
1318
const FUNCTION_NAME = '{{ .FunctionName }}'
1419
const SFN_FILE_PATH = '{{ .FilePath }}'
1520
const SOCK_PATH = join(WORK_DIR, 'sfn.sock');
1621
const REDUCE_TAG = 0xe001;
1722

1823
function run() {
19-
if (
20-
!description ||
21-
!handler ||
22-
tag === undefined ||
23-
tag === null
24-
) {
25-
throw Error('description, tags, handler signature must be exported!')
24+
if (!description || !handler) {
25+
throw Error('description, handler signature must be exported!')
26+
}
27+
let tags: number[] = []
28+
if (tag) {
29+
tags = [tag]
2630
}
2731
const tools = _genTools(FUNCTION_NAME, description, SFN_FILE_PATH)
2832
const header = JSON.stringify({
29-
tags: [tag],
33+
tags: tags,
3034
function_definition: JSON.stringify(tools, null, 2)
3135
})
3236
const { conn } = _createConnection(SOCK_PATH, {

cli/template/go/init_llm.tmpl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,9 @@ type LLMArguments struct {
4444
Longitude float64 `json:"longitude" jsonschema:"description=The longitude of the city, in decimal format, range should be in (-180, 180)"`
4545
}
4646

47-
// DataTags specifies the data tags to which this serverless function
48-
// subscribes, essential for data reception. Upon receiving data with these
49-
// tags, the Handler function is triggered.
50-
func DataTags() []uint32 {
51-
return []uint32{0x30}
52-
}
53-
5447
// Handler orchestrates the core processing logic of this function.
5548
// - ctx.ReadLLMArguments() parses LLM Function Calling Arguments (skip if none).
5649
// - ctx.WriteLLMResult() sends the retrieval result back to LLM.
57-
// - ctx.Tag() identifies the tag of the incoming data.
58-
// - ctx.Data() accesses the raw data.
59-
// - ctx.Write() forwards processed data downstream.
6050
func Handler(ctx serverless.Context) {
6151
var p LLMArguments
6252
// deserilize the arguments from llm tool_call response

cli/template/go/init_llm_test.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestHandler(t *testing.T) {
1616
}{
1717
{
1818
name: "get weather",
19-
ctx: mock.NewArgumentsContext(`{"city":"New York","latitude":40.7128,"longitude":-74.0060}`, 0x33),
19+
ctx: mock.NewArgumentsContext(`{"city":"New York","latitude":40.7128,"longitude":-74.0060}`),
2020
want: "The current weather in New York (40.712800,-74.006000) is sunny",
2121
},
2222
// TODO: add more test cases.

cli/template/node/init_llm.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export const description = 'Get the current weather for `city_name`'
22

3-
export const tag = 0x33
4-
53
// For jsonschema in TypeScript, see: https://github.com/YousefED/typescript-json-schema
64
export type Argument = {
75
/**
@@ -15,6 +13,7 @@ async function getWeather(city_name: string) {
1513
console.log(`get weather for ${city_name} with temperature ${tempraure}°C`)
1614
return { city_name: city_name, temperature: tempraure }
1715
}
16+
1817
export async function handler(args: Argument) {
1918
const result = await getWeather(args.city_name)
2019
return result

example/10-ai/llm-sfn-currency-converter/app.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ func Handler(ctx serverless.Context) {
5454
}
5555
}
5656

57-
func DataTags() []uint32 {
58-
return []uint32{0x10}
59-
}
60-
6157
type Rates struct {
6258
Rates map[string]float64 `json:"rates"`
6359
}

example/10-ai/llm-sfn-get-ip-and-latency/app.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,3 @@ func Handler(ctx serverless.Context) {
6565

6666
ctx.WriteLLMResult(val)
6767
}
68-
69-
func DataTags() []uint32 {
70-
return []uint32{0x10}
71-
}

example/10-ai/llm-sfn-get-weather/app.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/yomorun/yomo/serverless"
1111
)
1212

13-
var tag uint32 = 0x11
14-
1513
type Parameter struct {
1614
CityName string `json:"city_name" jsonschema:"description=The name of a city to be queried"`
1715
}
@@ -35,7 +33,7 @@ func Handler(ctx serverless.Context) {
3533
slog.Error("[sfn] ReadLLMArguments error", "err", err)
3634
return
3735
}
38-
slog.Info("[sfn] << receive", "tag", tag, "msg", msg)
36+
slog.Info("[sfn] << receive", "msg", msg)
3937
data := fmt.Sprintf("[%s] temperature: %d°C", msg.CityName, rand.Intn(40))
4038
time.Sleep(time.Millisecond * 300)
4139
// helper ai function
@@ -50,7 +48,3 @@ func Handler(ctx serverless.Context) {
5048
slog.Info("[sfn] >> write", "tag", ai.ReducerTag, "fnCall", fnCall)
5149
}
5250
}
53-
54-
func DataTags() []uint32 {
55-
return []uint32{tag}
56-
}

0 commit comments

Comments
 (0)